add_seo_disclaimer_notice(); $instance->add_auth_admin_notices(); $instance->add_batch_request_admin_notices(); $instance->maybe_add_import_admin_notice(); $instance->maybe_show_debug_notice( $instance ); self::maybe_show_php_version_notice(); } /** * Show a notice if the PHP version is below the required minimum. * * @return void */ private static function maybe_show_php_version_notice() { if ( version_compare( PHP_VERSION, '8.1', '<' ) ) { $message = sprintf( /* translators: %s: current PHP version. */ Messages::raw( 'notices.php_version' ), esc_html( PHP_VERSION ) ); printf( '

%s

', wp_kses_post( $message ) ); } } /** * Show a notice if the API base URL is being overridden via define (used for local dev to connect to dev api) * * @param Notices $instance The current Notices instance. * @return void */ private static function maybe_show_debug_notice( $instance ) { if ( Settings::get( 'enable_debug_support' ) ) { echo '
'; echo '

Debug mode is enabled: Detailed logs will be recorded here View Log File

'; $instance->maybe_get_middleware_override_notice(); $instance->maybe_get_refresh_data_button(); $instance->get_client_info(); echo '
'; } } /** * Render client information for debug purposes. */ private function get_client_info() { $client = self::client(); if ( $client->is_user_authenticated() ) { echo '

' . esc_html( Messages::get( 'debug.client_info' ) ) . '

'; $name_line = $client->get_name() !== '' ? sprintf( '

%s %s

', esc_html( Messages::get( 'debug.client' ) ), esc_html( $client->get_name() ) ) : ''; $desc_line = $client->get_description() !== '' ? sprintf( '

%s %s

', esc_html( Messages::get( 'debug.description' ) ), esc_html( $client->get_description() ) ) : ''; $api_key_line = $client->get_api_key() !== '' ? sprintf( '

%s %s

', esc_html( Messages::get( 'debug.api_key' ) ), esc_html( $client->get_api_key() ) ) : ''; $client_id_line = $client->get_client_id() !== '' ? sprintf( '

%s %s

', esc_html( Messages::get( 'debug.client_id' ) ), esc_html( $client->get_client_id() ) ) : ''; printf( '%s%s%s%s', wp_kses_post( $name_line ), wp_kses_post( $desc_line ), wp_kses_post( $api_key_line ), wp_kses_post( $client_id_line ) ); echo '

'; } } /** * Render the "Sync Batch Request Data" button if not already in a refresh request. */ private function maybe_get_refresh_data_button() { if ( ! self::is_refresh_request() ) { $url = self::get_refresh_url(); printf( '

%2$s

', esc_url( $url ), esc_html( Messages::get( 'debug.sync_button' ) ) ); } } /** * Render a notice about API middleware override if applicable. */ private function maybe_get_middleware_override_notice() { $api_base = Env::get_string_constant( 'EPARALLAX_API_BASE' ); if ( null !== $api_base ) { printf( '

%s

', esc_html( sprintf( 'API Middleware URL override is active: %s', esc_html( $api_base ) ) ) ); } } /** * Determine if we should show notices on this screen */ private static function show_notices() { $screen = get_current_screen(); $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); if ( $screen && isset( $screen->id ) && strpos( $screen->id, 'ai-content-by-parallax' ) !== false && 'ai-content-by-parallax' === $page ) { return true; } return false; } /** * Determine if the current request is asking to refresh batch data. */ private static function is_refresh_request(): bool { $refresh = filter_input( INPUT_GET, 'ai_content_by_parallax_refresh', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); return '1' === $refresh; } /** * Generate the refresh URL with a nonce attached. */ private static function get_refresh_url(): string { $url = add_query_arg( 'ai_content_by_parallax_refresh', '1' ); return wp_nonce_url( $url, 'ai_content_by_parallax_refresh_action' ); } /** * Check whether the refresh request carries a valid nonce. */ private static function has_valid_refresh_nonce(): bool { $nonce = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); return is_string( $nonce ) && wp_verify_nonce( $nonce, 'ai_content_by_parallax_refresh_action' ); } /** * Display import-related admin notice from WordPress options. */ private static function maybe_add_import_admin_notice(): void { $import_notice = get_option( 'ai_content_by_parallax_import_notice' ); if ( is_array( $import_notice ) && ! empty( $import_notice['message'] ) ) { $type = isset( $import_notice['type'] ) && in_array( $import_notice['type'], array( 'success', 'error', 'warning', 'info' ), true ) ? $import_notice['type'] : 'info'; printf( '

%2$s

', esc_attr( $type ), esc_html( $import_notice['message'] ) ); delete_option( 'ai_content_by_parallax_import_notice' ); } } /** * Render an admin notice HTML snippet for the current client state. * Keeps all client-specific messaging in one place. */ private static function add_auth_admin_notices(): void { $client = self::client(); // Not authenticated: prompt to create/set API credentials. if ( ! $client->is_user_authenticated() ) { $create_url = Endpoints::get_marketing_site_url(); $settings_url = esc_url( admin_url( 'admin.php?page=ai-content-by-parallax&tab=connection' ) ); $message = sprintf( '

%s

%s
%s %s

', esc_html( Messages::get( 'auth.get_credentials_title' ) ), esc_html( Messages::get( 'auth.get_credentials_body' ) ), $create_url, esc_html( Messages::get( 'auth.create_credentials' ) ), $settings_url, esc_html( Messages::get( 'auth.set_credentials' ) ) ); printf( '
%s
', wp_kses_post( $message ) ); return; // no need to show further notices. } // Authenticated but insufficient credits. if ( $client->is_user_authenticated() && $client->get_credits() <= 0 ) { $message = sprintf( '

%s

%s

', esc_html( Messages::get( 'auth.insufficient_credits' ) ), esc_html( Messages::get( 'auth.no_credits_body' ) ) ); printf( '
%s
', wp_kses_post( $message ) ); } $message = sprintf( '
%s %s
%s
', esc_html( Messages::get( 'auth.credits_label' ) ), esc_html( $client->get_credits() ), esc_url( Endpoints::get_marketing_site_url() ), esc_html( Messages::get( 'auth.buy_more' ) ) ); printf( '
%s
', wp_kses_post( $message ) ); } /** * Render the admin SEO rollout disclaimer notice. */ private static function add_seo_disclaimer_notice() { $base_dir = wp_normalize_path( plugin_dir_path( WCPAI_PLUGIN_FILE ) ); $template = wp_normalize_path( $base_dir . 'templates/admin-disclaimer.php' ); $real_template = realpath( $template ); $real_base = realpath( $base_dir ); // Resolve and constrain the include path to the plugin directory. if ( false !== $real_template && false !== $real_base ) { $real_template = wp_normalize_path( $real_template ); $real_base = trailingslashit( wp_normalize_path( $real_base ) ); if ( 0 === strpos( $real_template, $real_base ) && is_readable( $real_template ) ) { include $real_template; } } } /** * Render admin notices related to batch requests. */ private static function add_batch_request_admin_notices() { $url_restore = admin_url( 'admin-post.php' ); if ( get_option( 'ai_content_by_parallax_show_reset_notice' ) ) { ?>

:

%s

', /* translators: %1$d: number of products, %2$d: number of terms. */ esc_html( Messages::format( 'notices.restored_originals', $p, $t ) ) ); } // Success notice after retake snapshots. if ( isset( $_GET['ai_content_by_parallax_retake'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'parallax_retake_notice' ) ) { $p = isset( $_GET['rp'] ) ? (int) $_GET['rp'] : 0; $t = isset( $_GET['rt'] ) ? (int) $_GET['rt'] : 0; printf( '

%s

', /* translators: %1$d: number of products, %2$d: number of terms. */ esc_html( Messages::format( 'notices.retook_snapshots', $p, $t ) ) ); } if ( self::is_refresh_request() ) { if ( ! self::has_valid_refresh_nonce() ) { printf( '

%1$s: %2$s

', esc_html( Messages::get( 'notices.plugin_name' ) ), esc_html( Messages::get( 'notices.security_failed' ) ) ); return; } $success = BatchRequest::pull_all(); $notice_type = $success ? 'success' : 'error'; $message = $success ? Messages::get( 'notices.data_refresh_ok' ) : Messages::get( 'notices.data_refresh_fail' ); printf( '

%2$s: %3$s

', esc_attr( $notice_type ), esc_html( Messages::get( 'notices.plugin_name' ) ), esc_html( $message ) ); } } }