settings ) ), '3.0.10' );
$args['output'] = [
[
'element' => $args['output'],
],
];
}
// Convert to array of arrays if needed.
if ( isset( $args['output']['element'] ) ) {
/* translators: The field ID where the error occurs. */
_doing_it_wrong( __METHOD__, sprintf( esc_html__( '"output" invalid format in field %s. The "output" argument should be defined as an array of arrays.', 'kirki' ), esc_html( $this->settings ) ), '3.0.10' );
$args['output'] = [ $args['output'] ];
}
if ( empty( $args['output'] ) ) {
return;
}
foreach ( $args['output'] as $key => $output ) {
if ( empty( $output ) || ! isset( $output['element'] ) ) {
unset( $args['output'][ $key ] );
continue;
}
if ( ! isset( $output['sanitize_callback'] ) && isset( $output['callback'] ) ) {
$args['output'][ $key ]['sanitize_callback'] = $output['callback'];
}
// Convert element arrays to strings.
if ( isset( $output['element'] ) && is_array( $output['element'] ) ) {
$args['output'][ $key ]['element'] = array_unique( $args['output'][ $key ]['element'] );
sort( $args['output'][ $key ]['element'] );
// Trim each element in the array.
foreach ( $args['output'][ $key ]['element'] as $index => $element ) {
$args['output'][ $key ]['element'][ $index ] = trim( $element );
}
$args['output'][ $key ]['element'] = implode( ',', $args['output'][ $key ]['element'] );
}
// Fix for https://github.com/aristath/kirki/issues/1659#issuecomment-346229751.
$args['output'][ $key ]['element'] = str_replace( [ "\t", "\n", "\r", "\0", "\x0B" ], ' ', $args['output'][ $key ]['element'] );
$args['output'][ $key ]['element'] = trim( preg_replace( '/\s+/', ' ', $args['output'][ $key ]['element'] ) );
}
if ( ! isset( $args['type'] ) && isset( $object->type ) ) {
$args['type'] = $object->type;
}
self::$fields[] = $args;
}
/**
* Print styles inline.
*
* @access public
* @since 3.0.36
* @return void
*/
public function print_styles_inline() {
echo '';
}
/**
* Enqueue the styles.
*
* @access public
* @since 3.0.36
* @return void
*/
public function enqueue_styles() {
$args = [
'action' => apply_filters( 'kirki_styles_action_handle', 'kirki-styles' ),
];
if ( is_admin() && ! is_customize_preview() ) {
$args['editor'] = '1';
}
// Enqueue the dynamic stylesheet.
wp_enqueue_style(
'kirki-styles',
add_query_arg( $args, home_url() ),
[],
'4.0'
);
}
/**
* Prints the styles as an enqueued file.
*
* @access public
* @since 3.0.36
* @return void
*/
public function print_styles_action() {
/**
* Note to code reviewers:
* There is no need for a nonce check here, we're only checking if this is a valid request or not.
*/
if ( empty( $_GET['action'] ) || apply_filters( 'kirki_styles_action_handle', 'kirki-styles' ) !== $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification
return;
}
// This is a stylesheet.
header( 'Content-type: text/css' );
$this->print_styles();
exit;
}
/**
* Prints the styles.
*
* @access public
*/
public function print_styles() {
// Go through all configs.
$configs = Kirki::$config;
foreach ( $configs as $config_id => $args ) {
if ( isset( $args['disable_output'] ) && true === $args['disable_output'] ) {
continue;
}
$styles = self::loop_controls( $config_id );
$styles = apply_filters( "kirki_{$config_id}_dynamic_css", $styles );
if ( ! empty( $styles ) ) {
/**
* Note to code reviewers:
*
* Though all output should be run through an escaping function, this is pure CSS.
*
* When used in the print_styles_action() method the PHP header() call makes the browser interpret it as such.
* No code, script or anything else can be executed from inside a stylesheet.
*
* When using in the print_styles_inline() method the wp_strip_all_tags call we use below
* strips anything that has the possibility to be malicious, and since this is inslide a