Twenty Fourteen: limit back compat to 3.6 and later versions. See #26055, props obenland.

Built from https://develop.svn.wordpress.org/trunk@26225


git-svn-id: http://core.svn.wordpress.org/trunk@26132 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Lance Willett 2013-11-15 21:15:10 +00:00
parent 0395919b11
commit a52f3ebb7b
3 changed files with 92 additions and 27 deletions

View File

@ -34,6 +34,12 @@
if ( ! isset( $content_width ) )
$content_width = 474;
/**
* Twenty Fourteen only works in WordPress 3.6 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '3.6', '<' ) )
require get_template_directory() . '/inc/back-compat.php';
if ( ! function_exists( 'twentyfourteen_setup' ) ) :
/**
* Twenty Fourteen setup.
@ -217,8 +223,6 @@ function twentyfourteen_font_url() {
* @return void
*/
function twentyfourteen_scripts() {
global $wp_styles;
// Add Lato font, used in the main stylesheet.
wp_enqueue_style( 'twentyfourteen-lato', twentyfourteen_font_url(), array(), null );
@ -230,7 +234,7 @@ function twentyfourteen_scripts() {
// Load the Internet Explorer specific stylesheet.
wp_enqueue_style( 'twentyfourteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentyfourteen-style' ), '20131110' );
$wp_styles->add_data( 'twentyfourteen-ie', 'conditional', 'lt IE 9' );
wp_style_add_data( 'twentyfourteen-ie', 'conditional', 'lt IE 9' );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
wp_enqueue_script( 'comment-reply' );

View File

@ -0,0 +1,71 @@
<?php
/**
* Twenty Fourteen back compat functionality
*
* Prevents Twenty Fourteen from running on WordPress versions prior to 3.6,
* since this theme is not meant to be backward compatible beyond that
* and relies on many newer functions and markup changes introduced in 3.6.
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
/**
* Prevent switching to Twenty Fourteen on old versions of WordPress.
*
* Switches to the default theme.
*
* @since Twenty Fourteen 1.0
*
* @return void
*/
function twentyfourteen_switch_theme() {
switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
unset( $_GET['activated'] );
add_action( 'admin_notices', 'twentyfourteen_upgrade_notice' );
}
add_action( 'after_switch_theme', 'twentyfourteen_switch_theme' );
/**
* Add message for unsuccessful theme switch.
*
* Prints an update nag after an unsuccessful attempt to switch to
* Twenty Fourteen on WordPress versions prior to 3.6.
*
* @since Twenty Fourteen 1.0
*
* @return void
*/
function twentyfourteen_upgrade_notice() {
$message = sprintf( __( 'Twenty Fourteen requires at least WordPress version 3.6. You are running version %s. Please upgrade and try again.', 'twentyfourteen' ), $GLOBALS['wp_version'] );
printf( '<div class="error"><p>%s</p></div>', $message );
}
/**
* Prevent the Theme Customizer from being loaded on WordPress versions prior to 3.6.
*
* @since Twenty Fourteen 1.0
*
* @return void
*/
function twentyfourteen_customize() {
wp_die( sprintf( __( 'Twenty Fourteen requires at least WordPress version 3.6. You are running version %s. Please upgrade and try again.', 'twentyfourteen' ), $GLOBALS['wp_version'] ), '', array(
'back_link' => true,
) );
}
add_action( 'load-customize.php', 'twentyfourteen_customize' );
/**
* Prevent the Theme Preview from being loaded on WordPress versions prior to 3.4.
*
* @since Twenty Fourteen 1.0
*
* @return void
*/
function twentyfourteen_preview() {
if ( isset( $_GET['preview'] ) ) {
wp_die( sprintf( __( 'Twenty Fourteen requires at least WordPress version 3.6. You are running version %s. Please upgrade and try again.', 'twentyfourteen' ), $GLOBALS['wp_version'] ) );
}
}
add_action( 'template_redirect', 'twentyfourteen_preview' );

View File

@ -131,22 +131,14 @@ class Twenty_Fourteen_Ephemera_Widget extends WP_Widget {
else :
$images = array();
if ( function_exists( 'get_post_galleries' ) ) {
$galleries = get_post_galleries( get_the_ID(), false );
if ( isset( $galleries[0]['ids'] ) )
$images = explode( ',', $galleries[0]['ids'] );
} else {
$pattern = get_shortcode_regex();
preg_match( "/$pattern/s", get_the_content(), $match );
$atts = shortcode_parse_atts( $match[3] );
if ( isset( $atts['ids'] ) )
$images = explode( ',', $atts['ids'] );
}
$galleries = get_post_galleries( get_the_ID(), false );
if ( isset( $galleries[0]['ids'] ) )
$images = explode( ',', $galleries[0]['ids'] );
if ( ! $images ) :
$images = get_posts( array(
'fields' => 'ids',
'numberposts' => 999,
'numberposts' => -1,
'order' => 'ASC',
'orderby' => 'menu_order',
'post_mime_type' => 'image',
@ -166,19 +158,17 @@ class Twenty_Fourteen_Ephemera_Widget extends WP_Widget {
if ( ! empty ( $post_thumbnail ) ) :
?>
<a href="<?php the_permalink(); ?>"><?php echo $post_thumbnail; ?></a>
<?php
endif;
?>
<p class="wp-caption-text">
<?php
printf( _n( 'This gallery contains <a href="%1$s" rel="bookmark">%2$s photo</a>.', 'This gallery contains <a href="%1$s" rel="bookmark">%2$s photos</a>.', $total_images, 'twentyfourteen' ),
esc_url( get_permalink() ),
number_format_i18n( $total_images )
);
?>
</p>
<a href="<?php the_permalink(); ?>"><?php echo $post_thumbnail; ?></a>
<?php endif; ?>
<p class="wp-caption-text">
<?php
printf( _n( 'This gallery contains <a href="%1$s" rel="bookmark">%2$s photo</a>.', 'This gallery contains <a href="%1$s" rel="bookmark">%2$s photos</a>.', $total_images, 'twentyfourteen' ),
esc_url( get_permalink() ),
number_format_i18n( $total_images )
);
?>
</p>
<?php
endif;
else :