(string) $tutorial['title'], 'url' => (string) $tutorial['url'], ); } } $general_links = array(); if ( ! empty( self::$documentation_link ) ) { $general_links[] = array( 'title' => __( 'Documentation', 'affiliate-ai-lite' ), 'url' => self::$documentation_link, ); } if ( ! empty( self::$tutorials_link ) ) { $general_links[] = array( 'title' => __( 'YouTube Tutorials', 'affiliate-ai-lite' ), 'url' => self::$tutorials_link, ); } if ( ! empty( self::$faq_link ) ) { $general_links[] = array( 'title' => __( 'FAQ', 'affiliate-ai-lite' ), 'url' => self::$faq_link, ); } if ( ! empty( self::$wp_forum_support_link ) ) { $general_links[] = array( 'title' => __( 'WP Forum Support', 'affiliate-ai-lite' ), 'url' => self::$wp_forum_support_link, ); } if ( ! empty( self::$support_center_link ) ) { $general_links[] = array( 'title' => __( 'Support Center', 'affiliate-ai-lite' ), 'url' => self::$support_center_link, ); } $help_links = array(); if ( ! empty( $tutorial_links ) ) { $help_links[ __( 'Tutorials', 'affiliate-ai-lite' ) ] = $tutorial_links; } if ( ! empty( $general_links ) ) { $help_links[ __( 'General', 'affiliate-ai-lite' ) ] = $general_links; } $items[] = array( 'id' => 'affiai_help', 'title' => __( 'Affiliate AI Lite Help', 'affiliate-ai-lite' ), 'description' => ! empty( $page_details['description'] ) ? '
' . esc_html( $page_details['description'] ) . '
' : '', 'help_links' => $help_links, 'source' => array( 'type' => 'plugin', 'name' => 'Affiliate AI Lite', 'slug' => 'affiliate-ai-lite', ), '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'] ) : ''; if ( in_array( $page, array( 'affiai', 'affiliate-ai-lite' ), true ) ) { return true; } if ( $screen_id && ( strpos( $screen_id, 'affiai' ) !== false || strpos( $screen_id, 'affiliate-ai-lite' ) !== 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.', 'affiliate-ai-lite' ), '', '' ), ) ); } /** * 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.', 'affiliate-ai-lite' ), ) ); } /** * 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 = AFFIAI_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 Affiliate AI Lite 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'] ) : ''; $screen_id = isset( $context['screen_id'] ) ? sanitize_text_field( $context['screen_id'] ) : ''; $tab = ''; foreach ( array( 'tab', 'section', 'view', 'subpage', 'panel' ) as $key ) { if ( ! empty( $request[ $key ] ) ) { $tab = sanitize_text_field( $request[ $key ] ); break; } } return self::get_page_details_by_values( $page, $tab, $screen_id, $context ); } /** * Resolve page details from the available context values. * * @param string $page * @param string $tab * @param string $screen_id * @param array $context * @return array */ private static function get_page_details_by_values( $page, $tab, $screen_id, $context ) { $page_details = array( 'settings' => array( 'description' => __( 'Configure how affiliate product content is displayed and managed across your site. Control structured data, automatic descriptions, pricing visibility, and call-to-action elements, along with caching, access permissions, and advanced behavior settings.', 'affiliate-ai-lite' ), 'tutorials' => array( array( 'url' => 'https://affi.ai/documentation/#How_to_use_AffiAi_according_to_the_different_WordPress_interfaces', 'title' => 'How to use AffiAi with Elementor, Gutenberg and other page builders?' ), array( 'url' => 'https://affi.ai/tuto-shortcodes/', 'title' => 'How to use the Affi.ai shortcode mode?' ), array( 'url' => 'https://affi.ai/tuto-pick-select/', 'title' => 'How to use the Affi.ai Pick & Select search?' ), array( 'url' => 'https://affi.ai/how-do-i-adjust-the-affiai-default-settings/#Main_Settings', 'title' => 'Main Settings' ), array( 'url' => 'https://affi.ai/how-do-i-adjust-the-affiai-default-settings/#Advanced_settings', 'title' => 'Advanced Settings' ) ) ), 'amazon' => array( 'description' => __( 'Configure your Amazon affiliate integration, including API credentials, tracking IDs, and marketplace settings. Manage geotargeting, request limits, and link conversion to ensure accurate tracking and optimized performance.', 'affiliate-ai-lite' ), 'tutorials' => array( array( 'url' => 'https://affi.ai/how-to-get-your-tracking-id-and-api-key-depending-on-the-platform/', 'title' => 'How to get your tracking ID and API key ?' ), array( 'url' => 'https://affi.ai/sitestripe-converter/', 'title' => 'How to use AFFIAI’s SiteStripe converter?' ) ) ), 'dashboard' => array( 'description' => __( 'Manage cached Amazon product data and monitor product availability. View product entries, check last price updates, and clear cache for individual items or all products.', 'affiliate-ai-lite' ), 'tutorials' => array( array( 'url' => 'https://affi.ai/use-dashboard/', 'title' => 'How to use the AffiAi product dashboard?' ) ) ) ); $area = self::resolve_context_area( $page, $tab, $screen_id, $context ); if ( ! empty( $page_details[ $area ] ) ) { return $page_details[ $area ]; } return $page_details['settings']; } /** * Best-effort area resolution for Affiliate AI Lite. * * @param string $page * @param string $tab * @param string $screen_id * @param array $context * @return string */ private static function resolve_context_area( $page, $tab, $screen_id, $context ) { $page = strtolower( (string) $page ); $tab = strtolower( (string) $tab ); $screen_id = strtolower( (string) $screen_id ); $haystack = strtolower( self::flatten_context_text( $context ) . ' ' . $page . ' ' . $tab . ' ' . $screen_id ); if ( strpos( $haystack, 'saveprod' ) !== false || strpos( $haystack, 'dashboard' ) !== false || strpos( $haystack, 'delete cache' ) !== false || strpos( $haystack, 'missing products' ) !== false || strpos( $haystack, 'last price update' ) !== false ) { return 'dashboard'; } if ( strpos( $haystack, 'merchant' ) !== false || strpos( $haystack, 'amazon' ) !== false || strpos( $haystack, 'api key' ) !== false || strpos( $haystack, 'tracking id' ) !== false || strpos( $haystack, 'sitestripe' ) !== false || strpos( $haystack, 'geoip' ) !== false ) { return 'amazon'; } if ( strpos( $haystack, 'options' ) !== false || strpos( $haystack, 'main settings' ) !== false || strpos( $haystack, 'advanced settings' ) !== false || strpos( $haystack, 'structured data' ) !== false || strpos( $haystack, 'automatic descriptions' ) !== false || strpos( $haystack, 'call to action' ) !== false ) { return 'settings'; } return 'settings'; } /** * Flatten a context array into searchable text. * * @param mixed $value * @return string */ private static function flatten_context_text( $value ) { if ( is_scalar( $value ) ) { return (string) $value; } if ( is_array( $value ) ) { $parts = array(); foreach ( $value as $item ) { $parts[] = self::flatten_context_text( $item ); } return implode( ' ', $parts ); } return ''; } } add_action( 'plugins_loaded', array( 'AFFIAI_Helper', 'aiaa_add_filter' ), 20 ); }