From f6544f237ac8303589cfb08fa43d2eebc555fe2e Mon Sep 17 00:00:00 2001 From: Ian Stewart Date: Wed, 29 Oct 2014 22:13:14 +0000 Subject: [PATCH] Twenty Fifteen: avoid errors by preventing Twenty Fifteen from being activated in old versions of WordPress Props iamtakashi, fixes #30137. git-svn-id: https://develop.svn.wordpress.org/trunk@30099 602fd350-edb4-49c9-b593-d223f7449a82 --- .../themes/twentyfifteen/functions.php | 7 +++ .../themes/twentyfifteen/inc/back-compat.php | 63 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/wp-content/themes/twentyfifteen/inc/back-compat.php diff --git a/src/wp-content/themes/twentyfifteen/functions.php b/src/wp-content/themes/twentyfifteen/functions.php index cc0d81639c..b560e83de0 100644 --- a/src/wp-content/themes/twentyfifteen/functions.php +++ b/src/wp-content/themes/twentyfifteen/functions.php @@ -34,6 +34,13 @@ if ( ! isset( $content_width ) ) { $content_width = 660; } +/** + * Twenty Fifteen only works in WordPress 4.1 or later. + */ +if ( version_compare( $GLOBALS['wp_version'], '4.1', '<' ) ) { + require get_template_directory() . '/inc/back-compat.php'; +} + if ( ! function_exists( 'twentyfifteen_setup' ) ) : /** * Sets up theme defaults and registers support for various WordPress features. diff --git a/src/wp-content/themes/twentyfifteen/inc/back-compat.php b/src/wp-content/themes/twentyfifteen/inc/back-compat.php new file mode 100644 index 0000000000..0536c0103c --- /dev/null +++ b/src/wp-content/themes/twentyfifteen/inc/back-compat.php @@ -0,0 +1,63 @@ +

%s

', $message ); +} + +/** + * Prevent the Customizer from being loaded on WordPress versions prior to 4.1. + * + * @since Twenty Fifteen 1.0 + */ +function twentyfifteen_customize() { + 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( + 'back_link' => true, + ) ); +} +add_action( 'load-customize.php', 'twentyfifteen_customize' ); + +/** + * Prevent the Theme Preview from being loaded on WordPress versions prior to 4.1. + * + * @since Twenty Fifteen 1.0 + */ +function twentyfifteen_preview() { + if ( isset( $_GET['preview'] ) ) { + 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'] ) ); + } +} +add_action( 'template_redirect', 'twentyfifteen_preview' ); \ No newline at end of file