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

Gutenberg support #2018

Merged
merged 3 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/css/class-kirki-modules-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public function init() {

// If we're in the customizer, load inline no matter what.
add_action( 'wp_enqueue_scripts', array( $this, 'inline_dynamic_css' ), $priority );
add_action( 'enqueue_block_editor_assets', array( $this, 'inline_dynamic_css' ), $priority );

// If we're using file method, on save write the new styles.
if ( 'file' === $method ) {
Expand Down Expand Up @@ -174,6 +175,9 @@ public function init() {

// If we got this far then add styles inline.
add_action( 'wp_enqueue_scripts', array( $this, 'inline_dynamic_css' ), $priority );

// Admin styles, adds Gutenberg compatibility.
add_action( 'admin_enqueue_scripts', array( $this, 'inline_dynamic_css' ), $priority );
}

/**
Expand Down
14 changes: 14 additions & 0 deletions modules/css/class-kirki-output.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ protected function parse_output() {
}

$value = $this->process_value( $value, $output );

// Set the context.
if ( ! isset( $output['context'] ) || empty( $output['context'] ) ) {
$output['context'] = array( 'front' );
}

// Check if this is an admin style.
if ( is_admin() && ! is_customize_preview() ) {
if ( ! in_array( 'editor', $output['context'] ) ) {
return;
}
} elseif ( ! in_array( 'front', $output['context'] ) ) {
return;
}
$this->process_output( $output, $value );
}
}
Expand Down
3 changes: 3 additions & 0 deletions modules/postmessage/class-kirki-modules-postmessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ protected function script( $args ) {
if ( ! isset( $js_var['function'] ) || 'html' !== $js_var['function'] ) {
$add_css = true;
}
if ( isset( $js_var['context'] ) && ! in_array( 'front', $js_var['context'] ) ) {
$add_css = false;
}
}

if ( $add_css ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Kirki_Modules_Webfont_Loader {
*/
protected function __construct() {
add_action( 'wp_head', array( $this, 'enqueue_scripts' ), 20 );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 20 );
}

/**
Expand Down
4 changes: 4 additions & 0 deletions modules/webfonts/class-kirki-modules-webfonts-async.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public function __construct( $config_id, $webfonts, $googlefonts, $args = array(
add_action( 'wp_head', array( $this, 'webfont_loader' ) );
add_action( 'wp_head', array( $this, 'webfont_loader_script' ), 30 );

// Add these in the dashboard to support editor-styles.
add_action( 'admin_enqueue_scripts', array( $this, 'webfont_loader' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'webfont_loader_script' ), 30 );

add_filter( 'wp_resource_hints', array( $this, 'resource_hints' ), 10, 2 );
}

Expand Down
1 change: 1 addition & 0 deletions modules/webfonts/class-kirki-modules-webfonts-local.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function __construct( $webfonts, $googlefonts ) {
$this->googlefonts = $googlefonts;

add_action( 'wp_footer', array( $this, 'add_styles' ) );
add_action( 'admin_footer', array( $this, 'add_styles' ) );
}

/**
Expand Down