Changeset 14190
- Timestamp:
- 11/21/2024 07:16:33 PM (2 months ago)
- Location:
- sites/trunk/wp-themes.com/public_html/wp-content/plugins/style-variations
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wp-themes.com/public_html/wp-content/plugins/style-variations/inc/page-intercept.php
r13301 r14190 2 2 3 3 namespace WordPressdotorg\Theme_Preview\Style_Variations\Page_Intercept; 4 5 use function WordPressdotorg\Theme_Preview\Style_Variations\get_style_variations; 4 6 5 7 /** … … 30 32 * Retrieve all variations and match to make sure we have one with the same title. 31 33 */ 32 $variations = \WP_Theme_JSON_Resolver::get_style_variations();34 $variations = get_style_variations(); 33 35 if ( empty( $variations ) ) { 34 36 return false; … … 99 101 * We need to call gutenberg's filter `theme_json_user` to make sure the styles are applied to the page. 100 102 * This use to work for both the page and card but a core change stopped that. 101 * 103 * 102 104 * See: https://core.trac.wordpress.org/ticket/56812 103 * 105 * 104 106 * We now need to also call the core filter `wp_theme_json_data_user` to get the card preview to work. 105 107 * Hopefully this code can be remove when we have a better component to use. 106 * 108 * 107 109 * Ref: https://github.com/WordPress/gutenberg/issues/44886 108 110 -
sites/trunk/wp-themes.com/public_html/wp-content/plugins/style-variations/inc/styles-endpoint.php
r13301 r14190 3 3 namespace WordPressdotorg\Theme_Preview\Style_Variations\API_Endpoint; 4 4 5 use function WordPressdotorg\Theme_Preview\Style_Variations\get_style_variations; 6 5 7 function endpoint_handler() { 6 $variations = \WP_Theme_JSON_Resolver::get_style_variations();8 $variations = get_style_variations(); 7 9 $theme_slug = get_option( 'stylesheet' ); 8 10 $styles = array(); … … 26 28 foreach ( $variations as $variation ) { 27 29 $title = strtolower( $variation['title'] ); 28 $link = add_query_arg( 'style_variation', urlencode( $title ), $base ); ;30 $link = add_query_arg( 'style_variation', urlencode( $title ), $base ); 29 31 30 32 $styles[] = array( -
sites/trunk/wp-themes.com/public_html/wp-content/plugins/style-variations/style-variations.php
r12349 r14190 13 13 defined( 'WPINC' ) || die(); 14 14 15 /** 16 * Get unique style variations. 17 * 18 * If there are multiple variations matching a title, use the longest. This is 19 * a rough way to check for full (combined) style variations, as opposed to 20 * color palettes or type sets. 21 * 22 * @return array Variation list, or empty array. 23 */ 24 function get_style_variations() { 25 $variations = array(); 26 $all_variations = \WP_Theme_JSON_Resolver::get_style_variations(); 27 28 foreach ( $all_variations as $variation ) { 29 // Safety check: variations must have a title and settings. 30 if ( ! isset( $variation['title'], $variation['settings'] ) ) { 31 continue; 32 } 33 $found_variations = wp_list_filter( 34 $variations, 35 array( 'title' => $variation['title'] ) 36 ); 37 if ( ! $found_variations ) { 38 $variations[] = $variation; 39 } else { 40 // Loop over the found variations, even though there should only 41 // ever be one, to keep track of the index value. 42 foreach ( $found_variations as $i => $found ) { 43 $found_settings = wp_json_encode( $found ); 44 $new_settings = wp_json_encode( $variation ); 45 if ( strlen( $new_settings ) > strlen( $found_settings ) ) { 46 // Replace the item in the variations list. 47 $variations[ $i ] = $variation; 48 } 49 } 50 } 51 } 52 53 return $variations; 54 } 55 15 56 require_once __DIR__ . '/inc/global-style-page.php'; 16 57 require_once __DIR__ . '/inc/page-intercept.php';
Note: See TracChangeset
for help on using the changeset viewer.