back-compat.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. * Display upgrade notice on theme switch.
  15. *
  16. * @since Twenty Twenty-One 1.0
  17. *
  18. * @return void
  19. */
  20. function twenty_twenty_one_switch_theme() {
  21. add_action( 'admin_notices', 'twenty_twenty_one_upgrade_notice' );
  22. }
  23. add_action( 'after_switch_theme', 'twenty_twenty_one_switch_theme' );
  24. /**
  25. * Adds a message for unsuccessful theme switch.
  26. *
  27. * Prints an update nag after an unsuccessful attempt to switch to
  28. * the theme on WordPress versions prior to 5.3.
  29. *
  30. * @since Twenty Twenty-One 1.0
  31. *
  32. * @global string $wp_version WordPress version.
  33. *
  34. * @return void
  35. */
  36. function twenty_twenty_one_upgrade_notice() {
  37. echo '<div class="error"><p>';
  38. printf(
  39. /* translators: %s: WordPress Version. */
  40. esc_html__( 'This theme requires WordPress 5.3 or newer. You are running version %s. Please upgrade.', 'twentytwentyone' ),
  41. esc_html( $GLOBALS['wp_version'] )
  42. );
  43. echo '</p></div>';
  44. }
  45. /**
  46. * Prevents the Customizer from being loaded on WordPress versions prior to 5.3.
  47. *
  48. * @since Twenty Twenty-One 1.0
  49. *
  50. * @global string $wp_version WordPress version.
  51. *
  52. * @return void
  53. */
  54. function twenty_twenty_one_customize() {
  55. wp_die(
  56. sprintf(
  57. /* translators: %s: WordPress Version. */
  58. esc_html__( 'This theme requires WordPress 5.3 or newer. You are running version %s. Please upgrade.', 'twentytwentyone' ),
  59. esc_html( $GLOBALS['wp_version'] )
  60. ),
  61. '',
  62. array(
  63. 'back_link' => true,
  64. )
  65. );
  66. }
  67. add_action( 'load-customize.php', 'twenty_twenty_one_customize' );
  68. /**
  69. * Prevents the Theme Preview from being loaded on WordPress versions prior to 5.3.
  70. *
  71. * @since Twenty Twenty-One 1.0
  72. *
  73. * @global string $wp_version WordPress version.
  74. *
  75. * @return void
  76. */
  77. function twenty_twenty_one_preview() {
  78. if ( isset( $_GET['preview'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
  79. wp_die(
  80. sprintf(
  81. /* translators: %s: WordPress Version. */
  82. esc_html__( 'This theme requires WordPress 5.3 or newer. You are running version %s. Please upgrade.', 'twentytwentyone' ),
  83. esc_html( $GLOBALS['wp_version'] )
  84. )
  85. );
  86. }
  87. }
  88. add_action( 'template_redirect', 'twenty_twenty_one_preview' );