back-compat.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Twenty Sixteen back compat functionality
  4. *
  5. * Prevents Twenty Sixteen from running on WordPress versions prior to 4.4,
  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 4.4.
  8. *
  9. * @package WordPress
  10. * @subpackage Twenty_Sixteen
  11. * @since Twenty Sixteen 1.0
  12. */
  13. /**
  14. * Prevent switching to Twenty Sixteen on old versions of WordPress.
  15. *
  16. * Switches to the default theme.
  17. *
  18. * @since Twenty Sixteen 1.0
  19. */
  20. function twentysixteen_switch_theme() {
  21. switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
  22. unset( $_GET['activated'] );
  23. add_action( 'admin_notices', 'twentysixteen_upgrade_notice' );
  24. }
  25. add_action( 'after_switch_theme', 'twentysixteen_switch_theme' );
  26. /**
  27. * Adds a message for unsuccessful theme switch.
  28. *
  29. * Prints an update nag after an unsuccessful attempt to switch to
  30. * Twenty Sixteen on WordPress versions prior to 4.4.
  31. *
  32. * @since Twenty Sixteen 1.0
  33. *
  34. * @global string $wp_version WordPress version.
  35. */
  36. function twentysixteen_upgrade_notice() {
  37. $message = sprintf( __( 'Twenty Sixteen requires at least WordPress version 4.4. You are running version %s. Please upgrade and try again.', 'twentysixteen' ), $GLOBALS['wp_version'] );
  38. printf( '<div class="error"><p>%s</p></div>', $message );
  39. }
  40. /**
  41. * Prevents the Customizer from being loaded on WordPress versions prior to 4.4.
  42. *
  43. * @since Twenty Sixteen 1.0
  44. *
  45. * @global string $wp_version WordPress version.
  46. */
  47. function twentysixteen_customize() {
  48. wp_die( sprintf( __( 'Twenty Sixteen requires at least WordPress version 4.4. You are running version %s. Please upgrade and try again.', 'twentysixteen' ), $GLOBALS['wp_version'] ), '', array(
  49. 'back_link' => true,
  50. ) );
  51. }
  52. add_action( 'load-customize.php', 'twentysixteen_customize' );
  53. /**
  54. * Prevents the Theme Preview from being loaded on WordPress versions prior to 4.4.
  55. *
  56. * @since Twenty Sixteen 1.0
  57. *
  58. * @global string $wp_version WordPress version.
  59. */
  60. function twentysixteen_preview() {
  61. if ( isset( $_GET['preview'] ) ) {
  62. wp_die( sprintf( __( 'Twenty Sixteen requires at least WordPress version 4.4. You are running version %s. Please upgrade and try again.', 'twentysixteen' ), $GLOBALS['wp_version'] ) );
  63. }
  64. }
  65. add_action( 'template_redirect', 'twentysixteen_preview' );