Skip to content

Commit

Permalink
Global Styles: Create new public function to make it easier to expose…
Browse files Browse the repository at this point in the history
… style variations from other themes
  • Loading branch information
scruffian committed Jul 9, 2024
1 parent ae20515 commit 1cdd6be
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,18 @@ private static function style_variation_has_scope( $variation, $scope ) {
* @return array
*/
public static function get_style_variations( $scope = 'theme' ) {

Check warning on line 766 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Unused function parameter $scope.
return static::get_style_variations_from_directory( get_stylesheet_directory() );
}

/**
* Returns the style variation files defined by the theme (parent and child).
*
* @since 6.7.0
*
* @return array An array of style variation files.
*/
protected static function get_style_variation_files_from_current_theme() {
$variation_files = array();
$variations = array();
$base_directory = get_stylesheet_directory() . '/styles';
$template_directory = get_template_directory() . '/styles';
if ( is_dir( $base_directory ) ) {
Expand All @@ -783,6 +793,29 @@ public static function get_style_variations( $scope = 'theme' ) {
}
$variation_files = array_merge( $variation_files, $variation_files_parent );
}

return $variation_files;
}

/**
* Returns the style variations in the given directory.
*
* @since 6.7.0
*
* @param string $directory The directory to get the style variations from.
* @param string $scope The scope or type of style variation to retrieve e.g. theme, block etc.
* @return array
*/
public static function get_style_variations_from_directory( $directory, $scope = 'theme' ) {
$variation_files = array();

Check warning on line 810 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 1 space but found 4 spaces
$variations = array();

Check warning on line 811 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 6 spaces but found 9 spaces
if ( is_dir( $directory ) ) {
if ( $directory === get_stylesheet_directory() ) {

Check failure on line 813 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Use Yoda Condition checks, you must.
$variation_files = static::get_style_variation_files_from_current_theme();
} else {
$variation_files = static::recursively_iterate_json( $base_directory );

Check warning on line 816 in lib/class-wp-theme-json-resolver-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Variable $base_directory is undefined.
}
}
ksort( $variation_files );
foreach ( $variation_files as $path => $file ) {
$decoded_file = self::read_json_file( $path );
Expand Down

0 comments on commit 1cdd6be

Please sign in to comment.