updated theme GeneratePress
version 3.1.3
This commit is contained in:
@ -92,6 +92,34 @@ function generate_get_block_editor_content_width() {
|
||||
return apply_filters( 'generate_block_editor_content_width', $content_width );
|
||||
}
|
||||
|
||||
add_filter( 'block_editor_settings_all', 'generate_add_inline_block_editor_styles' );
|
||||
/**
|
||||
* Add dynamic inline styles to the block editor content.
|
||||
*
|
||||
* @param array $editor_settings The existing editor settings.
|
||||
*/
|
||||
function generate_add_inline_block_editor_styles( $editor_settings ) {
|
||||
$show_editor_styles = apply_filters( 'generate_show_block_editor_styles', true );
|
||||
|
||||
if ( $show_editor_styles ) {
|
||||
if ( generate_is_using_dynamic_typography() ) {
|
||||
$google_fonts_uri = GeneratePress_Typography::get_google_fonts_uri();
|
||||
|
||||
if ( $google_fonts_uri ) {
|
||||
// Need to use @import for now until this is ready: https://github.com/WordPress/gutenberg/pull/35950.
|
||||
$google_fonts_import = sprintf(
|
||||
'@import "%s";',
|
||||
$google_fonts_uri
|
||||
);
|
||||
|
||||
$editor_settings['styles'][] = array( 'css' => $google_fonts_import );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $editor_settings;
|
||||
}
|
||||
|
||||
add_action( 'enqueue_block_editor_assets', 'generate_enqueue_google_fonts' );
|
||||
add_action( 'enqueue_block_editor_assets', 'generate_enqueue_backend_block_editor_assets' );
|
||||
/**
|
||||
@ -100,18 +128,17 @@ add_action( 'enqueue_block_editor_assets', 'generate_enqueue_backend_block_edito
|
||||
* @since 2.2
|
||||
*/
|
||||
function generate_enqueue_backend_block_editor_assets() {
|
||||
wp_enqueue_style( 'generate-block-editor-styles', get_template_directory_uri() . '/assets/css/admin/block-editor.css', false, GENERATE_VERSION, 'all' );
|
||||
wp_enqueue_script( 'generate-block-editor-tinycolor', get_template_directory_uri() . '/assets/js/admin/tinycolor.js', false, GENERATE_VERSION, true );
|
||||
wp_enqueue_script( 'generate-block-editor-scripts', get_template_directory_uri() . '/assets/js/admin/block-editor.js', array( 'jquery', 'generate-block-editor-tinycolor' ), GENERATE_VERSION, true );
|
||||
|
||||
$show_editor_styles = apply_filters( 'generate_show_block_editor_styles', true );
|
||||
|
||||
if ( $show_editor_styles ) {
|
||||
wp_add_inline_style( 'generate-block-editor-styles', wp_strip_all_tags( generate_do_inline_block_editor_css() ) );
|
||||
// Using wp-edit-blocks for now until we do this: https://github.com/tomusborne/generatepress/pull/343.
|
||||
wp_add_inline_style( 'wp-edit-blocks', wp_strip_all_tags( generate_do_inline_block_editor_css() ) );
|
||||
|
||||
if ( generate_is_using_dynamic_typography() ) {
|
||||
wp_enqueue_style( 'generate-editor-typography', get_template_directory_uri() . '/assets/css/admin/editor-typography.css', false, GENERATE_VERSION, 'all' );
|
||||
wp_add_inline_style( 'generate-editor-typography', wp_strip_all_tags( GeneratePress_Typography::get_css( 'core', 'editor' ) ) );
|
||||
wp_add_inline_style( 'wp-edit-blocks', wp_strip_all_tags( GeneratePress_Typography::get_css( 'core', 'editor' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,7 +247,7 @@ function generate_do_inline_block_editor_css() {
|
||||
$css->add_property( 'max-width', $content_width_calc );
|
||||
}
|
||||
|
||||
$css->set_selector( 'html body.gutenberg-editor-page .block-editor-block-list__block[data-align="full"]' );
|
||||
$css->set_selector( '.editor-styles-wrapper .wp-block[data-align="full"]' );
|
||||
$css->add_property( 'max-width', 'none' );
|
||||
|
||||
$css->set_selector( '.wp-block[data-align="wide"]' );
|
||||
@ -281,7 +308,7 @@ function generate_do_inline_block_editor_css() {
|
||||
$buttons_family = generate_get_font_family_css( 'font_buttons', 'generate_settings', generate_get_default_fonts() );
|
||||
}
|
||||
|
||||
$css->set_selector( 'body.gutenberg-editor-page .block-editor-block-list__block, body .editor-styles-wrapper' );
|
||||
$css->set_selector( 'body.gutenberg-editor-page .block-editor-block-list__block, html .editor-styles-wrapper' );
|
||||
|
||||
if ( ! generate_is_using_dynamic_typography() ) {
|
||||
$css->add_property( 'font-family', $body_family );
|
||||
@ -303,15 +330,15 @@ function generate_do_inline_block_editor_css() {
|
||||
}
|
||||
|
||||
if ( ! generate_is_using_dynamic_typography() ) {
|
||||
$css->set_selector( 'body .editor-styles-wrapper, body .editor-styles-wrapper p, body .editor-styles-wrapper .mce-content-body' );
|
||||
$css->set_selector( 'html .editor-styles-wrapper, html .editor-styles-wrapper p, html .editor-styles-wrapper .mce-content-body' );
|
||||
$css->add_property( 'line-height', floatval( $font_settings['body_line_height'] ) );
|
||||
|
||||
$css->set_selector( 'body .editor-styles-wrapper p' );
|
||||
$css->set_selector( 'html .editor-styles-wrapper p' );
|
||||
$css->add_property( 'margin-top', '0px' );
|
||||
$css->add_property( 'margin-bottom', $font_settings['paragraph_margin'], false, 'em' );
|
||||
}
|
||||
|
||||
$css->set_selector( 'body .editor-styles-wrapper h1, .wp-block-heading h1.editor-rich-text__tinymce, .editor-styles-wrapper .editor-post-title__input' );
|
||||
$css->set_selector( 'html .editor-styles-wrapper h1, .wp-block-heading h1.editor-rich-text__tinymce, .editor-styles-wrapper .editor-post-title__input' );
|
||||
|
||||
if ( ! generate_is_using_dynamic_typography() ) {
|
||||
$css->add_property( 'font-family', 'inherit' === $h1_family || '' === $h1_family ? $body_family : $h1_family );
|
||||
@ -336,7 +363,7 @@ function generate_do_inline_block_editor_css() {
|
||||
$css->add_property( 'color', $color_settings['content_title_color'] );
|
||||
}
|
||||
|
||||
$css->set_selector( 'body .editor-styles-wrapper h2, .wp-block-heading h2.editor-rich-text__tinymce' );
|
||||
$css->set_selector( 'html .editor-styles-wrapper h2, .wp-block-heading h2.editor-rich-text__tinymce' );
|
||||
|
||||
if ( ! generate_is_using_dynamic_typography() ) {
|
||||
$css->add_property( 'font-family', $h2_family );
|
||||
@ -356,7 +383,7 @@ function generate_do_inline_block_editor_css() {
|
||||
$css->add_property( 'color', generate_get_option( 'text_color' ) );
|
||||
}
|
||||
|
||||
$css->set_selector( 'body .editor-styles-wrapper h3, .wp-block-heading h3.editor-rich-text__tinymce' );
|
||||
$css->set_selector( 'html .editor-styles-wrapper h3, .wp-block-heading h3.editor-rich-text__tinymce' );
|
||||
|
||||
if ( ! generate_is_using_dynamic_typography() ) {
|
||||
$css->add_property( 'font-family', $h3_family );
|
||||
@ -376,7 +403,7 @@ function generate_do_inline_block_editor_css() {
|
||||
$css->add_property( 'color', generate_get_option( 'text_color' ) );
|
||||
}
|
||||
|
||||
$css->set_selector( 'body .editor-styles-wrapper h4, .wp-block-heading h4.editor-rich-text__tinymce' );
|
||||
$css->set_selector( 'html .editor-styles-wrapper h4, .wp-block-heading h4.editor-rich-text__tinymce' );
|
||||
|
||||
if ( ! generate_is_using_dynamic_typography() ) {
|
||||
$css->add_property( 'font-family', $h4_family );
|
||||
@ -404,7 +431,7 @@ function generate_do_inline_block_editor_css() {
|
||||
$css->add_property( 'color', generate_get_option( 'text_color' ) );
|
||||
}
|
||||
|
||||
$css->set_selector( 'body .editor-styles-wrapper h5, .wp-block-heading h5.editor-rich-text__tinymce' );
|
||||
$css->set_selector( 'html .editor-styles-wrapper h5, .wp-block-heading h5.editor-rich-text__tinymce' );
|
||||
|
||||
if ( ! generate_is_using_dynamic_typography() ) {
|
||||
$css->add_property( 'font-family', $h5_family );
|
||||
@ -432,7 +459,7 @@ function generate_do_inline_block_editor_css() {
|
||||
$css->add_property( 'color', generate_get_option( 'text_color' ) );
|
||||
}
|
||||
|
||||
$css->set_selector( 'body .editor-styles-wrapper h6, .wp-block-heading h6.editor-rich-text__tinymce' );
|
||||
$css->set_selector( 'html .editor-styles-wrapper h6, .wp-block-heading h6.editor-rich-text__tinymce' );
|
||||
|
||||
if ( ! generate_is_using_dynamic_typography() ) {
|
||||
$css->add_property( 'font-family', $h6_family );
|
||||
|
@ -220,7 +220,7 @@ class GeneratePress_Dashboard {
|
||||
'siteIdentitySection' => admin_url( 'customize.php?autofocus[section]=title_tagline' ),
|
||||
'colorsSection' => admin_url( 'customize.php?autofocus[section]=generate_colors_section' ),
|
||||
'typographySection' => admin_url( 'customize.php?autofocus[section]=generate_typography_section' ),
|
||||
'layoutSection' => admin_url( 'customize.php?autofocus[section]=generate_layout_panel' ),
|
||||
'layoutSection' => admin_url( 'customize.php?autofocus[panel]=generate_layout_panel' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
@ -36,23 +36,25 @@ class GeneratePress_Typography {
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_google_fonts' ) );
|
||||
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_google_fonts' ) );
|
||||
add_filter( 'generate_editor_styles', array( $this, 'add_editor_styles' ) );
|
||||
|
||||
// Load fonts the old way in versions before 5.8 as block_editor_settings_all didn't exist.
|
||||
if ( version_compare( $GLOBALS['wp_version'], '5.8', '<' ) ) {
|
||||
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_google_fonts' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue Google Fonts if they're set.
|
||||
* Generate our Google Fonts URI.
|
||||
*/
|
||||
public function enqueue_google_fonts() {
|
||||
if ( ! generate_is_using_dynamic_typography() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
public static function get_google_fonts_uri() {
|
||||
$fonts = generate_get_option( 'font_manager' );
|
||||
|
||||
if ( empty( $fonts ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$google_fonts_uri = '';
|
||||
$data = array();
|
||||
|
||||
foreach ( $fonts as $font ) {
|
||||
@ -92,6 +94,22 @@ class GeneratePress_Typography {
|
||||
);
|
||||
|
||||
$google_fonts_uri = add_query_arg( $font_args, 'https://fonts.googleapis.com/css' );
|
||||
}
|
||||
|
||||
return $google_fonts_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue Google Fonts if they're set.
|
||||
*/
|
||||
public function enqueue_google_fonts() {
|
||||
if ( ! generate_is_using_dynamic_typography() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$google_fonts_uri = self::get_google_fonts_uri();
|
||||
|
||||
if ( $google_fonts_uri ) {
|
||||
wp_enqueue_style( 'generate-google-fonts', $google_fonts_uri, array(), GENERATE_VERSION );
|
||||
}
|
||||
}
|
||||
@ -118,14 +136,10 @@ class GeneratePress_Typography {
|
||||
|
||||
$body_selector = 'body';
|
||||
$paragraph_selector = 'p';
|
||||
$tablet_prefix = '';
|
||||
$mobile_prefix = '';
|
||||
|
||||
if ( 'editor' === $type ) {
|
||||
$body_selector = '.editor-styles-wrapper';
|
||||
$paragraph_selector = '.editor-styles-wrapper p';
|
||||
$tablet_prefix = '.gp-is-device-tablet ';
|
||||
$mobile_prefix = '.gp-is-device-mobile ';
|
||||
$body_selector = 'html .editor-styles-wrapper';
|
||||
$paragraph_selector = 'html .editor-styles-wrapper p';
|
||||
}
|
||||
|
||||
foreach ( $typography as $key => $data ) {
|
||||
@ -160,16 +174,7 @@ class GeneratePress_Typography {
|
||||
$css->add_property( 'margin-bottom', $options['marginBottom'], false, $options['marginBottomUnit'] );
|
||||
}
|
||||
|
||||
if ( 'frontend' === $type ) {
|
||||
$css->start_media_query( generate_get_media_query( 'tablet' ) );
|
||||
}
|
||||
|
||||
if ( 'editor' === $type ) {
|
||||
// Add the tablet prefix to each class.
|
||||
$selector = explode( ', ', $selector );
|
||||
$selector = preg_filter( '/^/', $tablet_prefix, $selector );
|
||||
$selector = implode( ', ', $selector );
|
||||
}
|
||||
$css->start_media_query( generate_get_media_query( 'tablet' ) );
|
||||
|
||||
$css->set_selector( $selector );
|
||||
$css->add_property( 'font-size', $options['fontSizeTablet'], false, $options['fontSizeUnit'] );
|
||||
@ -179,24 +184,16 @@ class GeneratePress_Typography {
|
||||
$css->add_property( 'line-height', $options['lineHeightTablet'], false, $options['lineHeightUnit'] );
|
||||
$css->add_property( 'margin-bottom', $options['marginBottomTablet'], false, $options['marginBottomUnit'] );
|
||||
} else {
|
||||
$css->set_selector( $tablet_prefix . $body_selector );
|
||||
$css->set_selector( $body_selector );
|
||||
$css->add_property( 'line-height', $options['lineHeightTablet'], false, $options['lineHeightUnit'] );
|
||||
|
||||
$css->set_selector( $tablet_prefix . $paragraph_selector );
|
||||
$css->set_selector( $paragraph_selector );
|
||||
$css->add_property( 'margin-bottom', $options['marginBottomTablet'], false, $options['marginBottomUnit'] );
|
||||
}
|
||||
|
||||
if ( 'frontend' === $type ) {
|
||||
$css->stop_media_query();
|
||||
}
|
||||
$css->stop_media_query();
|
||||
|
||||
if ( 'frontend' === $type ) {
|
||||
$css->start_media_query( generate_get_media_query( 'mobile' ) );
|
||||
}
|
||||
|
||||
if ( 'editor' === $type ) {
|
||||
$selector = str_replace( '.gp-is-device-tablet', '.gp-is-device-mobile', $selector );
|
||||
}
|
||||
$css->start_media_query( generate_get_media_query( 'mobile' ) );
|
||||
|
||||
$css->set_selector( $selector );
|
||||
$css->add_property( 'font-size', $options['fontSizeMobile'], false, $options['fontSizeUnit'] );
|
||||
@ -206,16 +203,14 @@ class GeneratePress_Typography {
|
||||
$css->add_property( 'line-height', $options['lineHeightMobile'], false, $options['lineHeightUnit'] );
|
||||
$css->add_property( 'margin-bottom', $options['marginBottomMobile'], false, $options['marginBottomUnit'] );
|
||||
} else {
|
||||
$css->set_selector( $mobile_prefix . $body_selector );
|
||||
$css->set_selector( $body_selector );
|
||||
$css->add_property( 'line-height', $options['lineHeightMobile'], false, $options['lineHeightUnit'] );
|
||||
|
||||
$css->set_selector( $mobile_prefix . $paragraph_selector );
|
||||
$css->set_selector( $paragraph_selector );
|
||||
$css->add_property( 'margin-bottom', $options['marginBottomMobile'], false, $options['marginBottomUnit'] );
|
||||
}
|
||||
|
||||
if ( 'frontend' === $type ) {
|
||||
$css->stop_media_query();
|
||||
}
|
||||
$css->stop_media_query();
|
||||
}
|
||||
|
||||
return $css->css_output();
|
||||
@ -288,7 +283,7 @@ class GeneratePress_Typography {
|
||||
if ( 'editor' === $type ) {
|
||||
switch ( $selector ) {
|
||||
case 'body':
|
||||
$selector = 'body .editor-styles-wrapper';
|
||||
$selector = 'html .editor-styles-wrapper';
|
||||
break;
|
||||
|
||||
case 'buttons':
|
||||
@ -296,15 +291,15 @@ class GeneratePress_Typography {
|
||||
break;
|
||||
|
||||
case 'all-headings':
|
||||
$selector = '.editor-styles-wrapper h1, .editor-styles-wrapper h2, .editor-styles-wrapper h3, .editor-styles-wrapper h4, .editor-styles-wrapper h5, .editor-styles-wrapper h6';
|
||||
$selector = 'html .editor-styles-wrapper h1, html .editor-styles-wrapper h2, html .editor-styles-wrapper h3, html .editor-styles-wrapper h4, html .editor-styles-wrapper h5, html .editor-styles-wrapper h6';
|
||||
break;
|
||||
|
||||
case 'h1':
|
||||
$selector = '.editor-styles-wrapper h1, .editor-styles-wrapper .editor-post-title__input';
|
||||
$selector = 'html .editor-styles-wrapper h1, html .editor-styles-wrapper .editor-post-title__input';
|
||||
break;
|
||||
|
||||
case 'single-content-title':
|
||||
$selector = '.editor-styles-wrapper .editor-post-title__input';
|
||||
$selector = 'html .editor-styles-wrapper .editor-post-title__input';
|
||||
break;
|
||||
|
||||
case 'h2':
|
||||
@ -312,7 +307,7 @@ class GeneratePress_Typography {
|
||||
case 'h4':
|
||||
case 'h5':
|
||||
case 'h6':
|
||||
$selector = '.editor-styles-wrapper ' . $selector;
|
||||
$selector = 'html .editor-styles-wrapper ' . $selector;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -378,6 +373,19 @@ class GeneratePress_Typography {
|
||||
'marginBottomUnit' => 'px',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add editor styles to the block editor.
|
||||
*
|
||||
* @param array $editor_styles Existing styles.
|
||||
*/
|
||||
public function add_editor_styles( $editor_styles ) {
|
||||
if ( generate_is_using_dynamic_typography() ) {
|
||||
$editor_styles[] = 'assets/css/admin/editor-typography.css';
|
||||
}
|
||||
|
||||
return $editor_styles;
|
||||
}
|
||||
}
|
||||
|
||||
GeneratePress_Typography::get_instance();
|
||||
|
@ -328,6 +328,10 @@ function generate_do_control_inline_scripts() {
|
||||
true
|
||||
);
|
||||
|
||||
if ( function_exists( 'wp_set_script_translations' ) ) {
|
||||
wp_set_script_translations( 'generate-customizer-controls', 'generatepress' );
|
||||
}
|
||||
|
||||
$color_palette = get_theme_support( 'editor-color-palette' );
|
||||
$colors = array();
|
||||
|
||||
|
Reference in New Issue
Block a user