= []; $tag_taxonomy = $post->post_type . '_tags'; if ( taxonomy_exists( $tag_taxonomy ) ) { $terms = wp_get_post_terms( $post_id, $tag_taxonomy ); if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { foreach ( $terms as $term_obj ) { $tags[] = $term_obj->name; } } } $attachments = []; if ( function_exists( 'geodir_get_images' ) ) { $images = geodir_get_images( $post_id ); if ( ! empty( $images ) ) { foreach ( $images as $image ) { if ( ! empty( $image->file ) ) { $attachments[] = $image->file; } } } } $address = ''; $country = ''; $region = ''; $city = ''; $postal_code = ''; $latitude = ''; $longitude = ''; if ( ! empty( $gd_post ) ) { if ( isset( $gd_post->street ) ) { $address = $gd_post->street; } if ( isset( $gd_post->country ) ) { $country = $gd_post->country; } if ( isset( $gd_post->region ) ) { $region = $gd_post->region; } if ( isset( $gd_post->city ) ) { $city = $gd_post->city; } if ( isset( $gd_post->zip ) ) { $postal_code = $gd_post->zip; } if ( isset( $gd_post->latitude ) ) { $latitude = $gd_post->latitude; } if ( isset( $gd_post->longitude ) ) { $longitude = $gd_post->longitude; } } $base_data = [ 'listing_id' => $post->ID, 'listing_title' => $post->post_title, 'listing_type' => $post->post_type, 'listing_url' => get_permalink( $post->ID ), 'description' => $post->post_content, 'categories' => $categories, 'tags' => $tags, 'attachments' => $attachments, 'address' => $address, 'country' => $country, 'region' => $region, 'city' => $city, 'postal_code' => $postal_code, 'latitude' => $latitude, 'longitude' => $longitude, ]; switch ( $term ) { case 'geodir_claimed_listing_added': case 'geodir_claim_approved': case 'geodir_claim_rejected': $claim = []; $claim_status_text = 'unknown'; if ( 'geodir_claimed_listing_added' === $term ) { $claim_status_text = 'pending'; } elseif ( 'geodir_claim_approved' === $term ) { $claim_status_text = 'approved'; } elseif ( 'geodir_claim_rejected' === $term ) { $claim_status_text = 'rejected'; } global $wpdb; $claim_table = $wpdb->prefix . 'geodir_claim'; $claim_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}geodir_claim WHERE post_id = %d ORDER BY id DESC LIMIT 1", $post_id ) ); if ( $claim_id && class_exists( '\GeoDir_Claim_Post' ) && is_callable( [ '\GeoDir_Claim_Post', 'get_item' ] ) ) { $claim = \GeoDir_Claim_Post::get_item( $claim_id ); } $context['pluggable_data'] = array_merge( $base_data, [ 'claim' => array_merge( (array) $claim, [ 'status' => $claim_status_text, ] ), ], $user ); break; case 'geodir_listing_upgraded': $context['pluggable_data'] = array_merge( $base_data, [ 'package_id' => 789, 'package_name' => 'Premium Package', 'package_amount' => '99.99', 'package_days' => '365', ], $user ); break; default: $context['pluggable_data'] = array_merge( $base_data, $user ); break; } $context['response_type'] = 'live'; return $context; } } $sample_data = [ 'listing_id' => 123, 'listing_title' => 'Sample Business Listing', 'listing_type' => 'gd_place', 'listing_url' => site_url( '/places/sample-business-listing/' ), 'description' => 'This is a sample business listing description.', 'categories' => [ 'Restaurant', 'Cafe' ], 'tags' => [ 'Food', 'Coffee', 'Breakfast' ], 'attachments' => [ site_url( '/wp-content/uploads/sample-image.jpg' ) ], 'address' => '123 Main St', 'country' => 'United States', 'region' => 'California', 'city' => 'San Francisco', 'postal_code' => '94105', 'latitude' => '37.7749', 'longitude' => '-122.4194', 'wp_user_id' => 10, 'user_login' => 'sampleuser', 'display_name' => 'Sample User', 'user_firstname' => 'Sample', 'user_lastname' => 'User', 'user_email' => 'sample@example.com', 'user_role' => [ 'subscriber' ], ]; switch ( $term ) { case 'geodir_claim_approved': case 'geodir_claim_rejected': case 'geodir_claimed_listing_added': $sample_data['claim'] = [ 'id' => 14, 'post_id' => 123, 'post_type' => 'gd_place', 'author_id' => 10, 'user_id' => 10, 'user_fullname' => 'Sample User', 'user_number' => '+1234567890', 'user_position' => 'Business Owner', 'user_ip' => '127.0.0.1', 'user_comments' => 'Hi, I am the owner of this business and I would like to claim it.', 'admin_comments' => '', 'claim_date' => current_time( 'mysql' ), 'status' => 'pending', 'rand_string' => 'sampleclaimstring123', 'payment_id' => 0, 'old_package_id' => 0, 'package_id' => 0, 'meta' => [ 'ninja_form_id' => '2', 'ninja_sub_id' => '', 'ninja_post' => 123, 'extra_fields' => [ 'user_id' => [ 'label' => 'User ID', 'value' => '10', ], ], ], ]; break; case 'geodir_listing_upgraded': $sample_data['package_id'] = 789; $sample_data['package_name'] = 'Premium Package'; $sample_data['package_amount'] = '99.99'; $sample_data['package_days'] = '365'; break; } $context['pluggable_data'] = $sample_data; $context['response_type'] = 'sample'; return $context; } /** * Get WP Subscription triggers last data. * * @param array $data data. * * @return array */ public function search_wp_subscription_triggers_last_data( $data ) { global $wpdb; $context = []; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; $needs_subscription = in_array( $term, [ 'subscription_activated', 'subscription_cancelled', 'subscription_expired', 'subscription_status_changed', 'subscription_pending', 'subscription_pending_cancellation', ], true ); if ( ! $needs_subscription ) { return $context; } $subscription = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type = 'subscrpt_order' ORDER BY post_modified DESC LIMIT 1" ); $sample_subscription = new \stdClass(); $sample_subscription->ID = 100; $sample_subscription->post_author = 2; $sample_subscription->post_date = '2025-07-07 09:51:52'; $sample_subscription->post_date_gmt = '2025-07-07 09:51:52'; $sample_subscription->post_content = ''; $sample_subscription->post_title = 'Subscription #100'; $sample_subscription->post_excerpt = ''; $sample_subscription->post_status = 'active'; $sample_subscription->comment_status = 'closed'; $sample_subscription->ping_status = 'closed'; $sample_subscription->post_password = ''; $sample_subscription->post_name = 'subscription-100'; $sample_subscription->to_ping = ''; $sample_subscription->pinged = ''; $sample_subscription->post_modified = '2025-07-07 10:15:16'; $sample_subscription->post_modified_gmt = '2025-07-07 10:15:16'; $sample_subscription->post_content_filtered = ''; $sample_subscription->post_parent = 0; $sample_subscription->guid = 'http://example.com/subscrpt_order/'; $sample_subscription->menu_order = 0; $sample_subscription->post_type = 'subscrpt_order'; $sample_subscription->post_mime_type = ''; $sample_subscription->comment_count = 4; $sample_subscription->filter = 'raw'; $sub = $subscription ? $subscription : $sample_subscription; $type = $subscription ? 'live' : 'sample'; $pluggable_data = [ 'subscription_id' => $sub->ID, 'subscription' => $sub, 'user_id' => $sub->post_author, ]; if ( 'subscription_status_changed' === $term ) { $pluggable_data['old_status'] = 'pending'; $pluggable_data['new_status'] = $sub->post_status; } $context['pluggable_data'] = $pluggable_data; $context['response_type'] = $type; return $context; } /** * Prepare clickwhale categories. * * @param array $data Search Params. * * @return array */ public function search_clickwhale_categories( $data ) { $options = []; global $wpdb; $categories = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}clickwhale_categories ORDER BY id DESC", ARRAY_A ); if ( ! empty( $categories ) ) { foreach ( $categories as $category ) { $options[] = [ 'label' => $category['title'], 'value' => $category['id'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get ClickWhale Last Data * * @param array $data data. * * @return array */ public function search_clickwhale_triggers_last_data( $data ) { global $wpdb; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; $context = []; $latest_link = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}clickwhale_links ORDER BY id DESC LIMIT 1", ARRAY_A ); $get_author_data = function( $author_id ) { if ( class_exists( '\SureTriggers\Integrations\WordPress\WordPress' ) ) { return WordPress::get_user_context( $author_id ); } return []; }; $format_link = function( $link_data ) use ( $get_author_data ) { $author_id = isset( $link_data['author'] ) ? $link_data['author'] : 0; return [ 'id' => isset( $link_data['id'] ) ? $link_data['id'] : 17, 'title' => isset( $link_data['title'] ) ? $link_data['title'] : 'Sample Title', 'slug' => isset( $link_data['slug'] ) ? $link_data['slug'] : 'sample-slug', 'url' => isset( $link_data['url'] ) ? $link_data['url'] : 'https://example.com', 'redirection' => isset( $link_data['redirection'] ) ? $link_data['redirection'] : '301', 'link_target' => isset( $link_data['link_target'] ) ? $link_data['link_target'] : '', 'nofollow' => isset( $link_data['nofollow'] ) ? $link_data['nofollow'] : '1', 'sponsored' => isset( $link_data['sponsored'] ) ? $link_data['sponsored'] : '0', 'description' => isset( $link_data['description'] ) ? $link_data['description'] : '', 'categories' => isset( $link_data['categories'] ) ? $link_data['categories'] : '', 'author_id' => $author_id, 'author' => $get_author_data( $author_id ), 'created_at' => isset( $link_data['created_at'] ) ? $link_data['created_at'] : current_time( 'mysql' ), 'updated_at' => isset( $link_data['updated_at'] ) ? $link_data['updated_at'] : current_time( 'mysql' ), ]; }; switch ( $term ) { case 'link_created': case 'link_updated': $link_data = ! empty( $latest_link ) ? $format_link( $latest_link ) : $format_link( [] ); $context['pluggable_data'] = [ 'link' => $link_data ]; $context['response_type'] = ! empty( $latest_link ) ? 'live' : 'sample'; break; case 'link_deleted': if ( ! empty( $latest_link ) ) { $context['pluggable_data'] = [ 'link_id' => $latest_link['id'], 'deleted_at' => current_time( 'mysql' ), ]; $context['response_type'] = 'live'; } else { $context['pluggable_data'] = [ 'link_id' => 17, 'deleted_at' => current_time( 'mysql' ), ]; $context['response_type'] = 'sample'; } break; case 'link_clicked': $link_data = ! empty( $latest_link ) ? $format_link( $latest_link ) : $format_link( [] ); $context['pluggable_data'] = [ 'link' => $link_data, ]; $context['response_type'] = ! empty( $latest_link ) ? 'live' : 'sample'; break; } return (array) $context; } /** * Get Pretty Links Last Data * * @param array $data data. * * @return array */ public function search_pretty_links_triggers_last_data( $data ) { global $wpdb; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; $context = []; // Check if Pretty Links plugin is active. if ( ! defined( 'PRLI_VERSION' ) ) { return $context; } // Get latest pretty link. $latest_link = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}prli_links ORDER BY id DESC LIMIT 1", ARRAY_A ); // Get latest click if available. $latest_click = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}prli_clicks ORDER BY id DESC LIMIT 1", ARRAY_A ); $get_user_data = function( $user_id ) { if ( class_exists( '\SureTriggers\Integrations\WordPress\WordPress' ) ) { return WordPress::get_user_context( $user_id ); } return [ 'user_id' => 0, 'user_login' => 'guest', 'display_name' => 'Guest User', 'user_firstname' => '', 'user_lastname' => '', 'user_email' => 'guest@example.com', 'user_role' => [], ]; }; $format_link = function( $link_data ) { return [ 'id' => isset( $link_data['id'] ) ? $link_data['id'] : 17, 'name' => isset( $link_data['name'] ) ? $link_data['name'] : 'Sample Pretty Link', 'url' => isset( $link_data['url'] ) ? $link_data['url'] : 'https://example.com', 'slug' => isset( $link_data['slug'] ) ? $link_data['slug'] : 'sample-link', 'pretty_url' => home_url( '/' . ( isset( $link_data['slug'] ) ? $link_data['slug'] : 'sample-link' ) ), 'description' => isset( $link_data['description'] ) ? $link_data['description'] : 'Sample description', 'redirect_type' => isset( $link_data['redirect_type'] ) ? $link_data['redirect_type'] : '307', 'clicks' => isset( $link_data['clicks'] ) ? $link_data['clicks'] : '5', 'created_at' => isset( $link_data['created_at'] ) ? $link_data['created_at'] : current_time( 'mysql' ), ]; }; $format_click = function( $click_data ) { return [ 'click_id' => isset( $click_data['id'] ) ? $click_data['id'] : 42, 'url' => isset( $click_data['url'] ) ? $click_data['url'] : 'https://example.com', 'timestamp' => isset( $click_data['created_at'] ) ? $click_data['created_at'] : current_time( 'mysql' ), 'is_logged_in' => true, ]; }; switch ( $term ) { case 'link_clicked': $link_data = ! empty( $latest_link ) ? $format_link( $latest_link ) : $format_link( [] ); $click_data = ! empty( $latest_click ) ? $format_click( $latest_click ) : $format_click( [] ); // Get user context from latest click or sample data. $user_id = 0; if ( ! empty( $latest_click ) ) { if ( isset( $latest_click['user'] ) && $latest_click['user'] > 0 ) { $user_id = $latest_click['user']; } elseif ( isset( $latest_click['user_id'] ) && $latest_click['user_id'] > 0 ) { $user_id = $latest_click['user_id']; } elseif ( isset( $latest_click['visitor'] ) && is_numeric( $latest_click['visitor'] ) && $latest_click['visitor'] > 0 ) { $user_id = $latest_click['visitor']; } } if ( $user_id > 0 ) { $user_data = $get_user_data( $user_id ); } else { $user_data = [ 'wp_user_id' => 1, 'user_login' => 'sampleuser', 'display_name' => 'Sample User', 'user_firstname' => 'John', 'user_lastname' => 'Doe', 'user_email' => 'sampleuser@example.com', 'user_registered' => current_time( 'mysql' ), 'user_role' => [ 'subscriber' ], ]; } $context['pluggable_data'] = array_merge( $user_data, [ 'link' => $link_data, 'click' => $click_data, ] ); $context['response_type'] = ! empty( $latest_link ) ? 'live' : 'sample'; break; } return (array) $context; } /** * Get ProfilePress Payment Methods. * * @param array $data data. * * @return array|void */ public function search_profilepress_payment_methods( $data ) { $options = []; if ( class_exists( '\ProfilePress\Core\Membership\PaymentMethods\PaymentMethods' ) ) { $payment_methods = \ProfilePress\Core\Membership\PaymentMethods\PaymentMethods::get_instance()->get_all(); $methods = [ '' => 'Default' ]; if ( ! empty( $payment_methods ) ) { foreach ( $payment_methods as $method ) { $methods[ $method->get_id() ] = $method->get_method_title(); } } $methods = apply_filters( 'ppress_admin_order_page_enabled_payment_methods', $methods ); if ( $methods ) { foreach ( $methods as $id => $name ) { $options[] = [ 'label' => $name, 'value' => $id, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get ProfilePress Order Status List. * * @param array $data data. * * @return array|void */ public function search_profilepress_order_status_list( $data ) { $options = []; if ( class_exists( 'ProfilePress\Core\Membership\Models\Order\OrderStatus' ) ) { $statuses = \ProfilePress\Core\Membership\Models\Order\OrderStatus::get_all(); if ( $statuses ) { foreach ( $statuses as $id => $name ) { $options[] = [ 'label' => $name, 'value' => $id, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get ProfilePress Last Data * * @param array $data data. * * @return array */ public function search_profilepress_triggers_last_data( $data ) { global $wpdb; $context = []; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; switch ( $term ) { /** * Customer Updated trigger. */ case 'profilepress_customer_updated': if ( class_exists( '\ProfilePress\Core\Membership\Models\Customer\CustomerFactory' ) ) { $customer = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}ppress_customers ORDER BY id DESC LIMIT 1", ARRAY_A ); if ( $customer ) { $customer_id = isset( $customer['id'] ) ? (int) $customer['id'] : 0; $customer = \ProfilePress\Core\Membership\Models\Customer\CustomerFactory::fromId( absint( $customer_id ) ); $pluggable_data = [ 'customer' => Utilities::object_to_array( $customer ), ]; $context = [ 'pluggable_data' => $pluggable_data, 'response_type' => 'live', ]; } else { $customer = \ProfilePress\Core\Membership\Models\Customer\CustomerFactory::fromId( absint( 0 ) ); $sample_data = [ 'customer' => Utilities::object_to_array( $customer ), ]; $context = [ 'pluggable_data' => $sample_data, 'response_type' => 'sample', ]; } } break; /** * Subscription Activated trigger. */ case 'profilepress_subscription_activated': $latest_subscription = $wpdb->get_row( 'SELECT * FROM ' . $wpdb->prefix . 'ppress_subscriptions ORDER BY id DESC LIMIT 1', ARRAY_A ); if ( $latest_subscription ) { if ( class_exists( '\ProfilePress\Core\Membership\Models\Subscription\SubscriptionFactory' ) ) { $latest_subscription = \ProfilePress\Core\Membership\Models\Subscription\SubscriptionFactory::fromId( intval( $latest_subscription['id'] ) ); $context['pluggable_data']['subscription'] = Utilities::object_to_array( $latest_subscription ); $context['response_type'] = 'live'; } } else { $sample_subscription = [ 'id' => 1, 'parent_order_id' => 1, 'plan_id' => 1, 'customer_id' => 7, 'billing_frequency' => 'monthly', 'initial_amount' => '10.00000000', 'initial_tax_rate' => '0', 'initial_tax' => '0', 'recurring_amount' => '10.00000000', 'recurring_tax_rate' => '0', 'recurring_tax' => '0', 'total_payments' => '0', 'trial_period' => 'disabled', 'profile_id' => '', 'status' => 'active', 'notes' => null, 'created_date' => '2025-08-19 11:45:41', 'expiration_date' => '2025-09-19 11:45:41', ]; $context['pluggable_data']['subscription'] = $sample_subscription; $context['response_type'] = 'sample'; } break; default: $context['pluggable_data'] = []; $context['response_type'] = 'error'; break; } return $context; } /** * Search FluentCRM Company Data. * * @param array $data data. * @return array */ public function search_pluggables_fluentcrm_company_created( $data ) { global $wpdb; $context = []; $pluggable_data = []; $term = ! empty( $data['search_term'] ) ? $data['search_term'] : ''; if ( ! class_exists( 'FluentCrm\App\Models\Company' ) ) { return []; } $result = null; // Fetch last record based on term. switch ( $term ) { case 'contact_deleted': $result = $wpdb->get_row( "SELECT id FROM {$wpdb->prefix}fc_subscribers ORDER BY id DESC LIMIT 1", ARRAY_A ); break; case 'campaign_sent': $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fc_campaigns WHERE status = 'archived' ORDER BY updated_at DESC LIMIT 1", ARRAY_A ); break; case 'company_updated': $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fc_companies ORDER BY updated_at DESC LIMIT 1", ARRAY_A ); break; case 'company_deleted': case 'company_assigned': case 'company_unassigned': $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fc_companies ORDER BY id DESC LIMIT 1", ARRAY_A ); break; default: // Default to company_created. $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fc_companies ORDER BY created_at DESC LIMIT 1", ARRAY_A ); break; } if ( $result ) { switch ( $term ) { case 'contact_deleted': $pluggable_data = [ 'contact_id' => $result['id'], 'deleted_at' => current_time( 'mysql' ), ]; break; case 'campaign_sent': $campaign_data = $result; if ( ! empty( $campaign_data['settings'] ) ) { $settings = maybe_unserialize( $campaign_data['settings'] ); if ( is_array( $settings ) ) { $campaign_data['settings'] = $settings; } } $pluggable_data = [ 'campaign' => $campaign_data, 'status' => 'archived', 'archived_at' => current_time( 'mysql' ), ]; if ( ! empty( $result['id'] ) ) { $total_emails = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}fc_campaign_emails WHERE campaign_id = %d", $result['id'] ) ); $sent_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}fc_campaign_emails WHERE campaign_id = %d AND status = 'sent'", $result['id'] ) ); $opened_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}fc_campaign_emails WHERE campaign_id = %d AND is_open > 0", $result['id'] ) ); $clicked_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}fc_campaign_emails WHERE campaign_id = %d AND click_counter > 0", $result['id'] ) ); $pluggable_data['total_emails_sent'] = $total_emails; $pluggable_data['sent_count'] = $sent_count; $pluggable_data['opened_count'] = $opened_count; $pluggable_data['clicked_count'] = $clicked_count; $pluggable_data['open_rate'] = $sent_count > 0 ? round( ( $opened_count / $sent_count ) * 100, 2 ) : 0; $pluggable_data['click_rate'] = $sent_count > 0 ? round( ( $clicked_count / $sent_count ) * 100, 2 ) : 0; } break; case 'company_deleted': $pluggable_data = [ 'company_id' => $result['id'], 'deleted_at' => current_time( 'mysql' ), ]; break; case 'company_assigned': case 'company_unassigned': $contact_result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fc_subscribers ORDER BY id DESC LIMIT 1", ARRAY_A ); if ( $contact_result ) { $pluggable_data['contact'] = [ 'details' => $contact_result, 'custom' => [], ]; $pluggable_data['companies'] = [ $result ]; if ( 'company_assigned' === $term ) { $pluggable_data['assigned_company_ids'] = [ $result['id'] ]; $pluggable_data['assigned_at'] = current_time( 'mysql' ); } else { $pluggable_data['unassigned_company_ids'] = [ $result['id'] ]; $pluggable_data['unassigned_at'] = current_time( 'mysql' ); } } break; default: $meta_data = ! empty( $result['meta'] ) ? maybe_unserialize( $result['meta'] ) : []; $company_result = array_intersect_key( $result, array_flip( [ 'id', 'hash', 'name', 'email', 'description', 'address_line_1', 'address_line_2', 'city', 'state', 'postal_code', 'country', 'phone', 'type', 'owner_id', 'employees_number', 'industry', 'website', 'linkedin_url', 'facebook_url', 'twitter_url', 'logo', 'timezone', 'date_of_start', 'created_at', 'updated_at', ] ) ); if ( is_array( $meta_data ) && isset( $meta_data['custom_values'] ) ) { $company_result['custom_fields'] = $meta_data['custom_values']; } $pluggable_data['company'] = $company_result; break; } $context['response_type'] = 'live'; } else { // Sample data for different terms. switch ( $term ) { case 'contact_deleted': $pluggable_data = [ 'contact_id' => 1, 'deleted_at' => current_time( 'mysql' ), ]; break; case 'campaign_sent': $pluggable_data = [ 'campaign' => [ 'id' => 1, 'type' => 'campaign', 'title' => 'Sample Email Campaign', 'status' => 'archived', 'template_id' => 1, 'email_subject' => 'Welcome to Our Newsletter!', 'email_body' => 'Sample campaign email content...', 'utm_status' => 1, 'utm_source' => 'fluentcrm', 'utm_medium' => 'email', 'utm_campaign' => 'sample-campaign', 'created_by' => 1, 'created_at' => current_time( 'mysql' ), 'updated_at' => current_time( 'mysql' ), 'scheduled_at' => current_time( 'mysql' ), ], 'status' => 'archived', 'archived_at' => current_time( 'mysql' ), 'total_emails_sent' => 1500, 'sent_count' => 1450, 'opened_count' => 725, 'clicked_count' => 145, 'open_rate' => 50.0, 'click_rate' => 10.0, ]; break; case 'company_deleted': $pluggable_data = [ 'company_id' => 1, 'deleted_at' => current_time( 'mysql' ), ]; break; case 'company_assigned': case 'company_unassigned': $pluggable_data['contact']['details'] = [ 'id' => 1, 'user_id' => 1, 'hash' => 'sample_hash', 'contact_owner' => 0, 'company_id' => 0, 'prefix' => 'Mr.', 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john@example.com', 'timezone' => 'America/New_York', 'address_line_1' => '123 Main Street', 'address_line_2' => 'Apt 4B', 'postal_code' => '10001', 'city' => 'New York', 'state' => 'NY', 'country' => 'USA', 'phone' => '+1-555-123-4567', 'status' => 'subscribed', 'contact_type' => 'customer', 'source' => 'manual', 'lifecycle_stage' => 'customer', 'created_at' => current_time( 'mysql' ), 'updated_at' => current_time( 'mysql' ), ]; $pluggable_data['contact']['custom'] = []; $pluggable_data['companies'] = [ [ 'id' => 1, 'hash' => 'sample_hash', 'name' => 'Sample Company Inc.', 'email' => 'contact@samplecompany.com', 'description' => 'This is a sample company', 'address_line_1' => '123 Business Street', 'address_line_2' => 'Suite 100', 'city' => 'Business City', 'state' => 'California', 'postal_code' => '90210', 'country' => 'USA', 'phone' => '+1-555-123-4567', 'type' => 'client', 'created_at' => current_time( 'mysql' ), 'updated_at' => current_time( 'mysql' ), ], ]; if ( 'company_assigned' === $term ) { $pluggable_data['assigned_company_ids'] = [ 1 ]; $pluggable_data['assigned_at'] = current_time( 'mysql' ); } else { $pluggable_data['unassigned_company_ids'] = [ 1 ]; $pluggable_data['unassigned_at'] = current_time( 'mysql' ); } break; case 'company_created': case 'company_updated': default: $pluggable_data['company'] = [ 'id' => 1, 'hash' => 'sample_hash', 'name' => 'Sample Company Inc.', 'email' => 'contact@samplecompany.com', 'description' => 'This is a sample company', 'address_line_1' => '123 Business Street', 'address_line_2' => 'Suite 100', 'city' => 'Business City', 'state' => 'California', 'postal_code' => '90210', 'country' => 'USA', 'phone' => '+1-555-123-4567', 'type' => 'client', 'owner_id' => 1, 'employees_number' => 50, 'industry' => 'Technology', 'website' => 'https://samplecompany.com', 'linkedin_url' => 'https://linkedin.com/company/samplecompany', 'facebook_url' => 'https://facebook.com/samplecompany', 'twitter_url' => 'https://twitter.com/samplecompany', 'logo' => '', 'timezone' => 'America/Los_Angeles', 'date_of_start' => '2024-01-01', 'created_at' => '2024-01-01 10:00:00', 'updated_at' => '2024-01-01 10:00:00', 'custom_fields' => [ 'annual_revenue' => '$1,000,000', 'primary_contact' => 'John Doe', ], ]; break; } $context['response_type'] = 'sample'; } $context['pluggable_data'] = $pluggable_data; return $context; } /** * Get FluentCRM email trigger details. * * @param array $data data. * * @return array */ public function search_pluggables_fluentcrm_email_triggers( $data ) { $context = []; $pluggable_data = []; global $wpdb; $term = $data['search_term'] ? $data['search_term'] : ''; // Helper function to build email data structure. $build_email_data = function( $email_result, $subscriber_result = null, $subscriber_status = null ) { $email_data = [ 'id' => $email_result['id'], 'status' => $email_result['status'], 'is_open' => $email_result['is_open'], 'is_parsed' => $email_result['is_parsed'], 'created_at' => $email_result['created_at'], 'updated_at' => isset( $email_result['updated_at'] ) ? $email_result['updated_at'] : $email_result['created_at'], 'campaign_id' => isset( $email_result['campaign_id'] ) ? $email_result['campaign_id'] : null, 'scheduled_at' => isset( $email_result['scheduled_at'] ) ? $email_result['scheduled_at'] : $email_result['created_at'], 'email_address' => isset( $email_result['email_address'] ) ? $email_result['email_address'] : ( isset( $subscriber_result['email'] ) ? $subscriber_result['email'] : '' ), 'email_headers' => isset( $email_result['email_headers'] ) ? $email_result['email_headers'] : '', 'email_subject' => isset( $email_result['email_subject'] ) ? $email_result['email_subject'] : '', 'email_body' => $email_result['email_body'], 'email_hash' => $email_result['email_hash'], 'email_type' => $email_result['email_type'], 'subscriber_id' => $email_result['subscriber_id'], ]; if ( $subscriber_result ) { $subscriber_fields = [ 'hash', 'email', 'phone', 'photo', 'prefix', 'status', 'full_name', 'last_name', 'created_at', 'first_name', 'updated_at', ]; foreach ( $subscriber_fields as $field ) { $email_data[ 'subscriber_' . $field ] = $subscriber_result[ $field ]; } if ( $subscriber_status ) { $email_data['subscriber_status'] = $subscriber_status; } } return $email_data; }; // Helper function to get sample email data. $get_sample_email_data = function( $status = 'subscribed' ) { return [ 'id' => 1, 'status' => 'sent', 'is_open' => 0, 'is_parsed' => 1, 'created_at' => current_time( 'mysql' ), 'updated_at' => current_time( 'mysql' ), 'campaign_id' => 83, 'scheduled_at' => current_time( 'mysql' ), 'email_address' => 'john@example.com', 'email_headers' => 'From: noreply@example.com', 'email_subject' => 'Sample Email Subject', 'email_body' => 'Sample email content here...', 'email_hash' => 'sample-email-hash-123', 'email_type' => 'campaign', 'subscriber_id' => 1, 'subscriber_hash' => 'sample_hash', 'subscriber_email' => 'john@example.com', 'subscriber_phone' => '9876654423', 'subscriber_photo' => 'http://example.com/avatar.png', 'subscriber_prefix' => 'Mr.', 'subscriber_status' => $status, 'subscriber_full_name' => 'John Doe', 'subscriber_last_name' => 'Doe', 'subscriber_created_at' => current_time( 'mysql' ), 'subscriber_first_name' => 'John', 'subscriber_updated_at' => current_time( 'mysql' ), ]; }; // Get result based on term. $result = null; if ( 'email_opened' === $term ) { $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fc_campaign_emails ORDER BY id DESC LIMIT %d", 1 ), ARRAY_A ); } elseif ( 'email_clicked' === $term ) { $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fc_campaign_emails WHERE click_counter > %d ORDER BY id DESC LIMIT %d", 0, 1 ), ARRAY_A ); } elseif ( 'email_unsubscribed' === $term ) { $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fc_subscribers WHERE status = 'unsubscribed' ORDER BY updated_at DESC LIMIT %d", 1 ), ARRAY_A ); } elseif ( 'email_bounced' === $term ) { $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fc_subscribers WHERE status = 'bounced' ORDER BY updated_at DESC LIMIT %d", 1 ), ARRAY_A ); } if ( $result ) { if ( 'email_opened' === $term || 'email_clicked' === $term ) { // Get subscriber details. $subscriber_result = null; if ( ! empty( $result['subscriber_id'] ) ) { $subscriber_result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fc_subscribers WHERE id = %d", $result['subscriber_id'] ), ARRAY_A ); } $pluggable_data['email'] = $build_email_data( $result, $subscriber_result ); $pluggable_data[ 'email_opened' === $term ? 'opened_at' : 'clicked_at' ] = current_time( 'mysql' ); } elseif ( 'email_unsubscribed' === $term ) { // Get email data for subscriber. $email_result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fc_campaign_emails WHERE subscriber_id = %d ORDER BY id DESC LIMIT %d", $result['id'], 1 ), ARRAY_A ); if ( $email_result ) { $pluggable_data['email'] = $build_email_data( $email_result, $result ); } $pluggable_data['source'] = 'from_header'; $pluggable_data['unsubscribed_at'] = current_time( 'mysql' ); } elseif ( 'email_bounced' === $term ) { // For bounced emails, we only need subscriber object and bounce-specific fields. $subscriber_data = []; $subscriber_fields = [ 'id', 'hash', 'email', 'phone', 'photo', 'prefix', 'status', 'full_name', 'last_name', 'created_at', 'first_name', 'updated_at', 'contact_type', 'total_points', 'last_activity', 'life_time_value', 'ip', ]; foreach ( $subscriber_fields as $field ) { if ( isset( $result[ $field ] ) ) { $subscriber_data[ $field ] = $result[ $field ]; } } $pluggable_data['subscriber'] = $subscriber_data; // Add bounce-specific data. $pluggable_data['old_status'] = 'subscribed'; $pluggable_data['new_status'] = 'bounced'; $pluggable_data['bounced_at'] = $result['updated_at']; } $context['response_type'] = 'live'; } else { // Sample data for different email terms. if ( 'email_opened' === $term || 'email_clicked' === $term ) { $pluggable_data['email'] = $get_sample_email_data(); if ( 'email_opened' === $term ) { $pluggable_data['opened_at'] = current_time( 'mysql' ); } else { $pluggable_data['url'] = [ 'id' => 1, 'url' => 'https://example.com/sample-link', 'short_url' => 'https://example.com/r/abc123', 'title' => 'Sample Link', 'created_at' => current_time( 'mysql' ), ]; $pluggable_data['clicked_at'] = current_time( 'mysql' ); } } elseif ( 'email_unsubscribed' === $term ) { $pluggable_data['email'] = $get_sample_email_data( 'unsubscribed' ); $pluggable_data['source'] = 'from_header'; $pluggable_data['unsubscribed_at'] = current_time( 'mysql' ); } elseif ( 'email_bounced' === $term ) { // Sample subscriber object for bounced email (no email object). $pluggable_data['subscriber'] = [ 'id' => 8, 'ip' => '::1', 'hash' => '6b2c0a83138a7e42ef12e6f87e8c58aa', 'email' => 'mrunalis@bsf.io', 'phone' => '9876654423', 'photo' => 'http://ottokit.local/wp-content/plugins/fluent-crm/assets/images/avatar.png', 'prefix' => 'Ms', 'status' => 'bounced', 'full_name' => 'Mrunali Salunke', 'last_name' => 'Salunke', 'created_at' => '2025-09-18 04:51:26', 'first_name' => 'Mrunali', 'updated_at' => current_time( 'mysql' ), 'contact_type' => 'lead', 'total_points' => 0, 'last_activity' => '2025-09-25 05:47:45', 'life_time_value' => 0, ]; $pluggable_data['old_status'] = 'subscribed'; $pluggable_data['new_status'] = 'bounced'; $pluggable_data['bounced_at'] = current_time( 'mysql' ); } $context['response_type'] = 'sample'; } $context['pluggable_data'] = $pluggable_data; return $context; } /** * Get WooCommerce Subscription triggers last data. * * @param array $data data. * * @return array */ public function search_woocommerce_subscription_triggers_last_data( $data ) { $context = []; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; if ( ! class_exists( 'WC_Subscription' ) || ! function_exists( 'wcs_get_subscription' ) ) { return $context; } $needs_subscription = in_array( $term, [ 'wc_subscription_updated', 'wc_cancels_subscription_product', 'wc_subscribes_product', 'wc_purchases_variable_subscription', 'wc_renews_subscription_product', 'wc_subscription_product_expires', ], true ); if ( ! $needs_subscription ) { return $context; } $subscription = null; $subscription_obj = null; if ( function_exists( 'wcs_get_subscriptions' ) ) { $subscriptions = wcs_get_subscriptions( [ 'subscriptions_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC', ] ); if ( ! empty( $subscriptions ) ) { $subscription_obj = reset( $subscriptions ); $subscription = (object) [ 'ID' => $subscription_obj->get_id() ]; } } if ( $subscription && ! $subscription_obj ) { $subscription_obj = wcs_get_subscription( $subscription->ID ); } if ( $subscription_obj ) { $user_id = $subscription_obj->get_user_id(); $items = $subscription_obj->get_items(); $product_id = 0; $variation_id = 0; $product_name = ''; $variation_name = ''; foreach ( $items as $item ) { $product_id = $item->get_product_id(); $variation_id = $item->get_variation_id(); $product_name = $item->get_name(); $variation_name = $item->get_name(); break; } $user_billing_data = [ 'billing_first_name' => $subscription_obj->get_billing_first_name(), 'billing_last_name' => $subscription_obj->get_billing_last_name(), 'billing_country' => $subscription_obj->get_billing_country(), 'billing_address_1' => $subscription_obj->get_billing_address_1(), 'billing_address_2' => $subscription_obj->get_billing_address_2(), 'billing_city' => $subscription_obj->get_billing_city(), 'billing_state' => $subscription_obj->get_billing_state(), 'billing_postcode' => $subscription_obj->get_billing_postcode(), 'billing_phone' => $subscription_obj->get_billing_phone(), 'billing_email' => $subscription_obj->get_billing_email(), ]; if ( 'wc_subscription_updated' === $term ) { $subscription_data = [ 'start_date' => $subscription_obj->get_date_created(), 'next_payment_date' => $subscription_obj->get_date( 'next_payment' ) ? $subscription_obj->get_date( 'next_payment' ) : 0, ]; $context['variation_id'] = $variation_id; $context['product_id'] = $product_id; $context['subscription'] = $product_id; $context['variation_name'] = $variation_name; $context['product_name'] = $product_name; $context['subscription_data'] = $subscription_data; $context['subscription_id'] = $subscription_obj->get_id(); $context['user'] = WordPress::get_user_context( $user_id ); $context['user_billing_data'] = $user_billing_data; $context['new_status'] = $subscription_obj->get_status(); $context['old_status'] = 'pending-cancel'; $context['status'] = 'wc-' . $subscription_obj->get_status(); } elseif ( 'wc_cancels_subscription_product' === $term ) { $subscription_data = [ 'status' => $subscription_obj->get_status(), 'start_date' => $subscription_obj->get_date_created(), ]; $context['subscription_data'] = $subscription_data; $context['user'] = WordPress::get_user_context( $user_id ); $context['user_billing_data'] = $user_billing_data; $context['subscription_id'] = $subscription_obj->get_id(); } elseif ( 'wc_subscribes_product' === $term ) { $subscription_data = [ 'status' => $subscription_obj->get_status(), 'start_date' => $subscription_obj->get_date_created(), 'next_payment_date' => $subscription_obj->get_date( 'next_payment' ) ? $subscription_obj->get_date( 'next_payment' ) : 0, ]; $context['subscription_data'] = $subscription_data; $context['subscription_id'] = $subscription_obj->get_id(); $context['user'] = WordPress::get_user_context( $user_id ); $context['user_billing_data'] = $user_billing_data; $context['subscription'] = $subscription_obj->get_id(); $context['subscription_name'] = get_the_title( $product_id ); } elseif ( 'wc_purchases_variable_subscription' === $term ) { $subscription_data = [ 'status' => $subscription_obj->get_status(), 'start_date' => $subscription_obj->get_date_created(), 'next_payment_date' => $subscription_obj->get_date( 'next_payment' ) ? $subscription_obj->get_date( 'next_payment' ) : 0, ]; $context['subscription_data'] = $subscription_data; $context['user'] = WordPress::get_user_context( $user_id ); $context['user_billing_data'] = $user_billing_data; $context['variable_subscription_option'] = $variation_id; $context['variable_subscription'] = $product_id; $context['subscription_name'] = $variation_name; $context['subscription_id'] = $subscription_obj->get_id(); } elseif ( 'wc_renews_subscription_product' === $term ) { $subscription_data = [ 'status' => $subscription_obj->get_status(), 'start_date' => $subscription_obj->get_date_created(), 'next_payment_date' => $subscription_obj->get_date( 'next_payment' ) ? $subscription_obj->get_date( 'next_payment' ) : 0, ]; $context['subscription'] = $product_id; $context['subscription_name'] = get_the_title( $product_id ); $context['last_order'] = $subscription_obj->get_last_order(); $context['subscription_data'] = $subscription_data; $context['subscription_id'] = $subscription_obj->get_id(); $context['user'] = WordPress::get_user_context( $user_id ); $context['user_billing_data'] = $user_billing_data; } elseif ( 'wc_subscription_product_expires' === $term ) { $subscription_data = [ 'status' => $subscription_obj->get_status(), 'start_date' => $subscription_obj->get_date_created(), 'next_payment_date' => $subscription_obj->get_date( 'next_payment' ) ? $subscription_obj->get_date( 'next_payment' ) : 0, ]; $context['subscription_data'] = $subscription_data; $context['subscription_id'] = $subscription_obj->get_id(); $context['user'] = WordPress::get_user_context( $user_id ); $context['user_billing_data'] = $user_billing_data; $context['subscription'] = $product_id; $context['subscription_name'] = get_the_title( $product_id ); } $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $sample_user = [ 'wp_user_id' => 1, 'user_login' => 'johndoe', 'display_name' => 'John Doe', 'user_firstname' => 'John', 'user_lastname' => 'Doe', 'user_email' => 'john.doe@example.com', 'user_registered' => '2024-01-15 10:30:25', 'user_role' => [ 'customer', 'subscriber', ], ]; $sample_billing_data = [ 'billing_first_name' => 'John', 'billing_last_name' => 'Doe', 'billing_country' => 'US', 'billing_address_1' => '123 Main Street', 'billing_address_2' => 'Apt 4B', 'billing_city' => 'New York', 'billing_state' => 'NY', 'billing_postcode' => '10001', 'billing_phone' => '+1-555-123-4567', 'billing_email' => 'john.doe@example.com', ]; $sample_start_date = [ 'utc_offset' => 0, 'date' => '2024-01-15 08:30:25.000000', 'timezone_type' => 1, 'timezone' => '+00:00', ]; if ( 'wc_subscription_updated' === $term ) { $context = [ 'variation_id' => 0, 'product_id' => 73, 'subscription' => 73, 'variation_name' => 'Hi-Fi Headphones', 'product_name' => 'Hi-Fi Headphones', 'subscription_data' => [ 'start_date' => $sample_start_date, 'next_payment_date' => '2024-12-15 08:30:25', ], 'subscription_id' => 1234, 'user' => $sample_user, 'user_billing_data' => $sample_billing_data, 'new_status' => 'active', 'old_status' => 'pending-cancel', 'status' => 'wc-active', ]; } elseif ( 'wc_cancels_subscription_product' === $term ) { $context = [ 'subscription_data' => [ 'status' => 'cancelled', 'start_date' => $sample_start_date, ], 'user' => $sample_user, 'user_billing_data' => $sample_billing_data, 'subscription_id' => 1567, ]; } elseif ( 'wc_subscribes_product' === $term ) { $context = [ 'subscription_data' => [ 'status' => 'active', 'start_date' => $sample_start_date, 'next_payment_date' => '2025-10-07 08:38:53', ], 'subscription_id' => 1798, 'user' => $sample_user, 'user_billing_data' => $sample_billing_data, 'subscription' => 1795, 'subscription_name' => 'Subscription Product', ]; } elseif ( 'wc_purchases_variable_subscription' === $term ) { $context = [ 'subscription_data' => [ 'status' => 'active', 'start_date' => $sample_start_date, 'next_payment_date' => '2025-11-06 05:25:01', ], 'user' => $sample_user, 'user_billing_data' => $sample_billing_data, 'variable_subscription_option' => 1803, 'variable_subscription' => 1802, 'subscription_name' => 'Variation test product – 1200, 10', 'subscription_id' => 1836, ]; } elseif ( 'wc_renews_subscription_product' === $term ) { $context = [ 'subscription' => 1234, 'subscription_name' => 'Monthly Subscription Product', 'last_order' => 5678, 'subscription_data' => [ 'status' => 'active', 'start_date' => $sample_start_date, 'next_payment_date' => '2025-11-06 08:30:25', ], 'subscription_id' => 1567, 'user' => $sample_user, 'user_billing_data' => $sample_billing_data, ]; } elseif ( 'wc_subscription_product_expires' === $term ) { $context = [ 'subscription_data' => [ 'status' => 'expired', 'start_date' => $sample_start_date, 'next_payment_date' => '2025-01-15 08:30:25', ], 'subscription_id' => 1890, 'user' => $sample_user, 'user_billing_data' => $sample_billing_data, 'subscription' => 1567, 'subscription_name' => 'Premium Subscription Product', ]; } $context['pluggable_data'] = $context; $context['response_type'] = 'sample'; } return $context; } /** * Prepare FluentCart Product list. * * @param array $data data. * * @return array */ public function search_fluentcart_product_list( $data ) { $options = []; if ( ! class_exists( '\FluentCart\App\Models\Product' ) ) { return [ 'options' => $options, 'hasMore' => false, ]; } $page = isset( $data['page'] ) ? max( 1, intval( $data['page'] ) ) : 1; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $search_term = isset( $data['search_term'] ) ? $data['search_term'] : ''; // Start with a basic query. $query = \FluentCart\App\Models\Product::where( 'post_status', 'publish' ); if ( ! empty( $search_term ) ) { $query->where( 'post_title', 'LIKE', '%' . $search_term . '%' ); } $products = $query->select( [ 'ID', 'post_title' ] ) ->offset( $offset ) ->limit( $limit ) ->get(); if ( ! empty( $products ) ) { foreach ( $products as $product ) { $options[] = [ 'label' => $product->post_title, 'value' => $product->ID, ]; } } // Get total count for pagination. $total_query = \FluentCart\App\Models\Product::where( 'post_status', 'publish' ); if ( ! empty( $search_term ) ) { $total_query->where( 'post_title', 'LIKE', '%' . $search_term . '%' ); } $posts_count = $total_query->count(); return [ 'options' => $options, 'hasMore' => $posts_count > ( $offset + $limit ), ]; } /** * Search SureDash triggers last data. * * @param array $data query params. * * @return array * @since 1.0.0 */ public function search_suredash_triggers_last_data( $data ) { $context = []; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; global $wpdb; // Sample user data reused across all cases. $sample_user = [ 'user_id' => 789, 'user_login' => 'john_doe', 'user_email' => 'john@example.com', 'user_nicename' => 'John Doe', 'display_name' => 'John Doe', ]; switch ( $term ) { case 'suredash_comments_data': $recent_comments = $wpdb->get_results( $wpdb->prepare( "SELECT c.*, p.post_title, p.post_content, p.post_author, p.post_type, p.post_status FROM {$wpdb->comments} c LEFT JOIN {$wpdb->posts} p ON c.comment_post_ID = p.ID WHERE c.comment_approved = 1 ORDER BY c.comment_date DESC LIMIT %d", 1 ) ); if ( ! empty( $recent_comments ) ) { $comment = $recent_comments[0]; $user_context = []; if ( $comment->user_id ) { $user_context = WordPress::get_user_context( $comment->user_id ); } $context = array_merge( [ 'comment_id' => $comment->comment_ID, 'comment_content' => $comment->comment_content, 'comment_author' => $comment->comment_author, 'comment_author_email' => $comment->comment_author_email, 'comment_date' => $comment->comment_date, 'comment_approved' => $comment->comment_approved, 'comment_type' => $comment->comment_type, 'comment_parent' => $comment->comment_parent, 'post_id' => $comment->comment_post_ID, 'post_title' => $comment->post_title, 'post_content' => $comment->post_content, 'post_author' => $comment->post_author, 'post_type' => $comment->post_type, 'post_status' => $comment->post_status, 'post_permalink' => get_permalink( $comment->comment_post_ID ), 'suredash_post' => $comment->comment_post_ID, ], $user_context ); $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $context = [ 'comment_id' => 123, 'comment_content' => 'This is a sample comment submission', 'comment_author' => 'John Doe', 'comment_author_email' => 'john@example.com', 'comment_date' => '2024-01-15 10:30:00', 'comment_approved' => 1, 'comment_type' => 'comment', 'comment_parent' => 0, 'post_id' => 456, 'post_title' => 'Sample Course Title', 'post_content' => 'Course content here...', 'post_author' => 1, 'post_type' => 'suredash_course', 'post_status' => 'publish', 'post_permalink' => 'https://example.com/course/sample-course', 'suredash_post' => 456, ]; $context = array_merge( $context, $sample_user ); $context['pluggable_data'] = $context; $context['response_type'] = 'sample'; } return $context; case 'suredash_comment_deleted_data': $recent_comments = $wpdb->get_results( $wpdb->prepare( "SELECT c.comment_ID, c.user_id FROM {$wpdb->comments} c ORDER BY c.comment_date DESC LIMIT %d", 1 ) ); if ( ! empty( $recent_comments ) ) { $comment = $recent_comments[0]; $user_context = WordPress::get_user_context( $comment->user_id ); $context = array_merge( [ 'comment_id' => $comment->comment_ID, ], $user_context ); $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $context = array_merge( [ 'comment_id' => 123 ], $sample_user ); $context['pluggable_data'] = $context; $context['response_type'] = 'sample'; } return $context; case 'suredash_post_deleted_data': $recent_posts = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_author FROM {$wpdb->posts} ORDER BY post_date DESC LIMIT %d", 1 ) ); if ( ! empty( $recent_posts ) ) { $post = $recent_posts[0]; $user_context = WordPress::get_user_context( $post->post_author ); $context = array_merge( [ 'post_id' => $post->ID, 'deleter_user_id' => $post->post_author, ], $user_context ); $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $context = array_merge( [ 'post_id' => 456, 'deleter_user_id' => 789, ], $sample_user ); $context['pluggable_data'] = $context; $context['response_type'] = 'sample'; } return $context; case 'suredash_post_data': $recent_posts = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_type NOT IN ('revision', 'nav_menu_item', 'attachment') ORDER BY post_date DESC LIMIT %d", 1 ) ); if ( ! empty( $recent_posts ) ) { $post = $recent_posts[0]; $user_context = WordPress::get_user_context( $post->post_author ); $context = array_merge( [ 'post_id' => $post->ID, 'post_title' => $post->post_title, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_status' => $post->post_status, 'post_author' => $post->post_author, 'post_date' => $post->post_date, 'post_modified' => $post->post_modified, 'post_type' => $post->post_type, 'post_name' => $post->post_name, 'post_permalink' => get_permalink( $post->ID ), 'suredash_post' => $post->ID, 'form_data' => [], ], $user_context ); $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $context = [ 'post_id' => 456, 'post_title' => 'Sample Post Title', 'post_content' => 'This is sample post content for SureDash...', 'post_excerpt' => 'Sample excerpt', 'post_status' => 'publish', 'post_author' => 1, 'post_date' => '2024-01-15 10:30:00', 'post_modified' => '2024-01-15 10:35:00', 'post_type' => 'post', 'post_name' => 'sample-post-title', 'post_permalink' => 'https://example.com/sample-post-title', 'suredash_post' => 456, 'form_data' => [ 'post_title' => 'Sample Post Title', 'post_content' => 'Sample content', ], ]; $context = array_merge( $context, $sample_user ); $context['pluggable_data'] = $context; $context['response_type'] = 'sample'; } return $context; case 'suredash_item_bookmarked': $recent_posts = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_type NOT IN ('revision', 'nav_menu_item', 'attachment') ORDER BY post_date DESC LIMIT %d", 1 ) ); if ( ! empty( $recent_posts ) ) { $post = $recent_posts[0]; $user_context = WordPress::get_user_context( $post->post_author ); $context = array_merge( [ 'item_id' => $post->ID, 'item_type' => $post->post_type, 'bookmark_status' => 'bookmarked', 'is_bookmarked' => true, 'is_unbookmarked' => false, 'item_title' => $post->post_title, 'item_content' => $post->post_content, 'item_excerpt' => $post->post_excerpt, 'item_author' => $post->post_author, 'item_date' => $post->post_date, 'item_status' => $post->post_status, 'item_permalink' => get_permalink( $post->ID ), ], $user_context ); $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $context = [ 'item_id' => 456, 'item_type' => 'post', 'bookmark_status' => 'bookmarked', 'is_bookmarked' => true, 'is_unbookmarked' => false, 'item_title' => 'Sample Item Title', 'item_content' => 'This is sample item content for bookmarking...', 'item_excerpt' => 'Sample item excerpt', 'item_author' => 1, 'item_date' => '2024-01-15 10:30:00', 'item_status' => 'publish', 'item_permalink' => 'https://example.com/sample-item-title', ]; $context = array_merge( $context, $sample_user ); $context['pluggable_data'] = $context; $context['response_type'] = 'sample'; } return $context; case 'suredash_space_data': $recent_posts = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_type NOT IN ('revision', 'nav_menu_item', 'attachment') ORDER BY post_date DESC LIMIT %d", 1 ) ); if ( ! empty( $recent_posts ) ) { $post = $recent_posts[0]; $context = [ 'space_id' => $post->ID, 'space_status' => 'deleted', ]; $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $context = [ 'space_id' => 456, 'space_status' => 'deleted', ]; $context['pluggable_data'] = $context; $context['response_type'] = 'sample'; } return $context; default: return $context; } } /** * Get MailerPress contact lists * * @param array $data data. * * @return array */ public function search_mailerpress_contact_lists( $data ) { global $wpdb; $lists = $wpdb->get_results( "SELECT name, list_id FROM {$wpdb->prefix}mailerpress_lists ORDER BY name ASC" ); $options = []; if ( ! empty( $lists ) ) { foreach ( $lists as $list ) { $options[] = [ 'label' => $list->name, 'value' => $list->list_id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get MailerPress contact tags * * @param array $data data. * * @return array */ public function search_mailerpress_contact_tags( $data ) { global $wpdb; $tags = $wpdb->get_results( "SELECT name, tag_id FROM {$wpdb->prefix}mailerpress_tags ORDER BY name ASC" ); $options = []; if ( ! empty( $tags ) ) { foreach ( $tags as $tag ) { $options[] = [ 'label' => $tag->name, 'value' => $tag->tag_id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get MailerPress last data * * @param array $data data. * * @return array */ public function search_mailerpress_last_data( $data ) { $context = []; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; global $wpdb; switch ( $term ) { case 'mailerpress_contact_data': $recent_contact = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}mailerpress_contact ORDER BY created_at DESC LIMIT 1" ); if ( $recent_contact ) { $context = [ 'contact_id' => $recent_contact->contact_id, 'email' => $recent_contact->email, 'first_name' => $recent_contact->first_name, 'last_name' => $recent_contact->last_name, 'subscription_status' => $recent_contact->subscription_status, 'opt_in_source' => $recent_contact->opt_in_source, 'opt_in_details' => $recent_contact->opt_in_details, 'created_at' => $recent_contact->created_at, 'updated_at' => $recent_contact->updated_at, ]; $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $context = [ 'contact_id' => 15, 'email' => 'sarah.johnson@example.com', 'first_name' => 'Sarah', 'last_name' => 'Johnson', 'subscription_status' => 'subscribed', 'opt_in_source' => 'signup_form', 'opt_in_details' => 'Newsletter signup - Homepage', 'created_at' => '2025-12-01 14:23:17', 'updated_at' => '2025-12-01 14:23:17', ]; $context['pluggable_data'] = $context; $context['response_type'] = 'sample'; } break; case 'list_created': $recent_list = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}mailerpress_lists ORDER BY created_at DESC LIMIT 1" ); if ( $recent_list ) { $user_data = get_userdata( 1 ); $context['pluggable_data'] = [ 'wp_user_id' => $user_data ? $user_data->ID : 1, 'user_login' => $user_data ? $user_data->user_login : 'root', 'display_name' => $user_data ? $user_data->display_name : 'Arian', 'user_firstname' => get_user_meta( $user_data ? $user_data->ID : 1, 'first_name', true ) ? get_user_meta( $user_data ? $user_data->ID : 1, 'first_name', true ) : '', 'user_lastname' => get_user_meta( $user_data ? $user_data->ID : 1, 'last_name', true ) ? get_user_meta( $user_data ? $user_data->ID : 1, 'last_name', true ) : '', 'user_email' => $user_data ? $user_data->user_email : 'dev-email@wpengine.local', 'user_registered' => $user_data ? $user_data->user_registered : '2025-07-02 10:50:38', 'user_role' => $user_data ? $user_data->roles : [ 'administrator' ], 'list' => [ 'id' => $recent_list->list_id, 'name' => $recent_list->name, 'description' => $recent_list->description, 'created_at' => $recent_list->created_at, 'updated_at' => $recent_list->updated_at, ], ]; $context['response_type'] = 'live'; } else { $context['pluggable_data'] = [ 'wp_user_id' => 1, 'user_login' => 'root', 'display_name' => 'Arian', 'user_firstname' => '', 'user_lastname' => '', 'user_email' => 'dev-email@wpengine.local', 'user_registered' => '2025-07-02 10:50:38', 'user_role' => [ 'administrator' ], 'list' => [ 'id' => 7, 'name' => 'Weekly Newsletter Subscribers', 'description' => 'Subscribers who opted in for weekly newsletter updates', 'created_at' => '2025-12-01 10:15:23', 'updated_at' => '2025-12-01 15:30:45', ], ]; $context['response_type'] = 'sample'; } break; case 'contact_added_to_list': $recent_list = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}mailerpress_lists ORDER BY created_at DESC LIMIT 1" ); $recent_contact = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}mailerpress_contact ORDER BY created_at DESC LIMIT 1" ); if ( $recent_contact && $recent_list ) { $context['pluggable_data'] = [ 'contact' => [ 'id' => $recent_contact->contact_id, 'email' => $recent_contact->email, 'first_name' => $recent_contact->first_name, 'last_name' => $recent_contact->last_name, 'subscription_status' => $recent_contact->subscription_status, 'created_at' => $recent_contact->created_at, 'updated_at' => $recent_contact->updated_at, ], 'list' => [ 'id' => $recent_list->list_id, 'name' => $recent_list->name, 'description' => $recent_list->description, 'created_at' => $recent_list->created_at, 'updated_at' => $recent_list->updated_at, ], ]; $context['response_type'] = 'live'; } else { $context['pluggable_data'] = [ 'contact' => [ 'id' => 12, 'email' => 'michael.chen@company.com', 'first_name' => 'Michael', 'last_name' => 'Chen', 'subscription_status' => 'subscribed', 'created_at' => '2025-12-01 09:15:33', 'updated_at' => '2025-12-01 11:22:47', ], 'list' => [ 'id' => 7, 'name' => 'Weekly Newsletter Subscribers', 'description' => 'Subscribers who opted in for weekly newsletter updates', 'created_at' => '2025-12-01 10:15:23', 'updated_at' => '2025-12-01 15:30:45', ], ]; $context['response_type'] = 'sample'; } break; case 'tag_created': $recent_tag = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}mailerpress_tags LIMIT 1" ); if ( $recent_tag ) { $context['pluggable_data'] = [ 'tag_id' => $recent_tag->tag_id, 'name' => $recent_tag->name, ]; $context['response_type'] = 'live'; } else { $context['pluggable_data'] = [ 'tag_id' => 8, 'name' => 'VIP Customers', ]; $context['response_type'] = 'sample'; } break; case 'mailerpress_tag_added_to_contact_data': $recent_contact = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}mailerpress_contact ORDER BY created_at DESC LIMIT 1" ); $recent_tag = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}mailerpress_tags LIMIT 1" ); if ( $recent_contact && $recent_tag ) { $user_data = get_userdata( 1 ); $context['pluggable_data'] = [ 'contact' => [ 'id' => $recent_contact->contact_id, 'email' => $recent_contact->email, 'first_name' => $recent_contact->first_name, 'last_name' => $recent_contact->last_name, 'subscription_status' => $recent_contact->subscription_status, 'created_at' => $recent_contact->created_at, 'updated_at' => $recent_contact->updated_at, ], 'tag' => [ 'id' => $recent_tag->tag_id, 'name' => $recent_tag->name, ], ]; $context['response_type'] = 'live'; } else { $context['pluggable_data'] = [ 'contact' => [ 'id' => 18, 'email' => 'emma.wilson@startup.io', 'first_name' => 'Emma', 'last_name' => 'Wilson', 'subscription_status' => 'subscribed', 'created_at' => '2025-12-01 13:45:12', 'updated_at' => '2025-12-01 16:18:35', ], 'tag' => [ 'id' => 5, 'name' => 'Premium Member', ], ]; $context['response_type'] = 'sample'; } break; case 'campaign_created': $recent_campaign = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}mailerpress_campaigns ORDER BY created_at DESC LIMIT 1" ); if ( $recent_campaign ) { $user_data = get_userdata( 1 ); $context['pluggable_data'] = [ 'wp_user_id' => $user_data ? $user_data->ID : 1, 'user_login' => $user_data ? $user_data->user_login : 'root', 'display_name' => $user_data ? $user_data->display_name : 'Arian', 'user_firstname' => get_user_meta( $user_data ? $user_data->ID : 1, 'first_name', true ) ? get_user_meta( $user_data ? $user_data->ID : 1, 'first_name', true ) : '', 'user_lastname' => get_user_meta( $user_data ? $user_data->ID : 1, 'last_name', true ) ? get_user_meta( $user_data ? $user_data->ID : 1, 'last_name', true ) : '', 'user_email' => $user_data ? $user_data->user_email : 'dev-email@wpengine.local', 'user_registered' => $user_data ? $user_data->user_registered : '2025-07-02 10:50:38', 'user_role' => $user_data ? $user_data->roles : [ 'administrator' ], 'campaign' => [ 'campaign_id' => $recent_campaign->campaign_id, 'name' => $recent_campaign->name, 'subject' => $recent_campaign->subject, 'status' => $recent_campaign->status, 'type' => $recent_campaign->type, 'created_at' => $recent_campaign->created_at, 'updated_at' => $recent_campaign->updated_at, ], ]; $context['response_type'] = 'live'; } else { $user_data = get_userdata( 1 ); $context['pluggable_data'] = [ 'wp_user_id' => $user_data ? $user_data->ID : 1, 'user_login' => $user_data ? $user_data->user_login : 'root', 'display_name' => $user_data ? $user_data->display_name : 'Arian', 'user_firstname' => get_user_meta( $user_data ? $user_data->ID : 1, 'first_name', true ) ? get_user_meta( $user_data ? $user_data->ID : 1, 'first_name', true ) : '', 'user_lastname' => get_user_meta( $user_data ? $user_data->ID : 1, 'last_name', true ) ? get_user_meta( $user_data ? $user_data->ID : 1, 'last_name', true ) : '', 'user_email' => $user_data ? $user_data->user_email : 'dev-email@wpengine.local', 'user_registered' => $user_data ? $user_data->user_registered : '2025-07-02 10:50:38', 'user_role' => $user_data ? $user_data->roles : [ 'administrator' ], 'campaign' => [ 'campaign_id' => 23, 'name' => 'Holiday Special Offer 2025', 'subject' => 'Exclusive 30% OFF - Limited Time Holiday Deal!', 'status' => 'draft', 'type' => 'newsletter', 'created_at' => '2025-12-01 16:45:22', 'updated_at' => '2025-12-01 17:12:38', ], ]; $context['response_type'] = 'sample'; } break; } return $context; } /** * Get WPCafe Branch List. * * @param array $data data. * * @return array */ public function search_wpcafe_branch_list( $data ) { $options = []; if ( ! class_exists( 'WpCafe\Models\Location_Model' ) ) { return [ 'options' => $options, 'hasMore' => false, ]; } $locations = \WpCafe\Models\Location_Model::all(); if ( ! empty( $locations ) ) { foreach ( $locations as $location ) { $options[] = [ 'label' => $location->restaurant_name, 'value' => $location->term_id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Kadence Forms. * * @param array $data data. * @return array */ public function search_kadence_forms( $data ) { $options = []; $args = [ 'post_type' => 'kadence_form', 'post_status' => 'publish', 'numberposts' => -1, ]; $forms = get_posts( $args ); if ( ! empty( $forms ) ) { foreach ( $forms as $form ) { $options[] = [ 'label' => $form->post_title, 'value' => $form->ID, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Advanced Forms for ACF forms. * * @param array $data Search Params. * * @return array */ public function search_advanced_forms( $data ) { if ( ! function_exists( 'af' ) ) { return [ 'options' => [], 'hasMore' => false, ]; } $forms = get_posts( [ 'post_type' => 'af_form', 'post_status' => 'publish', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC', ] ); $options = []; if ( ! empty( $forms ) ) { foreach ( $forms as $form ) { $options[] = [ 'label' => $form->post_title, 'value' => $form->post_name, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Code Snippets list. * * @param array $data data. * * @return array */ public function search_code_snippets_list( $data ) { $options = []; if ( ! function_exists( 'Code_Snippets\get_snippets' ) ) { return [ 'options' => $options, 'hasMore' => false, ]; } $all_snippets = \Code_Snippets\get_snippets(); $search_term = isset( $data['search_term'] ) ? strtolower( $data['search_term'] ) : ''; foreach ( $all_snippets as $snippet ) { if ( ! is_object( $snippet ) || empty( $snippet->id ) ) { continue; } $name = isset( $snippet->name ) ? $snippet->name : ''; if ( ! empty( $search_term ) && false === strpos( strtolower( $name ), $search_term ) ) { continue; } $options[] = [ 'label' => $name, 'value' => (string) $snippet->id, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get CLUEVO LMS learning structure items list. * * Returns all items from the CLUEVO tree table (courses, chapters, modules) * with pagination and optional name/path filtering. Item IDs from this list * are used by the Assign User to Course action. * * @param array $data Search params: page, term. * @return array */ public function search_cluevo_lms_items( $data ) { if ( ! function_exists( 'cluevo_get_lms_item_list' ) ) { return []; } $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $term = isset( $data['term'] ) ? strtolower( trim( (string) $data['term'] ) ) : ''; $all_items = cluevo_get_lms_item_list(); if ( empty( $all_items ) || ! is_array( $all_items ) ) { return [ 'options' => [], 'hasMore' => false, ]; } if ( ! empty( $term ) ) { $all_items = array_values( array_filter( $all_items, function ( $item ) use ( $term ) { return strpos( strtolower( (string) $item->name ), $term ) !== false || strpos( strtolower( (string) $item->path ), $term ) !== false; } ) ); } $total = count( $all_items ); $page_items = array_slice( $all_items, $offset, $limit ); $options = []; foreach ( $page_items as $item ) { $label = ! empty( $item->path ) ? rtrim( (string) $item->path, '/' ) : (string) $item->name; $options[] = [ 'label' => $label, 'value' => $item->item_id, ]; } return [ 'options' => $options, 'hasMore' => $total > ( $offset + $limit ), ]; } /** * Get Groups by itthinx — list groups from the custom groups table. * * @param array $data data. * @return array */ public function search_groups_itthinx_groups( $data ) { global $wpdb; if ( ! class_exists( 'Groups_Group' ) ) { return [ 'options' => [], 'hasMore' => false, ]; } $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $search_term = isset( $data['search_term'] ) ? sanitize_text_field( $data['search_term'] ) : ''; $group_table = $wpdb->prefix . 'groups_group'; //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared if ( ! empty( $search_term ) ) { $like = '%' . $wpdb->esc_like( $search_term ) . '%'; $results = $wpdb->get_results( $wpdb->prepare( "SELECT group_id, name FROM {$group_table} WHERE name LIKE %s ORDER BY name ASC LIMIT %d OFFSET %d", $like, $limit, $offset ) ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $total = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$group_table} WHERE name LIKE %s", $like ) ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared } else { $results = $wpdb->get_results( $wpdb->prepare( "SELECT group_id, name FROM {$group_table} ORDER BY name ASC LIMIT %d OFFSET %d", $limit, $offset ) ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $total = $wpdb->get_var( "SELECT COUNT(*) FROM {$group_table}" ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared } $options = []; if ( ! empty( $results ) ) { foreach ( $results as $group ) { $options[] = [ 'label' => is_string( $group->name ) ? $group->name : '', 'value' => $group->group_id, ]; } } $total = is_numeric( $total ) ? (int) $total : 0; return [ 'options' => $options, 'hasMore' => $total > ( $offset + $limit ), ]; } /** * Search Bricksforge Pro Forms. * * Scans all Bricks-built posts/templates for Pro Forms elements * (name: brf-pro-forms) and returns each form's element ID as the value. * The element ID is the formId sent by the frontend on submission. * * @param array $data data. * @return array */ public function search_bricksforge_pro_forms( $data ) { $options = []; if ( ! class_exists( 'Bricksforge\BricksForge' ) ) { return [ 'options' => $options, 'hasMore' => false, ]; } if ( ! defined( 'BRICKS_DB_PAGE_CONTENT' ) || ! defined( 'BRICKS_DB_GLOBAL_SETTINGS' ) ) { return [ 'options' => $options, 'hasMore' => false, ]; } // Respect the post types configured for Bricks. $bricks_settings = (array) get_option( BRICKS_DB_GLOBAL_SETTINGS ); if ( array_key_exists( 'postTypes', $bricks_settings ) && is_array( $bricks_settings['postTypes'] ) ) { $post_types = $bricks_settings['postTypes']; } else { $post_types = []; } $post_types[] = 'bricks_template'; $args = [ 'post_type' => $post_types, 'post_status' => 'publish', 'posts_per_page' => -1, ]; $posts = get_posts( $args ); foreach ( $posts as $post ) { $elements = get_post_meta( $post->ID, BRICKS_DB_PAGE_CONTENT, true ); if ( ! is_array( $elements ) ) { continue; } foreach ( $elements as $element ) { if ( ! is_array( $element ) || ! isset( $element['name'] ) || ! isset( $element['id'] ) ) { continue; } if ( 'brf-pro-forms' === $element['name'] ) { $form_label = $post->post_title . ' - Pro Form (ID: ' . $element['id'] . ')'; $options[] = [ 'label' => $form_label, 'value' => $element['id'], ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } } GlobalSearchController::get_instance();