post_content ) || ! has_shortcode( (string) $post->post_content, 'saasaudit_cookie_policy' ) ) { return; } if ( ! saasaudit_consent_valid_token( saasaudit_consent_settings()['token'] ) ) { return; } saasaudit_consent_cookie_policy_register_script( false ); wp_enqueue_script( SAASAUDIT_COOKIE_POLICY_SCRIPT ); } add_action( 'wp_enqueue_scripts', 'saasaudit_consent_cookie_policy_enqueue_early' ); /** The cookie table for this site, as the shortcode prints it; '' while the site has no valid token. */ function saasaudit_consent_cookie_policy_shortcode( $atts = array() ) { $settings = saasaudit_consent_settings(); if ( ! saasaudit_consent_valid_token( $settings['token'] ) ) { return ''; } $atts = shortcode_atts( array( 'theme' => '' ), is_array( $atts ) ? $atts : array(), 'saasaudit_cookie_policy' ); $theme = is_string( $atts['theme'] ) ? strtolower( trim( $atts['theme'] ) ) : ''; $base = saasaudit_consent_https_origin( $settings['api_base_url'] ); $base = '' === $base ? SAASAUDIT_DEFAULT_API : $base; $url = $base . '/api/v1/cookie-policy/' . rawurlencode( $settings['token'] ); if ( in_array( $theme, array( 'light', 'dark', 'transparent' ), true ) ) { $url .= '?theme=' . $theme; } $html = ''; // Already queued in the head when the page's own content holds the shortcode; otherwise (a widget, // a template, a page builder) it is queued here, in the footer, once however many tables there are. saasaudit_consent_cookie_policy_register_script(); wp_enqueue_script( SAASAUDIT_COOKIE_POLICY_SCRIPT ); return $html; } add_shortcode( 'saasaudit_cookie_policy', 'saasaudit_consent_cookie_policy_shortcode' );