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( array( "\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() { $should_print = true; if ( defined( 'KIRKI_NO_OUTPUT' ) && true === KIRKI_NO_OUTPUT ) { $should_print = false; } ob_start(); $this->print_styles(); $inline_styles = ob_get_clean(); /** * If KIRKI_NO_OUTPUT constant is defined (and is true), but typography field is defined, then print it. * Otherwise, the typography field might be broken (missing font-family) if the font-face is not outputted. */ if ( ! $should_print && false !== stripos($inline_styles, '@font-face') ) { $should_print = true; } if ( ! $should_print ) { return; } $inline_styles_id = apply_filters( 'kirki_inline_styles_id', self::$inline_styles_id ); echo ''; } /** * Enqueue the styles. * * @access public * @since 3.0.36 * @return void */ public function enqueue_styles() { $args = array( 'action' => apply_filters( 'kirki_styles_action_handle', self::$css_handle ), ); if ( is_admin() ) { global $current_screen; /** * This `enqueue_styles` method is also hooked into `enqueue_block_editor_assets`. * It needs to be excluded from customize control page. * * Why not simply excluding all admin area except gutenberg editing interface? * Because it would be nice to let the possibility open * if a 3rd party plugin will output gutenberg syles somewhere in admin area. * * Example of possibility: * In the future, Ultimate Dashboard Pro's admin page feature might supports Gutenberg. */ if ( is_object( $current_screen ) && property_exists( $current_screen, 'id' ) && 'customize' === $current_screen->id ) { return; } if ( property_exists( $current_screen, 'is_block_editor' ) && 1 === (int) $current_screen->is_block_editor ) { $args['editor'] = '1'; } } // Enqueue the dynamic stylesheet. wp_enqueue_style( self::$css_handle, add_query_arg( $args, home_url() ), array(), '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. */ // phpcs:ignore WordPress.Security.NonceVerification if ( empty( $_GET['action'] ) || apply_filters( 'kirki_styles_action_handle', self::$css_handle ) !== $_GET['action'] ) { 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 ( defined( 'KIRKI_NO_OUTPUT' ) && true === KIRKI_NO_OUTPUT ) { continue; } 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 '; } /** * Enqueue the styles. * * @access public * @since 3.0.36 * @return void */ public function enqueue_styles() { $args = array( 'action' => apply_filters( 'kirki_styles_action_handle', self::$css_handle ), ); if ( is_admin() ) { global $current_screen; /** * This `enqueue_styles` method is also hooked into `enqueue_block_editor_assets`. * It needs to be excluded from customize control page. * * Why not simply excluding all admin area except gutenberg editing interface? * Because it would be nice to let the possibility open * if a 3rd party plugin will output gutenberg syles somewhere in admin area. * * Example of possibility: * In the future, Ultimate Dashboard Pro's admin page feature might supports Gutenberg. */ if ( is_object( $current_screen ) && property_exists( $current_screen, 'id' ) && 'customize' === $current_screen->id ) { return; } if ( property_exists( $current_screen, 'is_block_editor' ) && 1 === (int) $current_screen->is_block_editor ) { $args['editor'] = '1'; } } // Enqueue the dynamic stylesheet. wp_enqueue_style( self::$css_handle, add_query_arg( $args, home_url() ), array(), '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. */ // phpcs:ignore WordPress.Security.NonceVerification if ( empty( $_GET['action'] ) || apply_filters( 'kirki_styles_action_handle', self::$css_handle ) !== $_GET['action'] ) { 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 ( defined( 'KIRKI_NO_OUTPUT' ) && true === KIRKI_NO_OUTPUT ) { continue; } 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