site_url(), 'admin_url' => admin_url(), 'nonce' => wp_create_nonce( 'wp_rest' ), 'date_format' => get_option( 'date_format' ), 'date_format_string' => date_i18n( get_option( 'date_format' ) ), 'time_format' => get_option( 'time_format' ), 'time_format_string' => date_i18n( get_option( 'time_format' ) ), 'gmt_offset' => (float) get_option( 'gmt_offset', 0 ), 'start_of_week' => get_option( 'start_of_week', 0 ), 'current_user_id' => get_current_user_id(), ]; return apply_filters( 'aisentic_admin_localize', $data ); } /** * Get frontend localize data * * Anonymous shoppers can't call the admin-only /settings endpoint, so public config is delivered here instead. * * @return array Collection localize data */ public static function get_frontend() { $settings = new \Aisentic\Api\Models\Settings(); $public_agent = new \Aisentic\PublicAgent\Public_Agent_Settings( $settings ); $data = [ 'site_url' => site_url(), 'root' => esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'date_format' => get_option( 'date_format' ), 'time_format' => get_option( 'time_format' ), 'gmt_offset' => (float) get_option( 'gmt_offset', 0 ), 'current_user_id' => get_current_user_id(), 'start_of_week' => get_option( 'start_of_week', 0 ), 'locale_name' => strtolower( str_replace( '_', '-', get_locale() ) ), // Injected into a shadow root by the JS entry so Tailwind's preflight stays scoped to the widget. 'styleUrl' => aisentic()->assets_url . '/build/css/frontend.css?ver=' . aisentic()->version, // home_url-relative; must not be hardcoded to the domain root (breaks subdirectory installs). 'wcAjaxUrl' => class_exists( 'WC_AJAX' ) ? \WC_AJAX::get_endpoint( 'add_to_cart' ) : home_url( '/?wc-ajax=add_to_cart' ), // The page the visitor is on, sent with each message so "book this" works. 'currentPage' => is_singular() ? get_post_type() . ':' . get_the_ID() : '', 'publicChat' => [ 'widget' => [ 'botName' => (string) $public_agent->widget( 'botName' ), 'headline' => (string) $public_agent->widget( 'headline' ), 'greeting' => (string) $public_agent->widget( 'greeting' ), 'inputPlaceholder' => (string) $public_agent->widget( 'inputPlaceholder' ), // The small square crop, on the site's own scheme. Empty when unset or deleted. 'avatarUrl' => esc_url_raw( (string) wp_get_attachment_image_url( (int) $public_agent->widget( 'avatarId' ), 'thumbnail' ) ), 'brandColor' => (string) $public_agent->widget( 'brandColor' ), 'position' => (string) $public_agent->widget( 'position' ), 'starterPrompts' => $public_agent->starter_prompts(), // One card per enabled plugin, and which one owns this page. 'topics' => $public_agent->topics(), 'pageTopic' => $public_agent->page_topic(), ], ], ]; // Only present on a WooCommerce single-product page. if ( function_exists( 'is_product' ) && is_product() && function_exists( 'wc_get_product' ) ) { $product = wc_get_product( get_the_ID() ); if ( $product ) { $price = wp_strip_all_tags( (string) $product->get_price_html() ); if ( '' === $price ) { $price = (string) $product->get_price(); } $data['currentProduct'] = [ 'id' => $product->get_id(), 'name' => $product->get_name(), 'permalink' => esc_url_raw( get_permalink( $product->get_id() ) ), 'price' => $price, ]; } } return apply_filters( 'aisentic_frontend_localize', $data ); } }