Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp_add_inline_style and wp-rig-global-css #8

Open
megphillips91 opened this issue Nov 8, 2020 · 1 comment
Open

wp_add_inline_style and wp-rig-global-css #8

megphillips91 opened this issue Nov 8, 2020 · 1 comment

Comments

@megphillips91
Copy link

megphillips91 commented Nov 8, 2020

inc/Styles/Component.php

What is the recommended best practice for pulling in customizer styles with WP_Rig 2.0?

In WP_Rig 1.x, I built a function which referenced the theme mods and output the user determined global typography, color settings into the global styles file using wp_add_inline_style.

In Wp_Rig 2.0, I've tried to do the same within inc/Styles/Component.php, but it does not work. When I used this technique in WP_Rig 1.x it worked well. Maybe I am doing it wrong, but I didn't see anything in the documentation regarding the best practice to output css back into the wp-rig-global-css styles from the customizer.

WP add inline styles from manual

`
public function action_enqueue_styles() {
// Enqueue Google Fonts.
$google_fonts_url = $this->get_google_fonts_url();
if ( ! empty( $google_fonts_url ) ) {
wp_enqueue_style( 'wp-rig-fonts', $google_fonts_url, [], null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
}

	$css_uri = get_theme_file_uri( '/assets/css/' );
	$css_dir = get_theme_file_path( '/assets/css/' );

	$preloading_styles_enabled = $this->preloading_styles_enabled();

	$css_files = $this->get_css_files();
	foreach ( $css_files as $handle => $data ) {
		$src     = $css_uri . $data['file'];
		$version = wp_rig()->get_asset_version( $css_dir . $data['file'] );

		/*
		 * Enqueue global stylesheets immediately and register the other ones for later use
		 * (unless preloading stylesheets is disabled, in which case stylesheets should be immediately
		 * enqueued based on whether they are necessary for the page content).
		 */
		if ( $data['global'] || ! $preloading_styles_enabled && is_callable( $data['preload_callback'] ) && call_user_func( $data['preload_callback'] ) ) {
			wp_enqueue_style( $handle, $src, [], $version, $data['media'] );
		} else {
			wp_register_style( $handle, $src, [], $version, $data['media'] );
		}
		wp_style_add_data( $handle, 'precache', true );
	}
	$customizations = wprig_return_customizer_styles();
	wp_add_inline_style('wp-rig-global-css', $customizations );
}

`

@benoitchantre
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants