Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Main | |
0.00% |
0 / 29 |
|
0.00% |
0 / 5 |
156 | |
0.00% |
0 / 1 |
| init | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| load_modules | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| jetpack_load_theme_tools | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| classic_theme_helper_load_theme_compat | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |||
| classic_theme_helper_require_compat_file | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Package description here |
| 4 | * |
| 5 | * @package automattic/jetpack-classic-theme-helper |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Classic_Theme_Helper; |
| 9 | |
| 10 | use WP_Error; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit( 0 ); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Classic Theme Helper Loader. |
| 18 | */ |
| 19 | class Main { |
| 20 | |
| 21 | const PACKAGE_VERSION = '0.14.15'; |
| 22 | |
| 23 | /** |
| 24 | * Modules to include. |
| 25 | * |
| 26 | * @var array |
| 27 | */ |
| 28 | public $modules = array( |
| 29 | 'custom-content-types.php', |
| 30 | 'responsive-videos.php', |
| 31 | 'site-breadcrumbs.php', |
| 32 | 'social-menu.php', |
| 33 | 'jetpack-color.php', |
| 34 | 'content-options.php', |
| 35 | ); |
| 36 | |
| 37 | /** Holds the singleton instance of the Loader |
| 38 | * |
| 39 | * @var Main |
| 40 | */ |
| 41 | public static $instance = null; |
| 42 | |
| 43 | /** |
| 44 | * Initialize the Loader. |
| 45 | */ |
| 46 | public static function init() { |
| 47 | if ( ! self::$instance ) { |
| 48 | self::$instance = new Main(); |
| 49 | self::$instance->load_modules(); |
| 50 | add_action( 'init', array( __CLASS__, 'jetpack_load_theme_tools' ), 30 ); |
| 51 | add_action( 'after_setup_theme', array( __CLASS__, 'classic_theme_helper_load_theme_compat' ), -1 ); |
| 52 | } |
| 53 | |
| 54 | return self::$instance; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Load modules. |
| 59 | */ |
| 60 | public function load_modules() { |
| 61 | |
| 62 | // Filter the modules to include. |
| 63 | // $since = 0.1.0 |
| 64 | // @param array $modules Array of modules to include. |
| 65 | $modules = apply_filters( 'jetpack_classic_theme_helper_modules', $this->modules ); |
| 66 | foreach ( $modules as $module ) { |
| 67 | require_once __DIR__ . '/' . $module; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Conditionally require the Tonesque lib depending on theme support. |
| 73 | */ |
| 74 | public static function jetpack_load_theme_tools() { |
| 75 | if ( current_theme_supports( 'tonesque' ) ) { |
| 76 | require_once __DIR__ . '/../_inc/lib/tonesque.php'; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Load theme compat file if it exists. |
| 82 | */ |
| 83 | public static function classic_theme_helper_load_theme_compat() { |
| 84 | |
| 85 | /** |
| 86 | * Filter theme compat files. |
| 87 | * |
| 88 | * Themes can add their own compat files here if they like. For example: |
| 89 | * |
| 90 | * add_filter( 'classic_theme_helper_theme_compat_files', 'mytheme_classic_theme_helper_theme_compat_file' ); |
| 91 | * function mytheme_classic_theme_helper_theme_compat_file( $files ) { |
| 92 | * $files['mytheme'] = locate_template( 'jetpack-compat.php' ); |
| 93 | * return $files; |
| 94 | * } |
| 95 | * |
| 96 | * @since 0.2.0 |
| 97 | * |
| 98 | * @param array Associative array of theme compat files to load. |
| 99 | */ |
| 100 | $compat_files = apply_filters( |
| 101 | 'classic_theme_helper_theme_compat_files', |
| 102 | array( |
| 103 | 'twentyfourteen' => __DIR__ . '/compat/twentyfourteen.php', |
| 104 | 'twentyfifteen' => __DIR__ . '/compat/twentyfifteen.php', |
| 105 | 'twentysixteen' => __DIR__ . '/compat/twentysixteen.php', |
| 106 | 'twentynineteen' => __DIR__ . '/compat/twentynineteen.php', |
| 107 | 'twentytwenty' => __DIR__ . '/compat/twentytwenty.php', |
| 108 | 'twentytwentyone' => __DIR__ . '/compat/twentytwentyone.php', |
| 109 | ) |
| 110 | ); |
| 111 | |
| 112 | self::classic_theme_helper_require_compat_file( get_stylesheet(), $compat_files ); |
| 113 | |
| 114 | if ( is_child_theme() ) { |
| 115 | self::classic_theme_helper_require_compat_file( get_template(), $compat_files ); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Requires a file once, if the passed key exists in the files array. |
| 121 | * |
| 122 | * @param string $key The key to check. |
| 123 | * @param array $files Array of files to check in. |
| 124 | * @return void|WP_Error |
| 125 | */ |
| 126 | private static function classic_theme_helper_require_compat_file( $key, $files ) { |
| 127 | if ( ! is_string( $key ) ) { |
| 128 | return new WP_Error( 'key_not_string', 'The specified key is not actually a string.', compact( 'key' ) ); |
| 129 | } |
| 130 | |
| 131 | if ( array_key_exists( $key, $files ) && is_readable( $files[ $key ] ) ) { |
| 132 | require_once $files[ $key ]; |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | Main::init(); |