back-compat.php 2.1 KB

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