__( 'Please enter a search term.', 'adminfly-fast-navigator' ) ) ); } $url = ''; $allowed_types = array( 'post', 'page', 'product', 'shop_order' ); if ( in_array( $type, $allowed_types, true ) ) { // Try strict ID first. if ( is_numeric( $query ) ) { $post = get_post( $query ); // Verify post type matches requested type. if ( $post && $post->post_type === $type ) { $url = get_edit_post_link( $post->ID, 'raw' ); } } // If not found, try searching by title. if ( empty( $url ) ) { $args = array( 'post_type' => $type, 's' => $query, 'posts_per_page' => 1, 'post_status' => 'any', ); $posts = get_posts( $args ); if ( ! empty( $posts ) ) { $url = get_edit_post_link( $posts[0]->ID, 'raw' ); } } } elseif ( 'user' === $type ) { $user = false; if ( is_numeric( $query ) ) { $user = get_user_by( 'id', $query ); } else { $user = get_user_by( 'email', $query ); if ( ! $user ) { $user = get_user_by( 'login', $query ); } if ( ! $user ) { // Try display name search. $user_search = new WP_User_Query( array( 'search' => '*' . $query . '*', 'search_columns' => array( 'user_login', 'user_url', 'user_email', 'user_nicename', 'display_name' ), 'number' => 1, ) ); $results = $user_search->get_results(); if ( ! empty( $results ) ) { $user = $results[0]; } } } if ( $user ) { $url = get_edit_user_link( $user->ID ); } } if ( $url ) { wp_send_json_success( array( 'url' => html_entity_decode( $url ) ) ); } else { wp_send_json_error( array( 'message' => __( 'No items found.', 'adminfly-fast-navigator' ) ) ); } } /** * Handle Plugin Settings Scan via AJAX. * Simulates plugins.php context to capture Settings links. */ function qmen_scan_plugins_handler() { check_ajax_referer( 'qmen_scan_nonce', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => 'Permission denied.' ) ); } // Fake the context so plugins adding filters conditionally on 'plugins.php' will fire. global $pagenow, $current_screen; $pagenow = 'plugins.php'; // Mock screen object if WP_Screen exists if ( class_exists( 'WP_Screen' ) ) { $current_screen = WP_Screen::get( 'plugins' ); } else { // Minimal mock $current_screen = (object) array( 'id' => 'plugins', 'base' => 'plugins' ); } if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $plugins = get_plugins(); $active_plugins = (array) get_option( 'active_plugins', array() ); $map = array(); $found_count = 0; foreach ( $active_plugins as $file ) { if ( ! isset( $plugins[ $file ] ) ) { continue; } $data = $plugins[ $file ]; // Apply the filter $actions = apply_filters( 'plugin_action_links_' . $file, array(), $file, $data, 'all' ); // Find Settings link $found_url = ''; // Priority 1: Keyword match $keywords = array( 'Settings', 'Configure', 'Manage', 'Options' ); foreach ( (array) $actions as $html ) { $text = strip_tags( $html ); foreach ( $keywords as $kw ) { if ( stripos( $text, $kw ) !== false ) { if ( preg_match( '/href=["\']([^"\']+)["\']/', $html, $matches ) ) { $found_url = $matches[1]; break 2; // Found a strong match } } } } // Priority 2: Heuristic match (links to admin pages) if ( empty( $found_url ) ) { foreach ( (array) $actions as $html ) { // skip deactivate/delete/edit which usually have these in URL or nonce if ( stripos( $html, 'action=deactivate' ) !== false || stripos( $html, 'action=delete' ) !== false ) { continue; } if ( preg_match( '/href=["\']([^"\']+)["\']/', $html, $matches ) ) { $url_candidate = $matches[1]; // Check for common settings paths if ( strpos( $url_candidate, 'admin.php?page=' ) !== false || strpos( $url_candidate, 'options-general.php' ) !== false || strpos( $url_candidate, 'settings.php' ) !== false ) { $found_url = $url_candidate; break; } } } } if ( ! empty( $found_url ) ) { $map[ $file ] = html_entity_decode( $found_url ); $found_count++; } } // Update the option update_option( 'qmen_plugin_settings_map', $map ); wp_send_json_success( array( 'message' => sprintf( __( 'Scanned %d active plugins. Found %d settings links.', 'adminfly-fast-navigator' ), count( $active_plugins ), $found_count ), 'count' => $found_count ) ); }