Skip to content

Commit 83e6216

Browse files
committed
feat(styles): publish per-file manifest for admin-uploaded styles
build_theme_registry_override() now ships a 'files' array alongside each uploaded entry, enumerated from the extracted storage directory. The embedded editor's ResourceFetcher reads this manifest to pull admin-uploaded styles file by file instead of looking for a zip in bundles/themes/, so preview and HTML5 export pack the real theme assets (CSS, fonts, icons) under theme/* rather than falling back to the placeholder theme/content.css + theme/default.js.
1 parent ee75518 commit 83e6216

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

includes/class-styles-service.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ public static function build_theme_registry_override() {
225225
continue;
226226
}
227227
$css_files = isset( $meta['css_files'] ) && is_array( $meta['css_files'] ) ? array_values( $meta['css_files'] ) : array( 'style.css' );
228+
$files = self::list_uploaded_files( $slug );
228229
$uploaded[] = array(
229230
'id' => (string) $slug,
230231
'name' => (string) $slug,
@@ -237,6 +238,7 @@ public static function build_theme_registry_override() {
237238
'type' => 'admin',
238239
'url' => trailingslashit( self::get_storage_url() ) . rawurlencode( $slug ),
239240
'cssFiles' => array_values( array_map( 'strval', $css_files ) ),
241+
'files' => $files,
240242
'downloadable' => '0',
241243
'valid' => true,
242244
);
@@ -730,6 +732,44 @@ private static function find_css_files( $dir ) {
730732
return $out;
731733
}
732734

735+
/**
736+
* Walk an uploaded style's extracted directory and return every file
737+
* inside it as a list of forward-slash relative paths. Used to publish
738+
* a per-file manifest to the embedded editor so its preview/export
739+
* pipeline can fetch admin-uploaded styles without a zip bundle.
740+
*
741+
* @param string $slug Uploaded style slug (already validated).
742+
* @return string[] Sorted relative paths; empty array if the directory is missing.
743+
*/
744+
public static function list_uploaded_files( $slug ) {
745+
$slug = self::normalize_slug( $slug );
746+
$dir = trailingslashit( self::get_storage_dir() ) . $slug;
747+
if ( ! is_dir( $dir ) ) {
748+
return array();
749+
}
750+
$base_len = strlen( trailingslashit( $dir ) );
751+
$out = array();
752+
try {
753+
$iter = new RecursiveIteratorIterator(
754+
new RecursiveDirectoryIterator( $dir, FilesystemIterator::SKIP_DOTS ),
755+
RecursiveIteratorIterator::LEAVES_ONLY
756+
);
757+
foreach ( $iter as $file_info ) {
758+
if ( ! $file_info->isFile() ) {
759+
continue;
760+
}
761+
$absolute = (string) $file_info->getPathname();
762+
$relative = substr( $absolute, $base_len );
763+
$relative = str_replace( DIRECTORY_SEPARATOR, '/', $relative );
764+
$out[] = $relative;
765+
}
766+
} catch ( Exception $e ) {
767+
return array();
768+
}
769+
sort( $out );
770+
return $out;
771+
}
772+
733773
/**
734774
* Normalize a user-supplied id so it is safe to embed in paths and URLs.
735775
*

0 commit comments

Comments
 (0)