$value ) { if ( isset( Custom_Code::LOCATION_FUNC[ $location ] ) && call_user_func( Custom_Code::LOCATION_FUNC[ $location ] ) ) { $uri = get_option( "ao_cc_css_{$location}_external", '' ); if ( ! empty( $uri ) && (bool) apply_filters( "ao_cc_output_{$location}_external_css", true ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- ao_cc_ is this module's established hook prefix, used consistently throughout Custom Code. wp_enqueue_style( 'ao-cc-css-' . $location, esc_url( $uri ), [], null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion } } } } // Sitewide inline. $sitewide_inline = get_option( 'ao_cc_css_sitewide_inline', '' ); if ( ! empty( $sitewide_inline ) && (bool) apply_filters( 'ao_cc_output_sitewide_inline_css', true ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- ao_cc_ is this module's established hook prefix, used consistently throughout Custom Code. wp_register_style( 'ao-cc-css-global', false ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion wp_enqueue_style( 'ao-cc-css-global' ); wp_add_inline_style( 'ao-cc-css-global', wp_strip_all_tags( $sitewide_inline ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } // Location-specific inline. if ( ! empty( $locations['inline'] ) ) { foreach ( $locations['inline'] as $location => $value ) { if ( isset( Custom_Code::LOCATION_FUNC[ $location ] ) && call_user_func( Custom_Code::LOCATION_FUNC[ $location ] ) ) { $code = get_option( "ao_cc_css_{$location}_inline", '' ); if ( ! empty( $code ) && (bool) apply_filters( "ao_cc_output_{$location}_inline_css", true ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- ao_cc_ is this module's established hook prefix, used consistently throughout Custom Code. wp_register_style( "ao-cc-css-{$location}", false ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion wp_enqueue_style( "ao-cc-css-{$location}" ); wp_add_inline_style( "ao-cc-css-{$location}", wp_strip_all_tags( $code ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } } } } /** * Output scripts in wp_head. * * @return void */ public function output_head_scripts(): void { $this->output_scripts( 'wp_head' ); } /** * Output scripts in wp_body_open. * * @return void */ public function output_body_open_scripts(): void { $this->output_scripts( 'wp_body_open' ); } /** * Output scripts in wp_footer. * * @return void */ public function output_footer_scripts(): void { $this->output_scripts( 'wp_footer' ); } /** * Output cached script code for a given position. * * @param string $position * @return void */ private function output_scripts( string $position ): void { if ( ! in_array( $position, Custom_Code::VALID_POSITIONS, true ) ) { return; } if ( ! apply_filters( 'ao_cc_output_free_default_cache', true, $position ) ) { return; } $script_code = $this->collect_cached_code( $position, 'js' ); if ( ! empty( $script_code ) ) { echo $script_code; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- intentional raw HTML/JS output, filtered at save time } $html_code = $this->collect_cached_code( $position, 'html' ); if ( ! empty( $html_code ) ) { echo do_shortcode( $html_code ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- intentional raw HTML output, filtered at save time } } /** * Collect the cached sitewide/location output for a given position and snippet type. * * @param string $position Hook position (wp_head, wp_body_open, wp_footer). * @param string $type 'js' or 'html'. * @return string */ private function collect_cached_code( string $position, string $type ): string { $option_prefix = 'html' === $type ? 'ao_cc_html' : 'ao_cc_script'; $locations_key = 'html' === $type ? 'ao_cc_html_locations' : 'ao_cc_script_locations'; $code = get_option( "{$option_prefix}_{$position}_sitewide", '' ); $locations = get_option( $locations_key, [] ); if ( ! empty( $locations[ $position ] ) ) { foreach ( $locations[ $position ] as $location => $value ) { if ( isset( Custom_Code::LOCATION_FUNC[ $location ] ) && call_user_func( Custom_Code::LOCATION_FUNC[ $location ] ) ) { $location_code = get_option( "{$option_prefix}_{$position}_{$location}", '' ); if ( ! empty( $location_code ) ) { $code = $this->join_script( $code, $location_code ); } } } } return $code; } /** * Append a script/HTML snippet to an aggregate string with a newline separator. * * @param string $aggregate Existing output. * @param string $snippet Snippet to append. * @return string */ private function join_script( string $aggregate, string $snippet ): string { if ( '' === $snippet ) { return $aggregate; } return '' === $aggregate ? $snippet : rtrim( $aggregate ) . "\n" . $snippet; } }