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

Output CSS generated by Customizer inline #323

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 0 additions & 8 deletions css/customizer.css.php

This file was deleted.

48 changes: 27 additions & 21 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,38 +282,44 @@ function independent_publisher_stylesheet() {
}
endif;

/*
* Loads the PHP file that generates the Customizer CSS for the front-end
*/
function independent_publisher_customizer_css() {
require( get_template_directory() . '/css/customizer.css.php' );
wp_die();
}
if ( ! function_exists( 'independent_publisher_customizer_styles_cache' ) ) :
/**
* Add the Customizer CSS styles inline
*/
function independent_publisher_customizer_styles_cache() {
global $wp_customize;

/*
* Enqueue the AJAX call to the dynamic Customizer CSS
* See http://codex.wordpress.org/AJAX_in_Plugins
*/
function independent_publisher_customizer_stylesheet() {
wp_enqueue_style( 'customizer', admin_url( 'admin-ajax.php' ) . '?action=independent_publisher_customizer_css', array(), '1.7' );
// Check we're not on the Customizer.
// If we're on the customizer then DO NOT cache the results.
if ( ! isset( $wp_customize ) ) {

}
// Get the theme_mod from the database
$data = get_theme_mod( 'independent_publisher_customizer_styles', false );

add_action( 'wp_ajax_independent_publisher_customizer_css', 'independent_publisher_customizer_css' );
add_action( 'wp_ajax_nopriv_independent_publisher_customizer_css', 'independent_publisher_customizer_css' );
// If the theme_mod does not exist, then create it.
if ( $data == false ) {
// Initialize the theme_mod.
set_theme_mod( 'independent_publisher_customizer_styles', null );
}

// Add the CSS inline.
wp_add_inline_style( 'independent-publisher-style', $data );
}
}
endif;

/*
* IMPORTANT: Customizer CSS *must* be called _after_ the main stylesheet,
* to ensure that customizer-modified styles override the defaults.
*/
if( is_rtl() ) {
add_action( 'init', 'independent_publisher_remove_locale_stylesheet' );
add_action( 'wp_enqueue_scripts', 'independent_publisher_stylesheet_rtl' );
} else {
add_action( 'wp_enqueue_scripts', 'independent_publisher_stylesheet' );
}

add_action( 'wp_enqueue_scripts', 'independent_publisher_customizer_stylesheet' );
/*
* IMPORTANT: Customizer CSS *must* be called _after_ the main stylesheet (above),
* to ensure that customizer-modified styles override the defaults.
*/
add_action( 'wp_enqueue_scripts', 'independent_publisher_customizer_styles_cache' );

if ( ! function_exists( 'independent_publisher_wp_fullscreen_title_editor_style' ) ) :
/**
Expand Down
Loading