back-compat.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Twenty Fourteen back compat functionality
  4. *
  5. * Prevents Twenty Fourteen from running on WordPress versions prior to 3.6,
  6. * since this theme is not meant to be backward compatible beyond that
  7. * and relies on many newer functions and markup changes introduced in 3.6.
  8. *
  9. * @package WordPress
  10. * @subpackage Twenty_Fourteen
  11. * @since Twenty Fourteen 1.0
  12. */
  13. /**
  14. * Prevent switching to Twenty Fourteen on old versions of WordPress.
  15. *
  16. * Switches to the default theme.
  17. *
  18. * @since Twenty Fourteen 1.0
  19. *
  20. * @return void
  21. */
  22. function twentyfourteen_switch_theme() {
  23. switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
  24. unset( $_GET['activated'] );
  25. add_action( 'admin_notices', 'twentyfourteen_upgrade_notice' );
  26. }
  27. add_action( 'after_switch_theme', 'twentyfourteen_switch_theme' );
  28. /**
  29. * Add message for unsuccessful theme switch.
  30. *
  31. * Prints an update nag after an unsuccessful attempt to switch to
  32. * Twenty Fourteen on WordPress versions prior to 3.6.
  33. *
  34. * @since Twenty Fourteen 1.0
  35. *
  36. * @return void
  37. */
  38. function twentyfourteen_upgrade_notice() {
  39. $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'] );
  40. printf( '<div class="error"><p>%s</p></div>', $message );
  41. }
  42. /**
  43. * Prevent the Theme Customizer from being loaded on WordPress versions prior to 3.6.
  44. *
  45. * @since Twenty Fourteen 1.0
  46. *
  47. * @return void
  48. */
  49. function twentyfourteen_customize() {
  50. 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(
  51. 'back_link' => true,
  52. ) );
  53. }
  54. add_action( 'load-customize.php', 'twentyfourteen_customize' );
  55. /**
  56. * Prevent the Theme Preview from being loaded on WordPress versions prior to 3.4.
  57. *
  58. * @since Twenty Fourteen 1.0
  59. *
  60. * @return void
  61. */
  62. function twentyfourteen_preview() {
  63. if ( isset( $_GET['preview'] ) ) {
  64. 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'] ) );
  65. }
  66. }
  67. add_action( 'template_redirect', 'twentyfourteen_preview' );