Changeset 14151
- Timestamp:
- 10/28/2024 04:20:05 PM (16 months ago)
- Location:
- sites/trunk/wp-themes.com/public_html/wp-content/plugins/style-variations
- Files:
-
- 2 edited
-
inc/global-style-page.php (modified) (1 diff)
-
views/card.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wp-themes.com/public_html/wp-content/plugins/style-variations/inc/global-style-page.php
r12349 r14151 4 4 5 5 /** 6 * Uses custom page if query string is present to display style variation cards. 6 * Bypass the template loader to show the "card view" when query string is present. 7 * 8 * @param string $template The path of the template to include. 9 * 10 * @return string Updated template path. 7 11 */ 8 function redirect_to_style_page() {12 function inject_style_card_view( $template ) { 9 13 if ( ! isset( $_GET['card_view'] ) ) { 10 return ;14 return $template; 11 15 } 12 16 13 include dirname( __DIR__ ) . '/views/card.php'; 14 exit; 15 17 return dirname( __DIR__ ) . '/views/card.php'; 16 18 } 17 19 18 add_action( 'template_ redirect', __NAMESPACE__ . '\redirect_to_style_page');20 add_action( 'template_include', __NAMESPACE__ . '\inject_style_card_view', 100 ); -
sites/trunk/wp-themes.com/public_html/wp-content/plugins/style-variations/views/card.php
r12349 r14151 9 9 $global_settings = wp_get_global_settings(); 10 10 $palette = $global_settings['color']['palette']; 11 12 $global_styles = wp_get_global_styles(); 13 $has_set_background = isset( $global_styles['color'], $global_styles['color']['background'] ); 14 15 $classes = 'wporg-global-style-container'; 16 17 // If the background is not set via theme.json's color.background setting, the background might be set on 18 // a wrapper element in the template. This will try to find the first child element of the template with 19 // a background color, and pull out those classes to use on the global style container. 20 // For example, it should add `has-first-background-color`, or `has-custom-main-gradiant-gradient-background`. 21 if ( ! $has_set_background ) { 22 $template_html = get_the_block_template_html(); 23 24 $tags = new \WP_HTML_Tag_Processor( $template_html ); 25 if ( $tags->next_tag( [ 'class_name' => 'has-background' ] ) ) { 26 $classes .= ' ' . $tags->get_attribute( 'class' ); 27 } 28 } 11 29 12 30 ?><!DOCTYPE html> … … 64 82 65 83 <body <?php body_class(); ?>> 66 <div class="wporg-global-style-container"> 84 85 <div class="<?php echo esc_attr( $classes ); ?>"> 67 86 <div> 68 87 <div><h1 id="wporg-global-style-heading">Aa</h1></div> … … 96 115 var bodyColor = rgba2hex( window.getComputedStyle( document.body ).backgroundColor ).toLowerCase(); 97 116 117 // If no background is set on this element, it's still a valid value (#0000). 118 var divColor = rgba2hex( window.getComputedStyle( document.querySelector( '.wporg-global-style-container' ) ).backgroundColor ).toLowerCase(); 119 98 120 // Remove the already used colors 99 var colors = palette.theme.filter( entry => ! [ h1TextColor, bodyColor ].includes( entry.color.toLowerCase() ) );121 var colors = palette.theme.filter( entry => ! [ h1TextColor, bodyColor, divColor ].includes( entry.color.toLowerCase() ) ); 100 122 101 123 // Create circles for the first 2 colors.
Note: See TracChangeset
for help on using the changeset viewer.