back-compat.php 2.0 KB

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