(string) $tutorial['title'], 'url' => (string) $tutorial['url'], ); } } $general_links = array(); if ( ! empty( self::$documentation_link ) ) { $general_links[] = array( 'title' => __( 'Documentation', 'ait-ai-admin-assistance' ), 'url' => self::$documentation_link, ); } if ( ! empty( self::$tutorials_link ) ) { $general_links[] = array( 'title' => __( 'YouTube Tutorials', 'ait-ai-admin-assistance' ), 'url' => self::$tutorials_link, ); } if ( ! empty( self::$faq_link ) ) { $general_links[] = array( 'title' => __( 'FAQ', 'ait-ai-admin-assistance' ), 'url' => self::$faq_link, ); } if ( ! empty( self::$wp_forum_support_link ) ) { $general_links[] = array( 'title' => __( 'WP Forum Support', 'ait-ai-admin-assistance' ), 'url' => self::$wp_forum_support_link, ); } if ( ! empty( self::$support_center_link ) ) { $general_links[] = array( 'title' => __( 'Support Center', 'ait-ai-admin-assistance' ), 'url' => self::$support_center_link, ); } $help_links = array(); if ( ! empty( $tutorial_links ) ) { $help_links[ __( 'Tutorials', 'ait-ai-admin-assistance' ) ] = $tutorial_links; } if ( ! empty( $general_links ) ) { $help_links[ __( 'General', 'ait-ai-admin-assistance' ) ] = $general_links; } $items[] = array( 'id' => 'ait_aiaa_help', 'title' => __( 'AIT AI Admin Assistance Help', 'ait-ai-admin-assistance' ), 'description' => ! empty( $page_details['description'] ) ? '

' . esc_html( $page_details['description'] ) . '

' : '', 'help_links' => $help_links, 'source' => array( 'type' => 'plugin', 'name' => 'AIT AI Admin Assistance', 'slug' => 'ait-ai-admin-assistance', ), 'target_callback' => array( __CLASS__, 'aiaa_target_callback' ), 'priority' => 20, 'capability' => 'manage_options', 'icon' => 'dashicons-editor-help', ); return $items; } /** * AIAA advanced targeting callback. * * @param array $context * @param array $item * @return bool * * @since 5.1.0 */ public static function aiaa_target_callback( $context, $item ) { return self::aiaa_matches_context( $context ); } /** * Shared matcher for AIAA context. * * @param array $context * @return bool * * @since 5.1.0 */ private static function aiaa_matches_context( $context ) { $context = is_array( $context ) ? $context : array(); $request = isset( $context['request'] ) && is_array( $context['request'] ) ? $context['request'] : array(); $page = isset( $request['page'] ) ? sanitize_text_field( $request['page'] ) : ''; $screen_id = isset( $context['screen_id'] ) ? sanitize_text_field( $context['screen_id'] ) : ''; $post_type = isset( $context['post_type'] ) ? sanitize_text_field( $context['post_type'] ) : ''; if ( $page === AIT_AIAA_OPTION || $screen_id === AIT_AIAA_OPTION || strpos( $screen_id, AIT_AIAA_OPTION ) !== false ) { return true; } if ( strpos( $page, 'ait-aiaa-settings' ) !== false || strpos( $screen_id, 'ait-aiaa-settings' ) !== false ) { return true; } if ( self::is_guidance_like_context( $screen_id, $post_type ) ) { return true; } return false; } /** * Identify guidance/workflow/acknowledgement-related admin screens. * * @param string $screen_id * @param string $post_type * @return bool */ private static function is_guidance_like_context( $screen_id, $post_type ) { $screen_id = (string) $screen_id; $post_type = (string) $post_type; $needles = array( 'guidance', 'workflow', 'acknowledg' ); foreach ( $needles as $needle ) { if ( ( $screen_id && strpos( strtolower( $screen_id ), $needle ) !== false ) || ( $post_type && strpos( strtolower( $post_type ), $needle ) !== false ) ) { return true; } } return false; } /** * Handle ajax requests in admin area for logged out users. * * @since 5.1.0 */ public static function admin_nopriv_ajax() { wp_send_json_error( array( 'error' => 'loggedout', 'msg' => sprintf( __( 'You have been logged out. Please %slogin again%s.', 'ait-ai-admin-assistance' ), '', '' ), ) ); } /** * Handle ajax requests where an invalid nonce is passed with the request. * * @since 5.1.0 */ public static function bad_nonce_ajax() { wp_send_json_error( array( 'error' => 'badnonce', 'msg' => __( 'The request has been rejected because it does not appear to have come from this site.', 'ait-ai-admin-assistance' ), ) ); } /** * Escapes PHP data being passed to JS, recursively. * * @since 5.1.0 */ public static function escape_js_recursive( $values ) { $return_values = array(); foreach ( (array) $values as $key => $value ) { if ( is_array( $value ) ) { $value = AIT_AIAA_Helper::escape_js_recursive( $value ); } elseif ( ! is_scalar( $value ) ) { continue; } else { $value = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); } $return_values[ $key ] = $value; } return $return_values; } /** * Get page details for the current AIAA context. * * @param array $context * @return array */ public static function get_page_details_for_context( $context ) { $context = is_array( $context ) ? $context : array(); $request = isset( $context['request'] ) && is_array( $context['request'] ) ? $context['request'] : array(); $page = isset( $request['page'] ) ? sanitize_text_field( $request['page'] ) : ''; $tab = isset( $request['tab'] ) ? sanitize_text_field( $request['tab'] ) : ''; $screen_id = isset( $context['screen_id'] ) ? sanitize_text_field( $context['screen_id'] ) : ''; $post_type = isset( $context['post_type'] ) ? sanitize_text_field( $context['post_type'] ) : ''; return self::get_page_details_by_values( $page, $tab, $screen_id, $post_type ); } /** * Resolve page details from the available context values. * * @param string $page * @param string $tab * @param string $screen_id * @param string $post_type * @return array */ private static function get_page_details_by_values( $page, $tab, $screen_id, $post_type ) { $page_details = array( 'settings-license' => array( 'description' => __( 'Activate and manage your AIT AI Admin Assistance Pro license. Enter your license key to unlock Pro features including AI Conversations, Workflows, guided step-by-step admin tasks, acknowledgements, import/export, and advanced styling options.', 'ait-ai-admin-assistance' ), 'tutorials' => array( array( 'url' => 'https://doc.wpaiplugins.dev/plugins/ai-admin-assistance/user/pro/activate', 'title' => 'Activate Pro Version' ), ) ), 'settings-general' => array( 'description' => __( 'Configure the core behaviour of the AIT AI Admin Assistance panel across your WordPress admin. You can fully disable the plugin panel when it\'s not needed, customize the label shown on the help button, and choose whether the panel slides in from the left or right side of the screen. Role-based visibility controls let you hide the panel button from specific user roles.', 'ait-ai-admin-assistance' ), 'tutorials' => array( array( 'url' => 'https://doc.wpaiplugins.dev/plugins/ai-admin-assistance/user/panel/', 'title' => 'Configure the Main Admin Assistance Panel' ), ) ), 'settings-designer-guidance' => array( 'description' => __( 'Manage how custom guidance content appears in the panel. Disable it if unneeded, cap how many items show per screen, and set the visual intensity of warning items. Quick Help Links can also be configured here, providing a persistent footer list of useful links shown across all admin screens.', 'ait-ai-admin-assistance' ), 'tutorials' => array( array( 'url' => 'https://doc.wpaiplugins.dev/plugins/ai-admin-assistance/user/guidance/', 'title' => 'Guidance' ), array( 'url' => 'https://doc.wpaiplugins.dev/plugins/ai-admin-assistance/user/guidance/add', 'title' => 'Add Guidance' ), array( 'url' => 'https://doc.wpaiplugins.dev/plugins/ai-admin-assistance/user/guidance/configure', 'title' => 'Configure Guidance' ), ) ), 'settings-ai-assistant' => array( 'description' => __( 'Configure the OpenAI-powered assistant. Disable AI entirely or restrict it by user role. Set response style (Concise, Balanced, or Detailed), toggle suggested WordPress docs, and enter your OpenAI API key. Fine-tune behaviour with model selection, Temperature, Max Output Tokens, and response Language.', 'ait-ai-admin-assistance' ), 'tutorials' => array( array( 'url' => 'https://doc.wpaiplugins.dev/plugins/ai-admin-assistance/user/ask-ai/', 'title' => 'AI Assistant' ), array( 'url' => 'https://doc.wpaiplugins.dev/plugins/ai-admin-assistance/user/openai-key/get-key', 'title' => 'OpenAI Key' ), array( 'url' => 'https://doc.wpaiplugins.dev/plugins/ai-admin-assistance/user/openai-key/adding-key', 'title' => 'Add Key in Plugin' ), ) ), 'settings-advanced' => array( 'description' => __( 'Enable Debug Logging to capture detailed activity logs when diagnosing unexpected behaviour with the panel, guidance, or AI responses. Disable logging once the issue is resolved to avoid unnecessary log accumulation.', 'ait-ai-admin-assistance' ), 'tutorials' => array( array( 'url' => 'https://doc.wpaiplugins.dev/plugins/ai-admin-assistance/user/settings/logs', 'title' => 'Logs' ), ) ), 'settings-styling' => array( 'description' => __( 'Customize the visual appearance of the AI Admin Assistance panel to match your admin interface or brand. Adjust the look and feel without touching code, making it useful when deploying across client sites.', 'ait-ai-admin-assistance' ), 'tutorials' => array( array( 'url' => 'https://doc.wpaiplugins.dev/plugins/ai-admin-assistance/user/settings/styling', 'title' => 'Styling Options' ), ) ), 'admin-guidance' => array( 'description' => __( 'A central overview of all your Guidance items. Each row shows key details including title, priority, target type, field-level status, and role visibility at a glance. From here you can manage your guidance content, organize Workflows (Pro) that guide admins through step-by-step tasks on specific screens, and handle import/export (Pro) of settings, guidance, and workflow configurations across sites.', 'ait-ai-admin-assistance' ), 'tutorials' => array( array( 'url' => 'https://doc.wpaiplugins.dev/plugins/ai-admin-assistance/user/guidance/', 'title' => 'Guidance' ), array( 'url' => 'https://doc.wpaiplugins.dev/plugins/ai-admin-assistance/user/import-export/', 'title' => 'Import/Export' ), ) ) ); $page = $page ? sanitize_text_field( $page ) : ''; $tab = $tab ? sanitize_text_field( $tab ) : ''; $screen_id = $screen_id ? sanitize_text_field( $screen_id ) : ''; $post_type = $post_type ? sanitize_text_field( $post_type ) : ''; if ( $page === AIT_AIAA_OPTION || strpos( $screen_id, AIT_AIAA_OPTION ) !== false || strpos( $page, 'ait-aiaa-settings' ) !== false ) { if ( in_array( $tab, array( 'ait_aiaa_license', 'ait_aiaa_license_tab' ), true ) ) { return $page_details['settings-license']; } if ( $tab === 'aiaa_tab_general' ) { return $page_details['settings-general']; } if ( $tab === 'aiaa_tab_guidance' ) { return $page_details['settings-designer-guidance']; } if ( $tab === 'aiaa_tab_ai' ) { return $page_details['settings-ai-assistant']; } if ( $tab === 'aiaa_tab_advanced' ) { return $page_details['settings-advanced']; } if ( $tab === 'aiaa_tab_styling' ) { return $page_details['settings-styling']; } return $page_details['settings-license']; } if ( self::is_guidance_like_context( $screen_id, $post_type ) ) { return $page_details['admin-guidance']; } return array( 'description' => '', 'tutorials' => array() ); } } add_action( 'plugins_loaded', array( 'AIT_AIAA_Helper', 'aiaa_add_filter' ), 20 ); }