back-compat.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php declare( strict_types = 1 ); ?>
  2. <?php
  3. /**
  4. * Varia back compat functionality
  5. *
  6. * Prevents Varia from running on WordPress versions prior to 4.7,
  7. * since this theme is not meant to be backward compatible beyond that and
  8. * relies on many newer functions and markup changes introduced in 4.7.
  9. *
  10. * @package WordPress
  11. * @subpackage Varia
  12. * @since Varia 1.0.0
  13. */
  14. /**
  15. * Prevent switching to Varia on old versions of WordPress.
  16. *
  17. * Switches to the default theme.
  18. *
  19. * @since Varia 1.0.0
  20. */
  21. function varia_switch_theme() {
  22. switch_theme( WP_DEFAULT_THEME );
  23. unset( $_GET['activated'] );
  24. add_action( 'admin_notices', 'varia_upgrade_notice' );
  25. }
  26. add_action( 'after_switch_theme', 'varia_switch_theme' );
  27. /**
  28. * Adds a message for unsuccessful theme switch.
  29. *
  30. * Prints an update nag after an unsuccessful attempt to switch to
  31. * Varia on WordPress versions prior to 4.7.
  32. *
  33. * @since Varia 1.0.0
  34. *
  35. * @global string $wp_version WordPress version.
  36. */
  37. function varia_upgrade_notice() {
  38. $message = sprintf( __( 'Varia requires at least WordPress version 4.7. You are running version %s. Please upgrade and try again.', 'varia' ), $GLOBALS['wp_version'] );
  39. printf( '<div class="error"><p>%s</p></div>', $message );
  40. }
  41. /**
  42. * Prevents the Customizer from being loaded on WordPress versions prior to 4.7.
  43. *
  44. * @since Varia 1.0.0
  45. *
  46. * @global string $wp_version WordPress version.
  47. */
  48. function varia_customize() {
  49. wp_die(
  50. sprintf(
  51. __( 'Varia requires at least WordPress version 4.7. You are running version %s. Please upgrade and try again.', 'varia' ),
  52. $GLOBALS['wp_version']
  53. ),
  54. '',
  55. array(
  56. 'back_link' => true,
  57. )
  58. );
  59. }
  60. add_action( 'load-customize.php', 'varia_customize' );
  61. /**
  62. * Prevents the Theme Preview from being loaded on WordPress versions prior to 4.7.
  63. *
  64. * @since Varia 1.0.0
  65. *
  66. * @global string $wp_version WordPress version.
  67. */
  68. function varia_preview() {
  69. if ( isset( $_GET['preview'] ) ) {
  70. wp_die( sprintf( __( 'Varia requires at least WordPress version 4.7. You are running version %s. Please upgrade and try again.', 'varia' ), $GLOBALS['wp_version'] ) );
  71. }
  72. }
  73. add_action( 'template_redirect', 'varia_preview' );