$content_size, '--wp--custom--layout--wide-size' => $wide_size, '--wp--custom--border' => "$border_width $border_style $border_color", '--wp--custom--body--background' => $body_background, '--wp--custom--body--color' => $body_color, // Gutenberg .wp-element-button issue workaround. Also used by input. '--wp--custom--button--background' => $button_background, '--wp--custom--button--color' => $button_text, '--wp--custom--button--padding-top' => $button_padding['top'] ?? null, '--wp--custom--button--padding-right' => $button_padding['right'] ?? null, '--wp--custom--button--padding-bottom' => $button_padding['bottom'] ?? null, '--wp--custom--button--padding-left' => $button_padding['left'] ?? null, '--wp--custom--button--border-radius' => $button_border_radius, '--wp--custom--button--border-width' => $button_border_width, '--wp--custom--button--font-size' => $button_font_size, '--wp--custom--button--font-weight' => $button_font_weight, '--wp--custom--button--line-height' => $button_line_height, ]; $css = $element . '{' . css_array_to_string( $all ) . '}'; wp_add_inline_style( is_admin() ? 'blockify-editor' : 'global-styles', $css ); } add_action( 'wp_enqueue_scripts', NS . 'enqueue_block_styles' ); /** * Enqueues front end scripts. * * @since 0.0.2 * * @return void */ function enqueue_block_styles(): void { global $wp_styles; wp_dequeue_style( 'wp-block-library-theme' ); if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { return; } $handles = array_flip( $wp_styles->queue ) ?? []; foreach ( $wp_styles->registered as $handle => $style ) { if ( ! isset( $handles[ $handle ] ) ) { continue; } $slug = str_replace( 'wp-block-', '', $handle ); $file = DIR . 'assets/css/blocks/' . $slug . '.css'; if ( file_exists( $file ) ) { wp_add_inline_style( $handle, file_get_contents( $file ) ); } } } add_action( 'blockify_editor_scripts', NS . 'add_conditional_styles', 11 ); add_action( 'wp_enqueue_scripts', NS . 'add_conditional_styles' ); /** * Adds split styles. * * @since 0.0.27 * * @return void */ function add_conditional_styles(): void { $styles = ''; $stylesheets = [ ...glob( DIR . 'assets/css/elements/*.css' ), ...glob( DIR . 'assets/css/components/*.css' ), ...glob( DIR . 'assets/css/extensions/*.css' ), ]; $conditions = [ 'admin-bar' => is_admin_bar_showing(), 'wp-org' => is_pattern_preview(), ]; foreach ( $stylesheets as $stylesheet ) { if ( $conditions[ basename( $stylesheet, '.css' ) ] ?? true ) { $styles .= trim( file_get_contents( $stylesheet ) ); } } wp_add_inline_style( is_admin() ? 'blockify-editor' : 'global-styles', $styles ); } add_action( 'blockify_editor_scripts', NS . 'add_dark_mode_custom_properties' ); add_action( 'wp_enqueue_scripts', NS . 'add_dark_mode_custom_properties' ); /** * Adds dark mode custom properties. * * @since 0.0.24 * * @return void */ function add_dark_mode_custom_properties(): void { $options = get_option( SLUG ); $enabled = true; if ( isset( $options['darkMode'] ) ) { $enabled = $options['darkMode'] === 'true'; } if ( ! $enabled && ! is_admin() ) { return; } $global_settings = wp_get_global_settings(); if ( ! isset( $global_settings['color']['palette']['theme'] ) ) { return; } $colors = []; foreach ( $global_settings['color']['palette']['theme'] as $color ) { $colors[ $color['slug'] ] = $color['color']; } $original = []; $properties = []; // Allows colors to be filtered with PHP, or removed in child theme json. $config = get_sub_config( 'darkModeColorPalette', null ); if ( ! $config ) { return; } foreach ( $colors as $slug => $color ) { if ( ! isset( $config[ $slug ] ) || ! is_string( $config[ $slug ] ) ) { continue; } if ( ! array_key_exists( $config[ $slug ], $colors ) ) { continue; } $original[ '--wp--preset--color--' . $slug ] = $color; $properties[ '--wp--preset--color--' . $slug ] = $colors[ $config[ $slug ] ]; } $body_element = is_admin() ? 'body .has-dark-mode' : 'body'; $new_css = '@media(prefers-color-scheme:dark){' . $body_element . '{'; foreach ( $properties as $property => $value ) { $new_css .= "$property:$value;"; } $new_css .= '}}.dark-mode{'; foreach ( $properties as $property => $value ) { $new_css .= "$property:$value;"; } $new_css .= '}.light-mode{'; foreach ( $original as $property => $value ) { $new_css .= "$property:$value;"; } $new_css .= '}'; wp_add_inline_style( is_admin() ? 'blockify-editor' : 'global-styles', $new_css ); }