leuser', '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 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, ]; } } GlobalSearchController::get_instance();