theme-tools.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * Load code specific to themes or theme tools
  4. * This file is special, and is not an actual `module` as such.
  5. * It is included by ./module-extras.php
  6. */
  7. function jetpack_load_theme_tools() {
  8. if ( current_theme_supports( 'tonesque' ) ) {
  9. jetpack_require_lib( 'tonesque' );
  10. }
  11. }
  12. add_action( 'init', 'jetpack_load_theme_tools', 30 );
  13. /**
  14. * Load theme compat file if it exists.
  15. */
  16. function jetpack_load_theme_compat() {
  17. /**
  18. * Filter theme compat files.
  19. *
  20. * Themes can add their own compat files here if they like. For example:
  21. *
  22. * add_filter( 'jetpack_theme_compat_files', 'mytheme_jetpack_compat_file' );
  23. * function mytheme_jetpack_compat_file( $files ) {
  24. * $files['mytheme'] = locate_template( 'jetpack-compat.php' );
  25. * return $files;
  26. * }
  27. *
  28. * @module theme-tools
  29. *
  30. * @since 2.8.0
  31. *
  32. * @param array Associative array of theme compat files to load.
  33. */
  34. $compat_files = apply_filters( 'jetpack_theme_compat_files', array(
  35. 'twentyfourteen' => JETPACK__PLUGIN_DIR . 'modules/theme-tools/compat/twentyfourteen.php',
  36. 'twentyfifteen' => JETPACK__PLUGIN_DIR . 'modules/theme-tools/compat/twentyfifteen.php',
  37. 'twentysixteen' => JETPACK__PLUGIN_DIR . 'modules/theme-tools/compat/twentysixteen.php',
  38. 'twentyseventeen' => JETPACK__PLUGIN_DIR . 'modules/theme-tools/compat/twentyseventeen.php',
  39. ) );
  40. _jetpack_require_compat_file( get_stylesheet(), $compat_files );
  41. if ( is_child_theme() ) {
  42. _jetpack_require_compat_file( get_template(), $compat_files );
  43. }
  44. }
  45. add_action( 'after_setup_theme', 'jetpack_load_theme_compat', -1 );
  46. /**
  47. * Requires a file once, if the passed key exists in the files array.
  48. *
  49. * @access private
  50. * @param string $key
  51. * @param array $files
  52. * @return void
  53. */
  54. function _jetpack_require_compat_file( $key, $files ) {
  55. if ( ! is_string( $key ) ) {
  56. return new WP_Error( 'key_not_string', 'The specified key is not actually a string.', compact( 'key' ) );
  57. }
  58. if ( array_key_exists( $key, $files ) && is_readable( $files[ $key ] ) ) {
  59. require_once $files[ $key ];
  60. }
  61. }