##CSS customizable by manipulate parse_query##
@Scott Reinmuth, I think you misdirection about those tutorials, yes you use parse_request
method.
###Similar approach with validate###
My similar approach with validate data. We just use file functions.php
theme to add this code.
/** Enqueue style for custom css
* we use parameter wpse_css and ( int ) 1 as value
*
*/
add_action( 'wp_enqueue_scripts', 'wpse221867_enqueue_style', 99 );
function wpse221867_enqueue_style()
{
/** check url ssl */
$url = ( is_ssl() ) ?
home_url( '/', 'https' ) : home_url( '/' );
/** Register and enqueue wpse_style_php
* Build query with wpse_css as parameter, 1 as number to validation
*
*/
wp_register_style( 'wpse_style_php',
add_query_arg( array(
'wpse_css' => ( int ) 1
), $url ),
array(), //your style handled
null, //remove wp version
'all' //media
);
wp_enqueue_style( 'wpse_style_php' );
}
/** Fire parse_request with function wpse221867_print_css
* Generate css in PHP
*
* @return string CSS Content
*/
add_action( 'parse_request', 'wpse221867_print_css' );
function wpse221867_print_css()
{
/** validate query on input */
$css = filter_input( INPUT_GET, 'wpse_css', FILTER_VALIDATE_INT );
if( empty( $css ) || ( int ) 1 != $css )
return;
ob_start();
header( 'Content-type: text/css' );
/** wpse_option_settings contain css in an array i.e
* array( 'wpse_css_content' => 'a{color:#ececec}' )
*
*/
$options = get_option( 'wpse_option_settings' );
$raw_css = ( isset( $options['wpse_css_content'] ) )
? $options['wpse_css_content'] : '';
/** sanitize for output */
$content = wp_kses( $raw_css,
array( '\'', '\"' )
);
$content = str_replace( '>', '>', $content );
echo $content; // output
die();
}
IMHO, this method not recommended, especially for performance issue. Just use static css file, find another way to make it your css customizable, please take a look wp_add_inline_style
( example available ) and get_theme_mod
.