diff --git a/includes/Checker/Preparations/Use_Minimal_Theme_Preparation.php b/includes/Checker/Preparations/Use_Minimal_Theme_Preparation.php new file mode 100644 index 000000000..015de78c8 --- /dev/null +++ b/includes/Checker/Preparations/Use_Minimal_Theme_Preparation.php @@ -0,0 +1,147 @@ +theme_slug = $theme_slug; + $this->themes_dir = $themes_dir; + } + + /** + * Runs this preparation step for the environment and returns a cleanup function. + * + * @since n.e.x.t + * + * @global array $wp_theme_directories + * + * @return callable Cleanup function to revert any changes made here. + * + * @throws Exception Thrown when preparation fails. + */ + public function prepare() { + // Override the theme slug and name. + add_filter( 'template', array( $this, 'get_theme_slug' ) ); + add_filter( 'stylesheet', array( $this, 'get_theme_slug' ) ); + add_filter( 'pre_option_template', array( $this, 'get_theme_slug' ) ); + add_filter( 'pre_option_stylesheet', array( $this, 'get_theme_slug' ) ); + add_filter( 'pre_option_current_theme', array( $this, 'get_theme_name' ) ); + + // Override the theme directory. + add_filter( 'pre_option_template_root', array( $this, 'get_theme_root' ) ); + add_filter( 'pre_option_stylesheet_root', array( $this, 'get_theme_root' ) ); + + // Register the custom themes directory if relevant. + if ( ! empty( $this->themes_dir ) ) { + register_theme_directory( $this->themes_dir ); + + // Force new directory scan to ensure the test theme directory is available. + search_theme_directories( true ); + } + + // Return the cleanup function. + return function() { + global $wp_theme_directories; + + remove_filter( 'template', array( $this, 'get_theme_slug' ) ); + remove_filter( 'stylesheet', array( $this, 'get_theme_slug' ) ); + remove_filter( 'pre_option_template', array( $this, 'get_theme_slug' ) ); + remove_filter( 'pre_option_stylesheet', array( $this, 'get_theme_slug' ) ); + remove_filter( 'pre_option_current_theme', array( $this, 'get_theme_name' ) ); + + remove_filter( 'pre_option_template_root', array( $this, 'get_theme_root' ) ); + remove_filter( 'pre_option_stylesheet_root', array( $this, 'get_theme_root' ) ); + + if ( ! empty( $this->themes_dir ) ) { + $index = array_search( untrailingslashit( $this->themes_dir ), $wp_theme_directories, true ); + if ( false !== $index ) { + array_splice( $wp_theme_directories, $index, 1 ); + $wp_theme_directories = array_values( $wp_theme_directories ); + + // Force new directory scan to remove the test theme directory. + search_theme_directories( true ); + } + } + }; + } + + /** + * Gets the theme slug. + * + * Used as a filter callback. + * + * @since n.e.x.t + * + * @return string The theme slug. + */ + public function get_theme_slug() { + return $this->theme_slug; + } + + /** + * Gets the theme name. + * + * Used as a filter callback. + * + * @since n.e.x.t + * + * @return string The theme name. + */ + public function get_theme_name() { + $theme = wp_get_theme( $this->theme_slug, $this->themes_dir ); + return $theme->display( 'Name' ); + } + + /** + * Gets the theme root. + * + * Used as a filter callback. + * + * @since n.e.x.t + * + * @return string The theme root. + */ + public function get_theme_root() { + return get_raw_theme_root( $this->theme_slug, true ); + } +} diff --git a/plugin-check.php b/plugin-check.php index b36261e8f..685f752e5 100644 --- a/plugin-check.php +++ b/plugin-check.php @@ -78,5 +78,4 @@ function wp_plugin_check_display_composer_autoload_notice() { echo '
'; } - wp_plugin_check_load(); diff --git a/test-content/themes/wp-empty-theme/comments.php b/test-content/themes/wp-empty-theme/comments.php new file mode 100644 index 000000000..cb12f364f --- /dev/null +++ b/test-content/themes/wp-empty-theme/comments.php @@ -0,0 +1,77 @@ + + +
+ +
+ ++ 60, + 'style' => 'ol', + 'short_ping' => true, + ) + ); + ?> +
+ + esc_html__( 'Page', 'wp-empty-theme' ) . ' ', + 'mid_size' => 0, + 'prev_text' => sprintf( + '%s', + esc_html__( 'Older comments', 'wp-empty-theme' ) + ), + 'next_text' => sprintf( + '%s', + esc_html__( 'Newer comments', 'wp-empty-theme' ) + ), + ) + ); + + if ( ! comments_open() ) { + ?> + + null, + 'title_reply' => esc_html__( 'Leave a comment', 'wp-empty-theme' ), + 'title_reply_before' => '', + 'title_reply_after' => '
', + ) + ); + ?> +