WordPress.org

Make WordPress Core

Ticket #30137: 30137.diff

File 30137.diff, 3.3 KB (added by iamtakashi, 7 years ago)

Limit back compat to 4.1 and later versions.

  • wp-content/themes/twentyfifteen/functions.php

     
    3434        $content_width = 660;
    3535}
    3636
     37/**
     38 * Twenty Fifteen only works in WordPress 4.1 or later.
     39 */
     40if ( version_compare( $GLOBALS['wp_version'], '4.1', '<' ) ) {
     41        require get_template_directory() . '/inc/back-compat.php';
     42}
     43
    3744if ( ! function_exists( 'twentyfifteen_setup' ) ) :
    3845/**
    3946 * Sets up theme defaults and registers support for various WordPress features.
  • wp-content/themes/twentyfifteen/inc/back-compat.php

     
     1<?php
     2/**
     3 * Twenty Fifteen back compat functionality
     4 *
     5 * Prevents Twenty Fifteen from running on WordPress versions prior to 4.1,
     6 * since this theme is not meant to be backward compatible beyond that
     7 * and relies on many newer functions and markup changes introduced in 4.1.
     8 *
     9 * @package WordPress
     10 * @subpackage Twenty_Fifteen
     11 * @since Twenty Fifteen 1.0
     12 */
     13
     14/**
     15 * Prevent switching to Twenty Fifteen on old versions of WordPress.
     16 *
     17 * Switches to the default theme.
     18 *
     19 * @since Twenty Fifteen 1.0
     20 */
     21function twentyfifteen_switch_theme() {
     22        switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
     23        unset( $_GET['activated'] );
     24        add_action( 'admin_notices', 'twentyfifteen_upgrade_notice' );
     25}
     26add_action( 'after_switch_theme', 'twentyfifteen_switch_theme' );
     27
     28/**
     29 * Add message for unsuccessful theme switch.
     30 *
     31 * Prints an update nag after an unsuccessful attempt to switch to
     32 * Twenty Fifteen on WordPress versions prior to 4.1.
     33 *
     34 * @since Twenty Fifteen 1.0
     35 */
     36function twentyfifteen_upgrade_notice() {
     37        $message = sprintf( __( 'Twenty Fifteen requires at least WordPress version 4.1. You are running version %s. Please upgrade and try again.', 'twentyfifteen' ), $GLOBALS['wp_version'] );
     38        printf( '<div class="error"><p>%s</p></div>', $message );
     39}
     40
     41/**
     42 * Prevent the Customizer from being loaded on WordPress versions prior to 4.1.
     43 *
     44 * @since Twenty Fifteen 1.0
     45 */
     46function twentyfifteen_customize() {
     47        wp_die( sprintf( __( 'Twenty Fifteen requires at least WordPress version 4.1. You are running version %s. Please upgrade and try again.', 'twentyfifteen' ), $GLOBALS['wp_version'] ), '', array(
     48                'back_link' => true,
     49        ) );
     50}
     51add_action( 'load-customize.php', 'twentyfifteen_customize' );
     52
     53/**
     54 * Prevent the Theme Preview from being loaded on WordPress versions prior to 4.1.
     55 *
     56 * @since Twenty Fifteen 1.0
     57 */
     58function twentyfifteen_preview() {
     59        if ( isset( $_GET['preview'] ) ) {
     60                wp_die( sprintf( __( 'Twenty Fifteen requires at least WordPress version 4.1. You are running version %s. Please upgrade and try again.', 'twentyfifteen' ), $GLOBALS['wp_version'] ) );
     61        }
     62}
     63add_action( 'template_redirect', 'twentyfifteen_preview' );
     64 No newline at end of file