get_import_post_type() ); $preview_css = FORWP_DRIVE_PATH . 'assets/admin-preview.css'; wp_enqueue_style( 'forwp-drive-admin-preview', FORWP_DRIVE_URL . 'assets/admin-preview.css', array( 'forwp-drive-admin', 'forwp-drive-preview-theme-scoped' ), file_exists( $preview_css ) ? (string) filemtime( $preview_css ) : FORWP_DRIVE_VERSION ); } /** * Limit theme CSS to the preview panel so wp-admin chrome is unaffected. * * @param string $css Raw stylesheet contents. */ public static function scope_css( string $css ): string { $css = trim( $css ); if ( '' === $css ) { return ''; } return sprintf( '@scope (%s) { %s }', self::PREVIEW_SCOPE, $css ); } /** * Read active theme styles and wrap them for preview-only use. */ private static function collect_scoped_theme_css(): string { $parts = array(); if ( function_exists( 'wp_get_global_stylesheet' ) ) { $global = wp_get_global_stylesheet( array( 'variables', 'presets', 'styles' ) ); if ( is_string( $global ) && '' !== trim( $global ) ) { $parts[] = $global; } } $theme_dir = get_stylesheet_directory(); $style_path = $theme_dir . '/style.css'; if ( is_readable( $style_path ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local theme file. $theme_css = self::strip_theme_header( (string) file_get_contents( $style_path ) ); if ( '' !== $theme_css ) { $parts[] = $theme_css; } } $bundled = array( 'custom.css', 'single.css', 'articles.css' ); foreach ( $bundled as $file ) { $path = $theme_dir . '/assets/css/' . $file; if ( ! is_readable( $path ) ) { continue; } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local theme file. $file_css = trim( (string) file_get_contents( $path ) ); if ( '' !== $file_css ) { $parts[] = $file_css; } } if ( array() === $parts ) { return ''; } return self::scope_css( implode( "\n", $parts ) ); } /** * Remove the theme file header comment from style.css. * * @param string $css Theme stylesheet contents. */ private static function strip_theme_header( string $css ): string { return trim( (string) preg_replace( '/^\/\*[\s\S]*?\*\/\s*/', '', $css ) ); } }