priorities = array_keys( $wp_filter[ 'wp_enqueue_scripts' ]->callbacks ); // add hook directly after each priority to get any added stylesheet handles foreach ( $this->priorities as $priority ) add_action( 'wp_enqueue_scripts', array( $this, 'get_handles' ), $priority ); } public function get_handles(){ global $wp_styles; // remove priority from stack $priority = array_shift( $this->priorities ); if ( !is_object( $wp_styles ) ) return; // get handles queued since last check $this->handles[ $priority ] = array_diff( $wp_styles->queue, $this->queued ); // add new handles to queued array $this->queued = array_merge( $this->queued, $this->handles[ $priority ] ); } public function setup_theme() { // are we previewing? - removed nonce requirement to bool flag v2.2.5 if ( empty( $_GET['preview_ctc'] ) || !current_user_can( 'switch_themes' ) ) return; $this->original_stylesheet = get_stylesheet(); $this->theme = wp_get_theme( isset( $_GET[ 'stylesheet' ] ) ? $_GET[ 'stylesheet' ] : NULL ); if ( ! $this->is_theme_active() ): add_filter( 'template', array( $this, 'get_template' ) ); add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) ); // @link: https://core.trac.wordpress.org/ticket/20027 add_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) ); add_filter( 'pre_option_template', array( $this, 'get_template' ) ); // swap out theme mods with preview theme mods add_filter( 'pre_option_theme_mods_' . $this->original_stylesheet, array( $this, 'preview_mods' ) ); endif; add_action( 'wp_head', array( $this, 'check_wp_queue' ), 0 ); // impossibly high priority to test for stylesheets loaded after wp_head() add_action( 'wp_print_styles', array( $this, 'test_css' ), 999999 ); // pass the wp_styles queue back to use for stylesheet handle verification add_action( 'wp_footer', array( $this, 'parse_stylesheet' ) ); send_origin_headers(); // hide admin bar in preview show_admin_bar( false ); } /** * Retrieves child theme mods for preview */ public function preview_mods() { if ( $this->is_theme_active() ) return false; return get_option( 'theme_mods_' . $this->get_stylesheet() ); } public function parse_stylesheet() { echo '' . LF; } // enqueue dummy stylesheet with extremely high priority to test wp_head() public function test_css() { wp_enqueue_style( 'ctc-test', get_stylesheet_directory_uri() . '/ctc-test.css' ); } public function woocommerce_unforce_ssl_checkout( $bool ){ return FALSE; } public function wp_redirect_status( $status ) { return 200; } public function is_theme_active() { return $this->get_stylesheet() == $this->original_stylesheet; } public function get_template() { return $this->theme()->get_template(); } public function get_stylesheet() { return $this->theme()->get_stylesheet(); } public function theme() { return $this->theme; } }