tail ); } $context = array_merge( WordPress::get_user_context( $result_user_id ), $course_detail ); } break; default: return; } $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } return $context; } /** * Get WooCommerce Order Note list. * * @param array $data data. * * @return array */ public function search_note_type_list( $data ) { $options = []; $options[] = [ 'label' => 'Customer', 'value' => 'customer', ]; $options[] = [ 'label' => 'Private', 'value' => 'internal', ]; return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get last data for trigger * * @param array $data data. * @return array */ public function search_woo_commerce_customers_triggers_last_data( $data ) { $context = []; $context['response_type'] = 'sample'; $context['pluggable_data'] = []; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; global $wpdb; if ( 'customer_created' === $term ) { $customer_query = get_users( [ 'fields' => 'ID', 'role' => 'customer', 'orderby' => 'ID', 'order' => 'DESC', 'number' => 1, ] ); $results = $customer_query; if ( ! empty( $results ) ) { $customer = new WC_Customer( $results[0] ); $last_order = $customer->get_last_order(); $customer_data = [ 'id' => $customer->get_id(), 'email' => $customer->get_email(), 'first_name' => $customer->get_first_name(), 'last_name' => $customer->get_last_name(), 'username' => $customer->get_username(), 'last_order_id' => is_object( $last_order ) ? $last_order->get_id() : null, 'orders_count' => $customer->get_order_count(), 'total_spent' => wc_format_decimal( $customer->get_total_spent(), 2 ), 'avatar_url' => $customer->get_avatar_url(), 'billing_address' => [ 'first_name' => $customer->get_billing_first_name(), 'last_name' => $customer->get_billing_last_name(), 'company' => $customer->get_billing_company(), 'address_1' => $customer->get_billing_address_1(), 'address_2' => $customer->get_billing_address_2(), 'city' => $customer->get_billing_city(), 'state' => $customer->get_billing_state(), 'postcode' => $customer->get_billing_postcode(), 'country' => $customer->get_billing_country(), 'email' => $customer->get_billing_email(), 'phone' => $customer->get_billing_phone(), ], 'shipping_address' => [ 'first_name' => $customer->get_shipping_first_name(), 'last_name' => $customer->get_shipping_last_name(), 'company' => $customer->get_shipping_company(), 'address_1' => $customer->get_shipping_address_1(), 'address_2' => $customer->get_shipping_address_2(), 'city' => $customer->get_shipping_city(), 'state' => $customer->get_shipping_state(), 'postcode' => $customer->get_shipping_postcode(), 'country' => $customer->get_shipping_country(), ], ]; if ( is_object( $last_order ) && method_exists( $last_order, 'get_date_created' ) ) { $created_date = $last_order->get_date_created(); if ( is_object( $created_date ) && method_exists( $created_date, 'getTimestamp' ) ) { $last_order_date = $created_date->getTimestamp(); $customer_data['created_at'] = $last_order_date; $customer_data['last_order_date'] = $last_order_date; } } $order_sample_data = $customer_data; $context['response_type'] = 'live'; $context['pluggable_data'] = $order_sample_data; } else { $order_sample_data = json_decode( '{"id": 158,"email": "johnd@d.com","first_name": "john","last_name": "d","username": "johnd","last_order_id": 6604,"orders_count": 3,"total_spent": "45.00","avatar_url": "https:\/\/secure.gravatar.com\/avatar\/0f9c8dc78cff3ea4d447b2297c8f6803?s=96&d=mm&r=g","billing_address": {"first_name": "john","last_name": "d","company": "","address_1": "","address_2": "","city": "London","state": "TN","postcode": "PV1 QW2","country": "UK","email": "johnd@d.com","phone": "9878988766"},"shipping_address": {"first_name": "","last_name": "","company": "","address_1": "","address_2": "","city": "","state": "","postcode": "","country": ""},"created_at": 1697631243,"last_order_date": 1697631243}', true ); $context['pluggable_data'] = $order_sample_data; } } elseif ( 'total_spend_reach' === $term ) { $total_spend_selected = isset( $data['filter']['total_spend']['value'] ) ? $data['filter']['total_spend']['value'] : ''; $customers = $wpdb->get_col( "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = '_customer_user' AND meta_value > 0" ); $target_customer = null; foreach ( $customers as $customer ) { $total_spend = (int) wc_get_customer_total_spent( $customer ); if ( $total_spend == $total_spend_selected ) { $target_customer = $customer; break; // Exit the loop once a matching customer is found. } } if ( $target_customer ) { $new_customer = new WC_Customer( $target_customer ); $new_customer_data = [ 'id' => $new_customer->get_id(), 'email' => $new_customer->get_email(), 'first_name' => $new_customer->get_first_name(), 'last_name' => $new_customer->get_last_name(), 'username' => $new_customer->get_username(), 'order_count' => $new_customer->get_order_count(), 'total_spend' => wc_format_decimal( $new_customer->get_total_spent(), 2 ), ]; $context['response_type'] = 'live'; $context['pluggable_data'] = $new_customer_data; } else { $sample_customer_data = [ 'id' => '101', 'created_at' => '1680675247', 'email' => 'john@d.com', 'first_name' => 'John', 'last_name' => 'D', 'username' => 'johnd', 'order_count' => '3', 'total_spend' => '22.00', ]; $context['pluggable_data'] = $sample_customer_data; } } elseif ( 'order_count_reach' === $term ) { $total_order_selected = isset( $data['filter']['order_count']['value'] ) ? $data['filter']['order_count']['value'] : ''; $customers = $wpdb->get_col( "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = '_customer_user' AND meta_value > 0" ); $target_customer = null; foreach ( $customers as $customer ) { $args = [ 'customer_id' => $customer, 'limit' => -1, 'status' => [ 'wc-completed' ], ]; $orders = wc_get_orders( $args ); if ( ! empty( $orders ) ) { $total_order = (int) wc_get_customer_order_count( $customer ); if ( $total_order == $total_order_selected ) { $target_customer = $customer; break; // Exit the loop once a matching customer is found. } } } if ( $target_customer ) { $new_customer = new WC_Customer( $target_customer ); $new_customer_data = [ 'id' => $new_customer->get_id(), 'email' => $new_customer->get_email(), 'first_name' => $new_customer->get_first_name(), 'last_name' => $new_customer->get_last_name(), 'username' => $new_customer->get_username(), 'order_count' => $new_customer->get_order_count(), ]; $context['response_type'] = 'live'; $context['pluggable_data'] = $new_customer_data; } else { $sample_customer_data = [ 'id' => '101', 'created_at' => '1680675247', 'email' => 'john@d.com', 'first_name' => 'John', 'last_name' => 'D', 'username' => 'johnd', 'orders_count' => '3', ]; $context['pluggable_data'] = $sample_customer_data; } } return $context; } /** * Get Affiliate list * * @param array $data data. * * @return array */ public function search_affiliate_list( $data ) { $options = []; $args = [ 'meta_query' => [ [ 'key' => 'wafp_is_affiliate', 'value' => '1', 'compare' => '=', ], ], ]; $affiliates = get_users( $args ); foreach ( $affiliates as $user ) { $options[] = [ 'label' => $user->display_name, 'value' => $user->ID, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Affiliate Source list * * @param array $data data. * * @return array */ public function search_affiliate_transaction_source_list( $data ) { $options = []; $sources = [ 'General', 'MemberPress', 'WooCommerce', 'Easy Digital Downloads', 'WPForms', 'Formidable', 'PayPal', ]; foreach ( $sources as $source ) { $options[] = [ 'label' => $source, 'value' => str_replace( ' ', '_', strtolower( $source ) ), ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Easy Affiliate data. * * @param array $data data. * @return array|void */ public function search_easy_affiliate_last_data( $data ) { global $wpdb; $trigger = $data['search_term']; $context = []; if ( 'sale_recorded' === $trigger ) { $affiliate_id = $data['filter']['affiliate_id']['value']; if ( -1 === $affiliate_id ) { $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wafp_transactions as postmeta JOIN {$wpdb->prefix}wafp_events as posts ON posts.evt_id=postmeta.id WHERE postmeta.status='complete' order by postmeta.id DESC LIMIT 1" ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wafp_transactions as postmeta JOIN {$wpdb->prefix}wafp_events as posts ON posts.evt_id=postmeta.id WHERE postmeta.status='complete' AND affiliate_id=%d order by postmeta.id DESC LIMIT 1", $affiliate_id ) ); } } elseif ( 'sale_added' === $trigger ) { $orderby = 'signup_date'; $order = 'DESC'; $paged = 1; $search = ''; $perpage = 1; /** * * Ignore line * * @phpstan-ignore-next-line */ $result = \EasyAffiliate\Models\User::affiliate_list_table( $orderby, $order, $paged, $search, $perpage ); if ( empty( $result['results'] ) ) { $result = []; } } elseif ( 'payout_made' === $trigger ) { $affiliate_id = $data['filter']['affiliate_id']['value']; if ( -1 === $affiliate_id ) { $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wafp_payments as postmeta JOIN {$wpdb->prefix}wafp_events as posts ON posts.evt_id=postmeta.id WHERE postmeta.amount>0 order by postmeta.id DESC LIMIT 1" ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wafp_payments as postmeta JOIN {$wpdb->prefix}wafp_events as posts ON posts.evt_id=postmeta.id WHERE postmeta.amount>0 AND affiliate_id=%d order by postmeta.id DESC LIMIT 1", $affiliate_id ) ); } } if ( ! empty( $result ) ) { switch ( $trigger ) { case 'sale_recorded': $result_affiliate_id = $result[0]->affiliate_id; /** * * Ignore line * * @phpstan-ignore-next-line */ $affiliate = \EasyAffiliate\Lib\ModelFactory::fetch( $result[0]->evt_id_type, $result[0]->evt_id ); $affiliate = get_object_vars( $affiliate->rec ); $context = array_merge( WordPress::get_user_context( $result_affiliate_id ), $affiliate ); break; case 'sale_added': /** * * Ignore line * * @phpstan-ignore-next-line */ $data = new \EasyAffiliate\Models\User( $result['results'][0]->ID ); /** * * Ignore line * * @phpstan-ignore-next-line */ $context = get_object_vars( $data->rec ); break; case 'payout_made': $result_affiliate_id = $result[0]->affiliate_id; /** * * Ignore line * * @phpstan-ignore-next-line */ $affiliate = \EasyAffiliate\Lib\ModelFactory::fetch( $result[0]->evt_id_type, $result[0]->evt_id ); $affiliate = get_object_vars( $affiliate->rec ); $context = array_merge( WordPress::get_user_context( $result_affiliate_id ), $affiliate ); break; default: return; } $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } elseif ( empty( $result ) ) { switch ( $trigger ) { case 'sale_added': $context = json_decode( '{"ID": 1,"first_name": "John","last_name": "D","user_login": "johnd","user_nicename": "johnd","user_email": "johnd@d.com","user_url": "","user_registered": "2023-10-13 13:39:16","user_activation_key": "","user_status": "0","display_name": "johnd","paypal_email": "johnd@d.com","address_one": "1street","address_two": "", "city": "london","state": "","zip": "","country": "UK","tax_id_us": "","tax_id_int": "","is_affiliate": "1","is_blocked": "","blocked_message": "","referrer": "0","notes": "","unsubscribed": ""}', true ); break; case 'sale_recorded': $context = json_decode( '{"wp_user_id": 73,"user_login": "johnd@yopmail.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["subscriber"],"id": "5","affiliate_id": "73","click_id": "0","item_id": "","item_name": "test","coupon": "","sale_amount": "10.00","refund_amount": "20.00","subscr_id": "","subscr_paynum": "0","ip_addr": "","cust_email": "","cust_name": "","trans_num": "test5","type": "commission","source": "general","order_id": "0","status": "complete","rebill": "0","created_at": "2023-10-11 09:18:41"}', true ); break; case 'payout_made': $context = json_decode( '{"wp_user_id": 73,"user_login": "johnd@yopmail.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["subscriber"],"id": "5","affiliate_id": "73","click_id": "0","item_id": "","item_name": "test","coupon": "","sale_amount": "10.00","refund_amount": "20.00","subscr_id": "","subscr_paynum": "0","ip_addr": "","cust_email": "","cust_name": "","trans_num": "test5","type": "commission","source": "general","order_id": "0","status": "complete","rebill": "0","created_at": "2023-10-11 09:18:41"}', true ); break; default: return; } $context['pluggable_data'] = $context; $context['response_type'] = 'sample'; } return $context; } /** * Get WooCommerce Subscriptions Coupon list * * @param array $data data. * * @return array */ public function search_woo_subscription_coupon_list( $data ) { $options = []; $coupon_codes = []; $query = new \WP_Query( [ 'post_type' => 'shop_coupon', 'posts_per_page' => -1, 'no_found_rows' => true, 'meta_query' => [ [ 'key' => '_is_aw_coupon', 'compare' => 'NOT EXISTS', ], ], ] ); foreach ( $query->posts as $coupon ) { /** * * Ignore line * * @phpstan-ignore-next-line */ $code = wc_format_coupon_code( $coupon->post_title ); $coupon_codes[ $code ] = $code; } foreach ( $coupon_codes as $code ) { $coupon = new \WC_Coupon( $code ); if ( ! in_array( $coupon->get_discount_type(), [ 'recurring_fee', 'recurring_percent' ], true ) ) { unset( $coupon_codes[ $code ] ); } } if ( ! empty( $coupon_codes ) ) { if ( is_array( $coupon_codes ) ) { foreach ( $coupon_codes as $coupon_code ) { $options[] = [ 'label' => $coupon_code, 'value' => $coupon_code, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get BuddyBoss field. * * @param array $data data. * * @return array|void */ public function search_bb_field_list( $data ) { global $wpdb; $options = []; $xprofile_fields = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_xprofile_fields WHERE parent_id = 0 ORDER BY field_order ASC" ); if ( ! empty( $xprofile_fields ) ) { foreach ( $xprofile_fields as $xprofile_field ) { $options[] = [ 'label' => $xprofile_field->name, 'value' => $xprofile_field->id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Woocommerce Bookings Product List. * * @param array $data data. * * @return array|void */ public function search_wb_bookable_product_list( $data ) { $options = []; if ( ! class_exists( 'WC_Bookings_Admin' ) ) { return; } $products = WC_Bookings_Admin::get_booking_products(); if ( ! empty( $products ) ) { if ( is_array( $products ) ) { foreach ( $products as $product ) { $options[] = [ 'label' => $product->get_name(), 'value' => $product->get_id(), ]; $resources = $product->get_resources(); if ( ! empty( $resources ) ) { foreach ( $resources as $resource ) { $options[] = [ 'label' => $resource->get_name(), 'value' => $resource->get_id(), ]; } } } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get last data for WooCommerce Booking trigger * * @param array $data data. * @return array */ public function search_woo_commerce_booking_last_data( $data ) { $context = []; $context['response_type'] = 'sample'; $context['pluggable_data'] = []; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; global $wpdb; if ( 'booking_created' === $term ) { $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type='wc_booking' AND post_status='confirmed' order by ID DESC LIMIT 1" ); if ( ! empty( $results ) ) { if ( class_exists( 'WC_Booking' ) ) { $booking = new WC_Booking( $results[0]->ID ); $person_counts = $booking->get_person_counts(); $bookable_product_id = $booking->get_product_id(); if ( method_exists( $booking, 'get_data' ) ) { $booking = $booking->get_data(); $booking['start'] = gmdate( 'Y-m-d H:i:s', $booking['start'] ); $booking['end'] = gmdate( 'Y-m-d H:i:s', $booking['end'] ); if ( ! empty( $person_counts ) ) { $total_count = 0; foreach ( $person_counts as $key => $value ) { $total_count += $value; } $booking['total_person_counts'] = $total_count; } $booking['bookable_product'] = $bookable_product_id; $context['response_type'] = 'live'; $context['pluggable_data'] = array_merge( $booking, WordPress::get_user_context( $booking['customer_id'] ) ); } } } else { $booking_sample_data = json_decode( '{"id": 6546,"all_day": false,"cost": "45.02","customer_id": 1,"date_created": 1696915500,"date_modified": 1696915863,"end": "2023-10-14 12:00:00","google_calendar_event_id": "0","order_id": 0,"order_item_id": 0,"parent_id": 0,"person_counts": {"6525": 1,"6526": 1},"product_id": 6527,"resource_id": 0,"start": "2023-10-14 10:00:00","status": "confirmed","local_timezone": "","meta_data": [{"id": 12163,"key": "_booking_all_day","value": "0"},{"id": 12164,"key": "_booking_cost","value": "45.02"},{"id": 12165,"key": "_booking_customer_id","value": "1"},{"id": 12166,"key": "_booking_order_item_id","value": "0"},{"id": 12167,"key": "_booking_parent_id","value": "0"},{"id": 12168,"key": "_booking_persons","value": {"6525": 1,"6526": 1}},{"id": 12169,"key": "_booking_product_id","value": "6527"},{"id": 12170,"key": "_booking_resource_id","value": "0"},{"id": 12171,"key": "_booking_start","value": "20231014100000"},{"id": 12172,"key": "_booking_end","value": "20231014120000"},{"id": 12173,"key": "_wc_bookings_gcalendar_event_id","value": "0"},{"id": 12175,"key": "_edit_lock","value": "1696915725:1"},{"id": 12176,"key": "_edit_last","value": "1"}],"total_person_counts": 2,"bookable_product": 6527,"wp_user_id": 1,"user_login": "johnd@yopmail.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["customer"]}', true ); $context['pluggable_data'] = $booking_sample_data; } } elseif ( 'booking_status_changed' === $term ) { $to_status = isset( $data['filter']['to_status']['value'] ) ? $data['filter']['to_status']['value'] : -1; if ( -1 == $to_status ) { $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type='wc_booking' order by ID DESC LIMIT 1" ); } else { $results = $wpdb->get_results( $wpdb->prepare( " SELECT * FROM {$wpdb->prefix}posts WHERE `post_status` = %s AND `post_type` LIKE %s ", $to_status, 'wc_booking' ) ); } if ( ! empty( $results ) ) { if ( class_exists( 'WC_Booking' ) ) { $booking = new WC_Booking( $results[0]->ID ); $person_counts = $booking->get_person_counts(); $bookable_product_id = $booking->get_product_id(); if ( method_exists( $booking, 'get_data' ) ) { $booking = $booking->get_data(); $booking['start'] = gmdate( 'Y-m-d H:i:s', $booking['start'] ); $booking['end'] = gmdate( 'Y-m-d H:i:s', $booking['end'] ); if ( ! empty( $person_counts ) ) { $total_count = 0; foreach ( $person_counts as $key => $value ) { $total_count += $value; } $booking['total_person_counts'] = $total_count; } $booking['bookable_product'] = $bookable_product_id; $booking['from_status'] = $data['filter']['from_status']['value']; $booking['to_status'] = $booking['status']; $context['response_type'] = 'live'; $context['pluggable_data'] = array_merge( $booking, WordPress::get_user_context( $booking['customer_id'] ) ); } } } else { $booking_sample_data = json_decode( '{"id": 6546,"all_day": false,"cost": "45.02","customer_id": 1,"date_created": 1696915500,"date_modified": 1696915863,"end": "2023-10-14 12:00:00","google_calendar_event_id": "0","order_id": 0,"order_item_id": 0,"parent_id": 0,"person_counts": {"6525": 1,"6526": 1},"product_id": 6527,"resource_id": 0,"start": "2023-10-14 10:00:00","status": "confirmed","to_status": "confirmed","from_status": "cancelled","local_timezone": "","meta_data": [{"id": 12163,"key": "_booking_all_day","value": "0"},{"id": 12164,"key": "_booking_cost","value": "45.02"},{"id": 12165,"key": "_booking_customer_id","value": "1"},{"id": 12166,"key": "_booking_order_item_id","value": "0"},{"id": 12167,"key": "_booking_parent_id","value": "0"},{"id": 12168,"key": "_booking_persons","value": {"6525": 1,"6526": 1}},{"id": 12169,"key": "_booking_product_id","value": "6527"},{"id": 12170,"key": "_booking_resource_id","value": "0"},{"id": 12171,"key": "_booking_start","value": "20231014100000"},{"id": 12172,"key": "_booking_end","value": "20231014120000"},{"id": 12173,"key": "_wc_bookings_gcalendar_event_id","value": "0"},{"id": 12175,"key": "_edit_lock","value": "1696915725:1"},{"id": 12176,"key": "_edit_last","value": "1"}],"total_person_counts": 2,"bookable_product": 6527,"wp_user_id": 1,"user_login": "johnd@yopmail.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["customer"]}', true ); $context['pluggable_data'] = $booking_sample_data; } } return $context; } /** * Get WooCommerce Booking status list. * * @param array $data data. * * @return array */ public function search_woo_booking_status_list( $data ) { $options = [ [ 'label' => 'Pending Confirmation', 'value' => 'pending-confirmation', ], [ 'label' => 'Unpaid', 'value' => 'unpaid', ], [ 'label' => 'Confirmed', 'value' => 'confirmed', ], [ 'label' => 'Paid', 'value' => 'paid', ], [ 'label' => 'Complete', 'value' => 'complete', ], [ 'label' => 'In Cart', 'value' => 'in-cart', ], [ 'label' => 'Cancelled', 'value' => 'cancelled', ], ]; return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Woocommerce Memberships Status List. * * @param array $data data. * * @return array|void */ public function search_wc_membership_status_list( $data ) { $options = []; if ( ! function_exists( 'wc_memberships_get_user_membership_statuses' ) ) { return; } $statuses = wc_memberships_get_user_membership_statuses(); if ( ! empty( $statuses ) ) { if ( is_array( $statuses ) ) { foreach ( $statuses as $status => $value ) { $status = 0 === strpos( $status, 'wcm-' ) ? substr( $status, 4 ) : $status; $options[] = [ 'label' => $value['label'], 'value' => $status, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Woocommerce Subscription data. * * @param array $data data. * @return array|void */ public function search_user_subscription_last_data( $data ) { $context = []; if ( ! class_exists( 'WC_Subscription' ) || ! function_exists( 'wcs_get_subscription' ) || ! function_exists( 'wcs_get_subscriptions_for_product' ) || ! function_exists( 'wcs_order_contains_renewal' ) || ! function_exists( 'wcs_get_subscriptions_for_order' ) ) { return; } if ( 'trial_end' == $data['search_term'] ) { $subscription_id = $data['filter']['subscription']['value']; $query_args = [ 'post_type' => 'shop_subscription', 'orderby' => 'ID', 'order' => 'DESC', 'post_status' => 'wc-active', 'posts_per_page' => 1, 'meta_query' => [ [ 'key' => '_schedule_trial_end', 'value' => gmdate( 'Y-m-d H:i:s' ), 'compare' => '<=', ], ], 'post__in' => [ $subscription_id ], ]; $query_result = new WP_Query( $query_args ); $subscription_orders = $query_result->get_posts(); if ( ! empty( $subscription_orders ) ) { /** * * Ignore line * * @phpstan-ignore-next-line */ $subscription = wcs_get_subscription( $subscription_orders[0]->ID ); $user_id = $subscription->get_user_id(); $items = $subscription->get_items(); $product_ids = []; foreach ( $items as $item ) { $product_ids[] = $item->get_product_id(); } $subscription_status = $subscription->get_status(); $subscription_start_date = $subscription->get_date_created(); $context['subscription_data'] = [ 'status' => $subscription_status, 'start_date' => $subscription_start_date, 'trial_end_date' => $subscription->get_date( 'schedule_trial_end' ), 'next_payment_date' => $subscription->get_date( 'next_payment' ), 'end_date' => $subscription->get_date( 'schedule_end' ), ]; $context['user'] = WordPress::get_user_context( $user_id ); foreach ( $product_ids as $val ) { $context['subscription'] = $val; $context['subscription_name'] = get_the_title( $val ); } $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $context = json_decode( '{"subscription_data": {"status": "active","start_date": {"date": "2023-05-18 12:36:53.000000","timezone_type": 1,"timezone": "+00:00"},"trial_end_date": "2023-10-20 03:31:04","next_payment_date": 0,"end_date": "2024-05-28 12:36:53"},"user": {"wp_user_id": 1,"user_login": "john@d.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "john@d.com","user_role": ["customer","subscriber"]},"subscription": 5861,"subscription_name": "Demo Subscription"}', true ); $context['pluggable_data'] = $context; $context['response_type'] = 'sample'; } } elseif ( 'renewal_payment_failed' == $data['search_term'] ) { $subscription_item = $data['filter']['subscription_item']['value']; $subscription_ids = wcs_get_subscriptions_for_product( $subscription_item ); $ids = []; $related = []; foreach ( $subscription_ids as $subscription ) { $ids[] = $subscription; $subscriptions = new WC_Subscription( $subscription ); $related[] = $subscriptions->get_related_orders(); } $failed_payment_orders = []; foreach ( $related as $value ) { foreach ( $value as $val ) { if ( wcs_order_contains_renewal( $val ) ) { $order = wc_get_order( $val ); if ( $order ) { /** * * Ignore line * * @phpstan-ignore-next-line */ $payment_status = $order->get_status(); if ( 'failed' === $payment_status || 'wc-on-hold' === $payment_status ) { $failed_payment_orders[] = $val; } } } } } if ( ! empty( $failed_payment_orders ) ) { $failed = array_rand( $failed_payment_orders ); $related_subscriptions = wcs_get_subscriptions_for_order( $failed_payment_orders[ $failed ] ); if ( ! empty( $related_subscriptions ) ) { $sub_id = get_post_meta( $failed_payment_orders[ $failed ], '_subscription_renewal', true ); $subscription = wcs_get_subscription( $sub_id ); $items = $subscription->get_items(); $product_ids = []; foreach ( $items as $item ) { $product_ids[] = $item->get_product_id(); } $context['user'] = WordPress::get_user_context( $subscription->get_user_id() ); foreach ( [ 'renewal' ] as $order_type ) { foreach ( $subscription->get_related_orders( 'ids', $order_type ) as $order_id ) { $context['subscription_related_order'][] = $order_id; } } foreach ( $product_ids as $val ) { $context['subscription_item'] = $val; $context['subscription_name'] = get_the_title( $val ); } $context['data'] = $subscription->get_data(); $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $context['pluggable_data'] = json_decode( '{"user": {"wp_user_id": 36,"user_login": "john@d.com","display_name": "test","user_firstname": "Test","user_lastname": "test","user_email": "john@d.com","user_role": ["wpamelia-customer","customer"]},"subscription_related_order": [6643],"subscription_item": 5962,"subscription_name": "Demo2 Subscription","data": {"id": 6642,"parent_id": 6641,"status": "on-hold","currency": "USD","version": "7.6.1","prices_include_tax": false,"date_created": {"date": "2023-10-20 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-20 08:45:02.000000","timezone_type": 1,"timezone": "+00:00"},"discount_total": "0","discount_tax": "0","shipping_total": "0","shipping_tax": "0","cart_tax": "0","total": "1.00","total_tax": "0","customer_id": 36,"order_key": "wc_order_6Pdirh5WDDiVA","billing": {"first_name": "bella","last_name": "test","company": "","address_1": "test","address_2": "","city": "test","state": "TN","postcode": "600144","country": "IN","email": "john@d.com","phone": "98675757"},"shipping": {"first_name": "bella","last_name": "test","company": "","address_1": "test","address_2": "","city": "Chennai","state": "TN","postcode": "600100","country": "IN","phone": ""},"payment_method": "","payment_method_title": "","transaction_id": "","customer_ip_address": "127.0.0.1","customer_user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/118.0.0.0 Safari\/537.36","created_via": "checkout","customer_note": "","date_completed": null,"date_paid": null,"cart_hash": "","order_stock_reduced": false,"download_permissions_granted": true,"new_order_email_sent": false,"recorded_sales": false,"recorded_coupon_usage_counts": false,"billing_period": "day","billing_interval": "1","suspension_count": 1,"requires_manual_renewal": true,"cancelled_email_sent": "","trial_period": "day","schedule_trial_end": {"date": "2023-10-21 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_next_payment": {"date": "2023-10-21 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_end": {"date": "2023-10-22 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_start": {"date": "2023-10-22 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"switch_data": [],"number": "6642","meta_data": [{"id": 13719,"key": "is_vat_exempt","value": "no"}],"line_items": {"142": []},"tax_lines": [],"shipping_lines": [],"fee_lines": [],"coupon_lines": []}}', true ); $context['response_type'] = 'sample'; } } else { $context['pluggable_data'] = json_decode( '{"user": {"wp_user_id": 36,"user_login": "john@d.com","display_name": "test","user_firstname": "Test","user_lastname": "test","user_email": "john@d.com","user_role": ["wpamelia-customer","customer"]},"subscription_related_order": [6643],"subscription_item": 5962,"subscription_name": "Demo2 Subscription","data": {"id": 6642,"parent_id": 6641,"status": "on-hold","currency": "USD","version": "7.6.1","prices_include_tax": false,"date_created": {"date": "2023-10-20 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-20 08:45:02.000000","timezone_type": 1,"timezone": "+00:00"},"discount_total": "0","discount_tax": "0","shipping_total": "0","shipping_tax": "0","cart_tax": "0","total": "1.00","total_tax": "0","customer_id": 36,"order_key": "wc_order_6Pdirh5WDDiVA","billing": {"first_name": "bella","last_name": "test","company": "","address_1": "test","address_2": "","city": "test","state": "TN","postcode": "600144","country": "IN","email": "john@d.com","phone": "98675757"},"shipping": {"first_name": "bella","last_name": "test","company": "","address_1": "test","address_2": "","city": "Chennai","state": "TN","postcode": "600100","country": "IN","phone": ""},"payment_method": "","payment_method_title": "","transaction_id": "","customer_ip_address": "127.0.0.1","customer_user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/118.0.0.0 Safari\/537.36","created_via": "checkout","customer_note": "","date_completed": null,"date_paid": null,"cart_hash": "","order_stock_reduced": false,"download_permissions_granted": true,"new_order_email_sent": false,"recorded_sales": false,"recorded_coupon_usage_counts": false,"billing_period": "day","billing_interval": "1","suspension_count": 1,"requires_manual_renewal": true,"cancelled_email_sent": "","trial_period": "day","schedule_trial_end": {"date": "2023-10-21 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_next_payment": {"date": "2023-10-21 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_end": {"date": "2023-10-22 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_start": {"date": "2023-10-22 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"switch_data": [],"number": "6642","meta_data": [{"id": 13719,"key": "is_vat_exempt","value": "no"}],"line_items": {"142": []},"tax_lines": [],"shipping_lines": [],"fee_lines": [],"coupon_lines": []}}', true ); $context['response_type'] = 'sample'; } } return $context; } /** * Get Masteriyo LMS Courses. * * @param array $data data. * * @return array */ public function search_masteriyo_lms_courses( $data ) { $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $args = [ 'post_type' => 'mto-course', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', ]; $courses = get_posts( $args ); $course_count = wp_count_posts( 'mto-course' )->publish; $options = []; if ( ! empty( $courses ) ) { if ( is_array( $courses ) ) { foreach ( $courses as $course ) { $options[] = [ 'label' => $course->post_title, 'value' => $course->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $course_count > $limit && $course_count > $offset, ]; } /** * Get Masteriyo LMS Lessons. * * @param array $data data. * * @return array */ public function search_masteriyo_lms_lessons( $data ) { $course_id = $data['dynamic']; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $options = []; $args = [ 'post_type' => 'mto-lesson', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', 'meta_query' => [ [ 'key' => '_course_id', 'value' => $course_id, 'compare' => '=', ], ], ]; $lessons = get_posts( $args ); $lesson_count = wp_count_posts( 'mto-lesson' )->publish; if ( ! empty( $lessons ) ) { if ( is_array( $lessons ) ) { foreach ( $lessons as $lesson ) { $options[] = [ 'label' => $lesson->post_title, 'value' => $lesson->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $lesson_count > $limit && $lesson_count > $offset, ]; } /** * Get Masteriyo LMS Quiz. * * @param array $data data. * * @return array */ public function search_masteriyo_lms_quizs( $data ) { $course_id = $data['dynamic']; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $options = []; $args = [ 'post_type' => 'mto-quiz', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', 'meta_query' => [ [ 'key' => '_course_id', 'value' => $course_id, 'compare' => '=', ], ], ]; $quizs = get_posts( $args ); $quiz_count = wp_count_posts( 'mto-quiz' )->publish; if ( ! empty( $quizs ) ) { if ( is_array( $quizs ) ) { foreach ( $quizs as $quiz ) { $options[] = [ 'label' => $quiz->post_title, 'value' => $quiz->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $quiz_count > $limit && $quiz_count > $offset, ]; } /** * Search Masteriyo LMS data. * * @param array $data data. * @return array|void|mixed */ public function search_masteriyo_lms_last_data( $data ) { global $wpdb; $post_type = $data['post_type']; $trigger = $data['search_term']; $context = []; $post_id = -1; if ( 'course_completed' === $trigger ) { $post_id = $data['filter']['course_id']['value']; } elseif ( 'lesson_completed' === $trigger ) { $post_id = $data['filter']['lesson_id']['value']; } elseif ( 'quiz_completed' === $trigger || 'quiz_failed' === $trigger ) { $post_id = $data['filter']['quiz_id']['value']; } if ( 'course_completed' === $trigger || 'lesson_completed' === $trigger ) { if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_user_activities as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.item_id WHERE postmeta.activity_status='completed' AND posts.post_type=%s order by postmeta.id DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_user_activities as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.item_id WHERE postmeta.item_id = %s AND postmeta.activity_status='completed' AND posts.post_type=%s order by postmeta.id DESC LIMIT 1", $post_id, $post_type ) ); } } if ( 'quiz_completed' === $trigger || 'quiz_failed' === $trigger ) { if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_user_activities as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.item_id WHERE postmeta.activity_status='completed' AND postmeta.activity_type='quiz' AND posts.post_type=%s order by postmeta.user_item_id DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_user_activities as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.item_id WHERE postmeta.item_id=%s AND postmeta.activity_type='quiz' OR postmeta.activity_status='completed' AND posts.post_type=%s order by postmeta.id DESC LIMIT 1", $post_id, $post_type ) ); } if ( ! empty( $result ) ) { $resultt = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_quiz_attempts WHERE quiz_id=%d AND user_id=%d order by id DESC LIMIT 1", $result[0]->item_id, $result[0]->user_id ) ); if ( function_exists( 'masteriyo_get_quiz' ) ) { $quiz = masteriyo_get_quiz( $resultt[0]->quiz_id ); if ( is_object( $quiz ) && method_exists( $quiz, 'get_pass_mark' ) ) { if ( 'quiz_completed' === $trigger && $resultt[0]->earned_marks < $quiz->get_pass_mark() ) { $result = []; } elseif ( 'quiz_failed' === $trigger && $resultt[0]->earned_marks > $quiz->get_pass_mark() ) { $result = []; } } } } } if ( ! empty( $result ) ) { $result_item_id = $result[0]->item_id; $result_user_id = $result[0]->user_id; $quiz_attempt = ''; if ( 'quiz_completed' === $trigger || 'quiz_failed' === $trigger ) { $resultt = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_quiz_attempts WHERE quiz_id=%d AND user_id=%d order by id DESC LIMIT 1", $result[0]->item_id, $result[0]->user_id ) ); $quiz_attempt = $resultt[0]->id; } switch ( $trigger ) { case 'course_completed': if ( function_exists( 'masteriyo_get_course' ) ) { $course = masteriyo_get_course( $result_item_id ); $context_data = array_merge( WordPress::get_user_context( $result_user_id ), $course->get_data() ); $context_data['course_id'] = $result_item_id; } break; case 'lesson_completed': if ( function_exists( 'masteriyo_get_lesson' ) ) { $lesson = masteriyo_get_lesson( $result_item_id ); $context_data = array_merge( WordPress::get_user_context( $result_user_id ), $lesson->get_data() ); $context_data['lesson_id'] = $result_item_id; } break; case 'quiz_completed': case 'quiz_failed': if ( function_exists( 'masteriyo_get_quiz' ) ) { $quiz = masteriyo_get_quiz( $result_item_id ); $context_data = WordPress::get_user_context( $result_user_id ); if ( function_exists( 'masteriyo_get_quiz_attempt' ) ) { $attempt = masteriyo_get_quiz_attempt( $quiz_attempt ); $context_data['quiz_id'] = $result_item_id; $context_data['course_id'] = $quiz->get_course_id(); $context_data['quiz'] = $quiz->get_data(); $context_data['attempt'] = $attempt->get_data(); } } break; default: return; } if ( ! empty( $context_data ) ) { $context['pluggable_data'] = $context_data; $context['response_type'] = 'live'; } } elseif ( empty( $result ) ) { switch ( $trigger ) { case 'course_completed': $sample_data = '{"pluggable_data":{"wp_user_id": 1,"user_login": "admin","display_name": "admin","user_firstname": "test","user_lastname": "test","user_email": "john@d.com","user_role": ["customer"],"id": 6636,"name": "Modes Master Class","slug": "modes-master-class-2","date_created": {"date": "2023-10-20 06:09:15.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-21 15:22:29.000000","timezone_type": 1,"timezone": "+00:00"},"status": "publish","menu_order": 0,"featured": false,"catalog_visibility": "visible","description": "Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words.","short_description": "","post_password": "","author_id": 1,"parent_id": 0,"reviews_allowed": true,"date_on_sale_from": null,"date_on_sale_to": null,"price": "0","regular_price": "0","sale_price": "","price_type": "free","category_ids": [106,107],"tag_ids": [],"difficulty_id": 0,"featured_image": 6616,"rating_counts": [],"average_rating": "0","review_count": 0,"enrollment_limit": 0,"duration": 360,"access_mode": "open","billing_cycle": "","show_curriculum": true,"purchase_note": "","highlights": "
this is a business course.<\/p>\n","post_title": "Business Course","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "business-course","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:27","post_modified_gmt": "2023-11-29 09:50:27","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example-wpnew.local\/course\/business-course\/","menu_order": 0,"post_type": "academy_courses","post_mime_type": "","comment_count": "0","filter": "raw"},"course": 1},"response_type":"sample"}'; break; case 'ac_lms_lesson_completed': $sample_data = '{"pluggable_data":{"ID": "1","lesson_author": "1","lesson_date": "2023-11-29 07:01:03","lesson_date_gmt": "2023-11-29 07:01:03","lesson_title": "Lesson 1","lesson_name": "","lesson_content": "","lesson_excerpt": "","lesson_status": "publish","comment_status": "close","comment_count": "0","lesson_password": "","lesson_modified": "2023-11-29 07:01:03","lesson_modified_gmt": "2023-11-29 07:01:03","wp_user_id": 73,"user_login": "abc@yopmail.com","display_name": "data data1","user_firstname": "data","user_lastname": "data1","user_email": "abc@yopmail.com","user_role": [],"course_data": {"ID": 6949,"post_author": "1","post_date": "2023-11-29 05:37:50","post_date_gmt": "2023-11-29 05:37:50","post_content": "\n
this is a business course.<\/p>\n","post_title": "Business Course","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "business-course","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:27","post_modified_gmt": "2023-11-29 09:50:27","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example-wpnew.local\/course\/business-course\/","menu_order": 0,"post_type": "academy_courses","post_mime_type": "","comment_count": "0","filter": "raw"},"lesson": 1,"course":1},"response_type":"sample"}'; break; case 'ac_lms_quiz_completed': $sample_data = '{"pluggable_data":{"wp_user_id": 73,"user_login": "abc@yopmail.com","display_name": "data data1","user_firstname": "data","user_lastname": "data1","user_email": "abc@yopmail.com","user_role": [],"quiz_data": {"ID": 6960,"post_author": "1","post_date": "2023-11-29 09:49:42","post_date_gmt": "2023-11-29 09:49:42","post_content": "","post_title": "First Quiz","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "closed","post_password": "","post_name": "first-quiz","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:11","post_modified_gmt": "2023-11-29 09:50:11","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example-wpnew.local\/?post_type=academy_quiz&p=6960","menu_order": 0,"post_type": "academy_quiz","post_mime_type": "","comment_count": "0","filter": "raw"}, "quiz_attempt_details": [{"attempt_id": "2","course_id": "6949","quiz_id": "6960","user_id": "126","total_questions": "1","total_answered_questions": "1","total_marks": "20.00","earned_marks": "20.00","attempt_info": "{\"total_correct_answers\":1}","attempt_status": "passed","attempt_ip": "127.0.0.1","attempt_started_at": "2023-11-30 06:20:10","attempt_ended_at": "2023-11-30 06:20:10","is_manually_reviewed": null,"manually_reviewed_at": null}],"quiz":1},"response_type":"sample"}'; break; case 'ac_lms_quiz_failed': $sample_data = '{"pluggable_data":{"wp_user_id": 73,"user_login": "abc@yopmail.com","display_name": "data data1","user_firstname": "data","user_lastname": "data1","user_email": "abc@yopmail.com","user_role": [],"quiz_data": {"ID": 6960,"post_author": "1","post_date": "2023-11-29 09:49:42","post_date_gmt": "2023-11-29 09:49:42","post_content": "","post_title": "First Quiz","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "closed","post_password": "","post_name": "first-quiz","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:11","post_modified_gmt": "2023-11-29 09:50:11","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example-wpnew.local\/?post_type=academy_quiz&p=6960","menu_order": 0,"post_type": "academy_quiz","post_mime_type": "","comment_count": "0","filter": "raw"}, "quiz_attempt_details": [{"attempt_id": "2","course_id": "6949","quiz_id": "6960","user_id": "126","total_questions": "1","total_answered_questions": "1","total_marks": "20.00","earned_marks": "0.00","attempt_info": "{\"total_correct_answers\":0}","attempt_status": "failed","attempt_ip": "127.0.0.1","attempt_started_at": "2023-11-30 06:20:10","attempt_ended_at": "2023-11-30 06:20:10","is_manually_reviewed": null,"manually_reviewed_at": null}],"quiz":1},"response_type":"sample"}'; break; case 'ac_lms_enrolled_course': $sample_data = '{"pluggable_data":{"course_data": {"ID": 6949,"post_author": "1","post_date": "2023-11-29 05:37:50","post_date_gmt": "2023-11-29 05:37:50","post_content": "\n
this is a business course.<\/p>\n","post_title": "Business Course","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "business-course","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:27","post_modified_gmt": "2023-11-29 09:50:27","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example-wpnew.local\/course\/business-course\/","menu_order": 0,"post_type": "academy_courses","post_mime_type": "","comment_count": "0","filter": "raw"},"enrollment_data": {"ID": "6971","post_author": "126","post_date": "2023-11-30 05:52:54","post_date_gmt": "2023-11-30 05:52:54","post_content": "","post_title": "Course Enrolled November 30, 2023 @ 5:52 am","post_excerpt": "","post_status": "completed","comment_status": "closed","ping_status": "closed","post_password": "","post_name": "course-enrolled-november-30-2023-552-am","to_ping": "","pinged": "","post_modified": "2023-11-30 05:52:54","post_modified_gmt": "2023-11-30 05:52:54","post_content_filtered": "","post_parent": "6949","guid": "https:\/\/example-wpnew.local\/?p=6971","menu_order": "0","post_type": "academy_enrolled","post_mime_type": "","comment_count": "0"},"course":1, "wp_user_id": 2,"user_login": "test","display_name": "test test","user_firstname": "test","user_lastname": "test", "user_email": "test@yopmail.com","user_role": ["academy_student"]},"response_type":"sample"}'; break; default: return; } $context = (array) json_decode( $sample_data, true ); } return $context; } /** * Search myCred Point Type List. * * @param array $data Search Params. * @return array */ public function search_mycred_point_type_list( $data ) { $options = []; if ( ! function_exists( 'mycred_get_types' ) ) { return []; } $posts = mycred_get_types(); if ( ! empty( $posts ) ) { if ( is_array( $posts ) ) { foreach ( $posts as $key => $post ) { $options[] = [ 'label' => $post, 'value' => $key, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare elementor forms. * * @param array $data Search Params. * * @return array */ public function search_new_elementor_form_fields( $data ) { $fields = []; $select_form_id = $data['dynamic']; global $wpdb; $post_metas = $wpdb->get_results( $wpdb->prepare( "SELECT pm.post_id, pm.meta_value FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts p ON p.ID = pm.post_id WHERE p.post_type IS NOT NULL AND p.post_status = %s AND pm.meta_key = %s AND pm.`meta_value` LIKE %s", 'publish', '_elementor_data', '%%form_fields%%' ) ); if ( ! empty( $post_metas ) ) { foreach ( $post_metas as $post_meta ) { /** * * Ignore line * * @phpstan-ignore-next-line */ $inner_forms = Utilities::search_elementor_forms( json_decode( $post_meta->meta_value ) ); if ( ! empty( $inner_forms ) ) { foreach ( $inner_forms as $form ) { $form_id = explode( '_', $select_form_id ); if ( is_object( $form ) ) { if ( $form->id == $form_id[1] ) { if ( ! empty( $form->settings->form_fields ) ) { foreach ( $form->settings->form_fields as $field ) { $fields[] = [ 'value' => $field->custom_id, 'text' => ! empty( $field->field_label ) ? $field->field_label : 'unknown', ]; } } } } } } } } $options = []; if ( ! empty( $fields ) ) { foreach ( $fields as $key => $value ) { $options[] = [ 'label' => $value['text'], 'value' => $value['value'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Fluent Booking Appointment Events. * * @param array $data data. * * @return array */ public function search_fluent_booking_calendars_list( $data ) { global $wpdb; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $calendars = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS id, title FROM {$wpdb->prefix}fcal_calendars WHERE status = %s ORDER BY id DESC LIMIT %d OFFSET %d", [ 'active', $limit, $offset ] ), OBJECT ); $calendars_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); $options = []; if ( ! empty( $calendars ) ) { foreach ( $calendars as $calendar ) { $options[] = [ 'label' => $calendar->title, 'value' => $calendar->id, ]; } } return [ 'options' => $options, 'hasMore' => $calendars_count > $limit && $calendars_count > $offset, ]; } /** * Get Fluent Booking Appointment Events. * * @param array $data data. * * @return array */ public function search_fluent_booking_events_list( $data ) { global $wpdb; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $calendar_id = sanitize_text_field( $data['dynamic']['calender_id'] ); if ( '-1' === $calendar_id ) { $events = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS id, title FROM {$wpdb->prefix}fcal_calendar_events WHERE status = %s ORDER BY id DESC LIMIT %d OFFSET %d", [ 'active', $limit, $offset ] ), OBJECT ); } else { $events = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS id, title FROM {$wpdb->prefix}fcal_calendar_events WHERE status = %s AND calendar_id = %d ORDER BY id DESC LIMIT %d OFFSET %d", [ 'active', $calendar_id, $limit, $offset ] ), OBJECT ); } $events_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); $options = []; if ( ! empty( $events ) ) { foreach ( $events as $event ) { $options[] = [ 'label' => $event->title, 'value' => $event->id, ]; } } return [ 'options' => $options, 'hasMore' => $events_count > $limit && $events_count > $offset, ]; } /** * Get Fluent Booking last data. * * @param array $data data. * * @return array */ public function search_fluent_booking_last_data( $data ) { global $wpdb; $trigger = $data['search_term']; $course_data = []; $lesson_data = []; $sample_data = '{"pluggable_data":{"booking":{"id":"7","hash":"dc641fd972e27be079945e3f998def39","calendar_id":"1","event_id":"1","group_id":"7","fcrm_id":null,"parent_id":null,"host_user_id":"1","person_user_id":"1","person_contact_id":null,"person_time_zone":"Asia/Calcutta","start_time":"2024-01-29 11:00:00","end_time":"2024-01-29 11:15:00","slot_minutes":"15","first_name":"Sure","last_name":"Test","email":"dev-email@wpengine.local","message":"","internal_note":null,"phone":"","country":null,"ip_address":"","browser":null,"device":null,"other_info":null,"location_details":{"type":"in_person_guest","description":"Location description."},"cancelled_by":"1","status":"completed","source":"web","booking_type":"scheduling","event_type":"single","payment_status":null,"payment_method":null,"source_url":"https://connector.com/fluent-booking/","source_id":null,"utm_source":"","utm_medium":"","utm_campaign":"","utm_term":"","created_at":"2024-01-29 06:46:22","updated_at":"2024-01-29 06:57:42","custom_fields":null},"event":{"id":"1","hash":"38c65708b797f5d6956070896f792b34","user_id":"1","calendar_id":"1","duration":"15","title":"One to one","slug":"15min","media_id":null,"description":"","settings":{"schedule_type":"weekly_schedules","weekly_schedules":{"sun":{"enabled":false,"slots":[]},"mon":{"enabled":true,"slots":[{"start":"03:30","end":"11:30"}]},"tue":{"enabled":true,"slots":[{"start":"03:30","end":"11:30"}]},"wed":{"enabled":true,"slots":[{"start":"03:30","end":"11:30"}]},"thu":{"enabled":true,"slots":[{"start":"03:30","end":"11:30"}]},"fri":{"enabled":true,"slots":[{"start":"03:30","end":"11:30"}]},"sat":{"enabled":false,"slots":[]}},"date_overrides":[],"range_type":"range_days","range_days":60,"range_date_between":["",""],"schedule_conditions":{"value":4,"unit":"hours"},"location_fields":{"conferencing":{"label":"Conferencing","options":{"google_meet":{"title":"Google Meet (Connect Google Meet First)","disabled":true,"location_type":"conferencing"},"ms_teams":{"title":"MS Teams (Connect Outlook First)","disabled":true,"location_type":"conferencing"}}},"in_person":{"label":"In Person","options":{"in_person_guest":{"title":"In Person (Attendee Address)"},"in_person_organizer":{"title":"In Person (Organizer Address)"}}},"phone":{"label":"Phone","options":{"phone_guest":{"title":"Attendee Phone Number"},"phone_organizer":{"title":"Organizer Phone Number"}}},"online":{"label":"Online","options":{"online_meeting":{"title":"Online Meeting"}}},"other":{"label":"Other","options":{"custom":{"title":"Custom"}}}},"team_members":[],"custom_redirect":{"enabled":false,"redirect_url":"","is_query_string":"no","query_string":""},"multi_duration":{"enabled":true,"default_duration":"15","available_durations":["15","30","45"]}},"availability_type":"existing_schedule","availability_id":"1","status":"active","type":"free","color_schema":"#0099ff","location_type":"","location_heading":"","location_settings":[{"type":"in_person_guest","title":"In Person (Attendee Address)","display_on_booking":""}],"event_type":"single","is_display_spots":"0","max_book_per_slot":"1","created_at":"2024-01-28 08:35:29","updated_at":"2024-01-28 08:36:06"}},"response_type":"sample"}'; //phpcs:ignore $context = [ 'pluggable_data' => json_decode( $sample_data, true ), 'response_type' => 'sample', ]; if ( 'fluent_booking_appointment_cancelled' === $trigger ) { $status = 'cancelled'; } elseif ( 'fluent_booking_appointment_completed' === $trigger ) { $status = 'completed'; } $event_id = (int) $data['filter']['event_id']['value']; if ( 'fluent_booking_appointment_cancelled' === $trigger || 'fluent_booking_appointment_completed' === $trigger ) { if ( $event_id > 0 ) { $booking = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fcal_bookings WHERE event_id= %d AND status= %s ORDER BY id DESC LIMIT 1", $event_id, $status ) ); } else { $booking = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fcal_bookings WHERE status= %s ORDER BY id DESC LIMIT 1", $status ) ); } } elseif ( 'fluent_booking_new_appointment_booked' === $trigger ) { if ( $event_id > 0 ) { $booking = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fcal_bookings WHERE event_id= %d AND status != %s ORDER BY id DESC LIMIT 1", $event_id, 'cancelled' ) ); } else { $booking = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fcal_bookings WHERE status != %s ORDER BY id DESC LIMIT 1", 'cancelled' ) ); } } if ( ! empty( $booking ) ) { $booking_meta = $wpdb->get_row( $wpdb->prepare( "SELECT value FROM {$wpdb->prefix}fcal_booking_meta WHERE booking_id= %d AND meta_key= 'custom_fields_data'", $booking->id ) ); $booking_event = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fcal_calendar_events WHERE id= %d", $booking->event_id ) ); $booking_data = $booking; $booking_data->custom_fields = $booking_meta->value; $booking_array = [ 'booking' => $booking_data, 'event' => $booking_event, ]; $booking_array_response = self::recursive_unserialize( $booking_array ); $context['pluggable_data'] = $booking_array_response; $context['response_type'] = 'live'; } return $context; } /** * Recursive unserilize. * * @param array $data data. * * @return array|mixed */ public static function recursive_unserialize( $data ) { if ( is_array( $data ) ) { foreach ( $data as $key => $value ) { $data[ $key ] = self::recursive_unserialize( $value ); } return $data; } elseif ( is_object( $data ) && 'stdClass' === get_class( $data ) ) { foreach ( $data as $property => $value ) { $data->$property = self::recursive_unserialize( $value ); } return $data; } elseif ( is_string( $data ) && self::is_serialized( strval( $data ) ) ) { return unserialize( $data ); } else { return $data; } } /** * Check if string serialized. * * @param string $data data. * * @return bool */ public static function is_serialized( $data ) { $unserialized = unserialize( $data ); if ( 'b:0;' === $data || false !== $unserialized ) { return true; } else { return false; } } /** * Search Tutor LMS data. * * @param array $data data. * @return array|void|mixed */ public function search_tutor_lms_last_data( $data ) { global $wpdb; $post_type = $data['post_type']; $trigger = $data['search_term']; $context = []; if ( ! function_exists( 'tutor_utils' ) ) { return []; } $post_id = -1; if ( 'course_enrolled' === $trigger || 'tutor_courses_question' === $trigger ) { $post_id = $data['filter']['tutor_course']['value']; } elseif ( 'quiz_attempt_percentage' === $trigger || 'quiz_failed' === $trigger || 'quiz_passed' === $trigger ) { $post_id = $data['filter']['quiz_id']['value']; } if ( 'course_enrolled' === $trigger ) { if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_status='completed' AND post_type=%s order by ID DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_parent = %s AND post_status='completed' AND post_type=%s order by ID DESC LIMIT 1", $post_id, $post_type ) ); } } elseif ( 'tutor_courses_question' === $trigger ) { if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}comments as comment JOIN {$wpdb->prefix}posts as posts ON posts.ID=comment.comment_post_ID WHERE comment.comment_approved='approved' AND comment.comment_type='tutor_q_and_a' AND posts.post_type=%s order by comment.comment_ID DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}comments as comment JOIN {$wpdb->prefix}posts as posts ON posts.ID=comment.comment_post_ID WHERE comment.comment_post_ID = %s AND comment.comment_approved='approved' AND comment.comment_type='tutor_q_and_a' AND posts.post_type=%s order by comment.comment_ID DESC LIMIT 1", $post_id, $post_type ) ); } } elseif ( 'quiz_passed' === $trigger ) { if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_quiz_attempts as quiz JOIN {$wpdb->prefix}posts as posts ON posts.ID=quiz.quiz_id WHERE quiz.attempt_status='attempt_ended' AND quiz.earned_marks >= quiz.total_marks AND posts.post_type=%s order by quiz.attempt_id DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_quiz_attempts as quiz JOIN {$wpdb->prefix}posts as posts ON posts.ID=quiz.quiz_id WHERE quiz.quiz_id = %s AND quiz.attempt_status='attempt_ended' AND quiz.earned_marks >= quiz.total_marks AND posts.post_type=%s order by quiz.attempt_id DESC LIMIT 1", $post_id, $post_type ) ); } } elseif ( 'quiz_failed' === $trigger ) { if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_quiz_attempts as quiz JOIN {$wpdb->prefix}posts as posts ON posts.ID=quiz.quiz_id WHERE quiz.attempt_status='attempt_ended' AND quiz.earned_marks < quiz.total_marks AND posts.post_type=%s order by quiz.attempt_id DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_quiz_attempts as quiz JOIN {$wpdb->prefix}posts as posts ON posts.ID=quiz.quiz_id WHERE quiz.quiz_id = %s AND quiz.attempt_status='attempt_ended' AND quiz.earned_marks < quiz.total_marks AND posts.post_type=%s order by quiz.attempt_id DESC LIMIT 1", $post_id, $post_type ) ); } } elseif ( 'quiz_attempt_percentage' == $trigger ) { $condition_compare = $data['filter']['condition_compare']['value']; $percentage = $data['filter']['percentage']['value']; if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_quiz_attempts as quiz JOIN {$wpdb->prefix}posts as posts ON posts.ID=quiz.quiz_id WHERE earned_marks $condition_compare %d AND quiz.attempt_status='attempt_ended' AND posts.post_type=%s order by quiz.attempt_id DESC LIMIT 1", $percentage, $post_type ) ); //phpcs:ignore } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_quiz_attempts as quiz JOIN {$wpdb->prefix}posts as posts ON posts.ID=quiz.quiz_id WHERE earned_marks $condition_compare %d AND quiz.quiz_id = %s AND quiz.attempt_status='attempt_ended' AND posts.post_type=%s order by quiz.attempt_id DESC LIMIT 1", $percentage, $post_id, $post_type ) ); //phpcs:ignore } } if ( ! empty( $result ) ) { switch ( $trigger ) { case 'course_enrolled': $result_item_id = $result[0]->post_parent; $result_user_id = $result[0]->post_author; $context_data = array_merge( WordPress::get_user_context( $result_user_id ), WordPress::get_post_context( $result_item_id ) ); $context_data['tutor_course'] = $result_item_id; break; case 'tutor_courses_question': $date = $result[0]->comment_date; $data = [ 'comment_post_ID' => $result[0]->comment_post_ID, 'comment_author' => $result[0]->comment_author, 'comment_date' => $date, 'comment_date_gmt' => get_gmt_from_date( $date ), 'comment_content' => $result[0]->comment_content, 'comment_approved' => 'approved', 'comment_agent' => 'TutorLMSPlugin', 'comment_type' => 'tutor_q_and_a', 'comment_parent' => $result[0]->comment_parent, 'user_id' => $result[0]->user_id, ]; $context_data['tutor_course'] = $result[0]->comment_post_ID; $context_data['data'] = $data; break; case 'quiz_attempt_percentage': case 'quiz_failed': case 'quiz_passed': $attempt = tutor_utils()->get_attempt( $result[0]->attempt_id ); $context_data = WordPress::get_user_context( $result[0]->user_id ); $context_data['quiz_id'] = $attempt->quiz_id; $context_data['attempt_id'] = $result[0]->attempt_id; $context_data['attempt'] = $attempt; break; default: return; } if ( ! empty( $context_data ) ) { $context['pluggable_data'] = $context_data; $context['response_type'] = 'live'; } } elseif ( empty( $result ) ) { switch ( $trigger ) { case 'course_enrolled': $sample_data = '{"pluggable_data":{"wp_user_id": 1,"user_login": "admin","display_name": "admin","user_firstname": "test","user_lastname": "test","user_email": "john@d.com","user_role": ["customer"],"id": 6636,"name": "Modes Master Class","slug": "modes-master-class-2","date_created": {"date": "2023-10-20 06:09:15.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-21 15:22:29.000000","timezone_type": 1,"timezone": "+00:00"},"status": "publish","menu_order": 0,"featured": false,"catalog_visibility": "visible","description": "Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words.","short_description": "","post_password": "","author_id": 1,"parent_id": 0,"reviews_allowed": true,"date_on_sale_from": null,"date_on_sale_to": null,"price": "0","regular_price": "0","sale_price": "","price_type": "free","category_ids": [106,107],"tag_ids": [],"difficulty_id": 0,"featured_image": 6616,"rating_counts": [],"average_rating": "0","review_count": 0,"enrollment_limit": 0,"duration": 360,"access_mode": "open","billing_cycle": "","show_curriculum": true,"purchase_note": "","highlights": "
PizzaCrust - Since 2009! Whether it\u2019s our iconic Sandwiches, wooden baked pizzas, signature sauce, original fresh dough or toppings, we invest in bringing the freshest and best ingredients to bring you the tastiest meal.<\/p>","post_title": "Pizza Crust","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "closed","post_password": "","post_name": "sach-pizza","to_ping": "","pinged": "","post_modified": "2024-03-18 09:01:54","post_modified_gmt": "2024-03-18 09:01:54","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example-wpnew.local\/places\/sach-pizza\/","menu_order": 0,"post_type": "places","post_mime_type": "","comment_count": "0","filter": "raw","review_content": "Nice one","review_created_at": "2024-04-04 12:59:22","review_details": {"rating": {"score": -1,"custom-660": -1,"custom-978": -1,"custom-271": -1}},"review_by": {"wp_user_id": 188,"user_login": "dev4","display_name": "dev4","user_firstname": "","user_lastname": "","user_email": "dev4@yopmail.com","user_role": ["subscriber"]}},"response_type":"sample"}', true );// @phpcs:ignore } } elseif ( 'collection_post_submitted' === $term || 'collection_post_updated' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data'] = Voxel::get_post_fields( $results[0]['ID'] ); $context['pluggable_data']['collection'] = WordPress::get_post_context( $results[0]['ID'] ); $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"field_step-general": null,"field_title": "First Collection","field_items": [8909,8293],"collection": {"ID": 9142,"post_author": "35", "post_date": "2024-05-27 05:55:21","post_date_gmt": "2024-05-27 05:55:21","post_content": "This is a first collection","post_title": "First Collection","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "closed","post_password": "","post_name": "first-collection","to_ping": "","pinged": "","post_modified": "2024-05-27 05:55:21","post_modified_gmt": "2024-05-27 05:55:21","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example.com\/collection\/first-collection\/","menu_order": 0,"post_type": "collection","post_mime_type": "","comment_count": "0","filter": "raw"}},"response_type":"sample"}', true );// @phpcs:ignore } } elseif ( 'new_wall_post_by_user' === $term || 'wall_post_approved' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data']['post'] = Voxel::get_post_fields( $results[0]['post_id'] ); $user = get_userdata( $results[0]['user_id'] ); if ( $user ) { $user_data = (array) $user->data; $context['pluggable_data']['user_display_name'] = $user_data['display_name']; $context['pluggable_data']['user_name'] = $user_data['user_nicename']; $context['pluggable_data']['user_email'] = $user_data['user_email']; $context['pluggable_data']['user_id'] = $results[0]['user_id']; } if ( class_exists( 'Voxel\Timeline\Status' ) ) { $args = [ 'post_id' => $results[0]['post_id'], 'order_by' => 'created_at', 'order' => 'desc', 'feed' => $results[0]['feed'], 'limit' => 1, 'moderation' => $results[0]['moderation'], ]; $statuses = \Voxel\Timeline\Status::query( $args ); $status_details = $statuses['items'][0]; foreach ( (array) $status_details as $key => $value ) { $clean_key = preg_replace( '/^\0.*?\0/', '', $key ); if ( is_object( $value ) ) { $encoded_value = wp_json_encode( $value ); if ( is_string( $encoded_value ) ) { $value = json_decode( $encoded_value, true ); } } $context['pluggable_data']['wall_post'][ $clean_key ] = $value; } } $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"post":{"field_step-general":null,"field_title":"How Data Fundamentally Changed Marketing","field__thumbnail_id":{"_thumbnail_id_0_url":"https://example.com/wp-content/uploads/2025/01/169cbc8.jpg"},"field_taxonomy":"General"},"user_display_name":"john d","user_name":"john","user_email":"johnd@example.com","user_id":"2","wall_post":{"id":31,"user_id":2,"post_id":447,"published_as":null,"content":"new hello","feed":"post_wall","moderation":0,"repost_of":null,"quote_of":null,"created_at":"2025-01-22 08:56:24","edited_at":null,"review_score":null,"like_count":0,"reply_count":0,"details":[],"liked_by_user":false,"reposted_by_user":false,"last3_liked":[],"friends_reposted":[],"friends_liked":[]}},"response_type":"sample"}', true );// @phpcs:ignore } } elseif ( 'taxonomy_updated' === $term ) { if ( ! empty( $results ) ) { $post_id = $results[0]['post_id']; $context['pluggable_data'] = WordPress::get_post_context( $post_id ); $context['pluggable_data']['post'] = Voxel::get_post_fields( $post_id ); $context['pluggable_data']['post_type'] = get_post_type( $post_id ); // Get taxonomy details. $term_obj = get_term( $results[0]['term_taxonomy_id'] ); if ( $term_obj && ! is_wp_error( $term_obj ) ) { $context['pluggable_data']['taxonomy'] = $results[0]['taxonomy']; $context['pluggable_data']['update_type'] = 'updated'; $context['pluggable_data']['terms_added'] = [ $results[0]['term_taxonomy_id'] ]; $context['pluggable_data']['terms_removed'] = []; $context['pluggable_data']['current_terms'] = [ $results[0]['term_taxonomy_id'] ]; $context['pluggable_data']['previous_terms'] = []; $context['pluggable_data']['added_terms_details'] = [ [ 'term_id' => $term_obj->term_id, 'name' => $term_obj->name, 'slug' => $term_obj->slug, ], ]; $context['pluggable_data']['removed_terms_details'] = []; $context['pluggable_data']['current_terms_details'] = [ [ 'term_id' => $term_obj->term_id, 'name' => $term_obj->name, 'slug' => $term_obj->slug, ], ]; $context['pluggable_data']['is_voxel_taxonomy_field'] = false; $context['pluggable_data']['voxel_field_data'] = null; } $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"ID": 557,"post_author": "1","post_date": "2022-11-18 12:18:14","post_date_gmt": "2022-11-18 12:18:14","post_content": "Test Post Content","post_title": "Test Post","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "test-post","to_ping": "","pinged": "","post_modified": "2022-11-18 12:18:14","post_modified_gmt": "2022-11-18 12:18:14","post_content_filtered": "","post_parent": 0,"guid": "https://example.com/test-post/","menu_order": 0,"post_type": "post","post_mime_type": "","comment_count": 0,"filter": "raw","post": {"field_step-general": null,"field_title": "Test Post","field_taxonomy": "General"},"post_type": "post","taxonomy": "category","update_type": "added","terms_added": [1],"terms_removed": [],"current_terms": [1],"previous_terms": [],"added_terms_details": [{"term_id": 1,"name": "Uncategorized","slug": "uncategorized"}],"removed_terms_details": [],"current_terms_details": [{"term_id": 1,"name": "Uncategorized","slug": "uncategorized"}],"is_voxel_taxonomy_field": false,"voxel_field_data": null},"response_type":"sample"}', true );// @phpcs:ignore } } elseif ( 'post_followed' === $term ) { if ( ! empty( $results ) ) { $follow_data = [ 'post_id' => $results[0]['object_id'], 'user_id' => $results[0]['follower_id'], 'status' => $results[0]['status'], ]; $follow_data = array_merge( $follow_data, Voxel::get_post_fields( $results[0]['object_id'] ), WordPress::get_post_context( $results[0]['object_id'] ) ); $followers_sql = "SELECT COUNT(*) FROM {$wpdb->prefix}voxel_followers WHERE object_id= %d"; $followers = $wpdb->get_var( $wpdb->prepare( $followers_sql, $results[0]['object_id'] ));// @phpcs:ignore $follow_data['total_followers'] = $followers; $context['pluggable_data'] = $follow_data; $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"field_step-general":null,"field_title":"How Data Fundamentally Changed Marketing","field__thumbnail_id":{"_thumbnail_id_0_url":"https://example.com/wp-content/uploads/2025/01/169cbc8.jpg"},"field_taxonomy":"General","ID": 8291,"post_author": "1","post_date": "2024-03-18 09:01:54","post_date_gmt": "2024-03-18 09:01:54","post_content": "
PizzaCrust - Since 2009! Whether it\u2019s our iconic Sandwiches, wooden baked pizzas, signature sauce, original fresh dough or toppings, we invest in bringing the freshest and best ingredients to bring you the tastiest meal.<\/p>","post_title": "Pizza Crust","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "closed","post_password": "","post_name": "sach-pizza","to_ping": "","pinged": "","post_modified": "2024-03-18 09:01:54","post_modified_gmt": "2024-03-18 09:01:54","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example-wpnew.local\/places\/sach-pizza\/","menu_order": 0,"post_type": "places","post_mime_type": "","comment_count": "0","filter": "raw","total_followers":4,"post_id": 447,"user_id": 2,"status":1},"response_type":"sample"}', true );// @phpcs:ignore } } return $context; } /** * Get Voxel Profiles Last Data * * @param array $data data. * * @return array|mixed|string */ public function search_voxel_profiles_triggers_last_data( $data ) { global $wpdb; $context = []; $term = $data['search_term']; if ( ! class_exists( 'Voxel\Timeline\Status' ) || ! class_exists( 'Voxel\Post_Type' ) ) { return []; } if ( 'profile_created' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}posts WHERE post_type LIKE %s ORDER BY ID DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'profile' ), ARRAY_A );// @phpcs:ignore } elseif ( 'profile_approved' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}posts WHERE post_type LIKE %s AND post_status LIKE %s ORDER BY ID DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'profile', 'publish' ), ARRAY_A );// @phpcs:ignore } elseif ( 'profile_rejected' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}posts WHERE post_type LIKE %s AND post_status LIKE %s ORDER BY ID DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'profile', 'rejected' ), ARRAY_A );// @phpcs:ignore } elseif ( 'profile_reviewed' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}voxel_timeline vt LEFT JOIN {$wpdb->prefix}posts pm ON vt.post_id = pm.ID WHERE pm.post_type LIKE %s AND vt.details IS NOT NULL ORDER BY vt.id DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'profile' ), ARRAY_A );// @phpcs:ignore } elseif ( 'profile_updated' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}posts WHERE post_type LIKE %s ORDER BY post_modified DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'profile' ), ARRAY_A );// @phpcs:ignore } elseif ( 'profile_new_wall_post' === $term ) { $sql = "SELECT vt.* FROM {$wpdb->prefix}voxel_timeline vt JOIN {$wpdb->prefix}posts p ON vt.post_id = p.ID JOIN {$wpdb->prefix}postmeta pm ON pm.post_id = p.ID WHERE p.post_type LIKE 'profile' ORDER BY vt.id DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'profile' ), ARRAY_A );// @phpcs:ignore } if ( 'profile_created' === $term || 'profile_approved' === $term || 'profile_rejected' === $term || 'profile_updated' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data'] = Voxel::get_post_fields( $results[0]['ID'] ); $user = get_userdata( $results[0]['post_author'] ); if ( $user ) { $user_data = (array) $user->data; $context['pluggable_data']['profile_display_name'] = $user_data['display_name']; $context['pluggable_data']['profile_email'] = $user_data['user_email']; $context['pluggable_data']['profile_user_id'] = $results[0]['post_author']; $context['pluggable_data']['profile_id'] = $results[0]['ID']; } $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"field_step-general": null,"field_voxel:name":"johnd","field_voxel:avatar": [],"field_description": "","profile_display_name": "johnd","profile_name": "johnd","profile_email": "johnd@yopmail.com","profile_user_id": "1"},"response_type":"sample"}', true );// @phpcs:ignore } } elseif ( 'profile_new_wall_post' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data']['profile'] = Voxel::get_post_fields( $results[0]['post_id'] ); $user = get_userdata( $results[0]['user_id'] ); if ( $user ) { $user_data = (array) $user->data; $context['pluggable_data']['profile_display_name'] = $user_data['display_name']; $context['pluggable_data']['profile_name'] = $user_data['user_nicename']; $context['pluggable_data']['profile_email'] = $user_data['user_email']; $context['pluggable_data']['profile_user_id'] = $results[0]['user_id']; } // Get the status details. $args = [ 'post_id' => $results[0]['post_id'], 'order_by' => 'created_at', 'order' => 'desc', 'feed' => $results[0]['feed'], 'limit' => 1, 'moderation' => $results[0]['moderation'], ]; $statuses = \Voxel\Timeline\Status::query( $args ); $status_details = $statuses['items'][0]; foreach ( (array) $status_details as $key => $value ) { $clean_key = preg_replace( '/^\0.*?\0/', '', $key ); if ( is_object( $value ) ) { $encoded_value = wp_json_encode( $value ); if ( is_string( $encoded_value ) ) { $value = json_decode( $encoded_value, true ); } } $context['pluggable_data']['wall_post'][ $clean_key ] = $value; } $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"profile":{"field_step-general":null,"field_ui-image-2":null,"field_voxel:name":"John","field_voxel:avatar":null,"field_cover":null,"field_ui-step":null,"field_ui-image-3":null,"field_location":null,"field_ui-step-2":null,"field_ui-image":null,"field_description":""},"profile_display_name":"John","profile_name":"admin","profile_email":"johnd@gmail.com","profile_user_id":"1","wall_post":{"id":73,"user_id":1,"post_id":586,"published_as":null,"content":"Test content","feed":"post_reviews","moderation":1,"repost_of":null,"quote_of":null,"created_at":"2025-02-02 05:28:00","edited_at":null,"review_score":-2,"like_count":0,"reply_count":0,"details":{"rating":{"score":-2}},"liked_by_user":false,"reposted_by_user":false,"last3_liked":[],"friends_reposted":[],"friends_liked":[]}},"response_type":"sample"}', true );// @phpcs:ignore } } elseif ( 'profile_reviewed' === $term ) { if ( ! empty( $results ) ) { // Get the review details. $args = [ 'post_id' => $results[0]['post_id'], 'order_by' => 'created_at', 'order' => 'desc', 'feed' => $results[0]['feed'], 'limit' => 1, 'moderation' => $results[0]['moderation'], ]; $statuses = \Voxel\Timeline\Status::query( $args ); $review_details = $statuses['items'][0]; foreach ( (array) $review_details as $key => $value ) { $clean_key = preg_replace( '/^\0.*?\0/', '', $key ); if ( 'user_can_edit' == $clean_key || 'publisher' == $clean_key || 'user_can_edit' == $clean_key || 'user_can_moderate' == $clean_key ) { continue; } if ( 'files' === $clean_key ) { $value = wp_json_encode( $value ); } elseif ( 'details' === $clean_key ) { $review_ratings = isset( $value['rating'] ) && is_array( $value['rating'] ) ? $value['rating'] : []; $value['rating'] = []; $type = \Voxel\Post_Type::get( 'profile' ); if ( ! empty( $review_ratings ) ) { $rating_levels = $type->reviews->get_rating_levels(); $categories = $type->reviews->get_categories(); foreach ( $categories as $category ) { $category_key = $category['key']; $category_label = strtolower( $category['label'] ); if ( isset( $review_ratings[ $category_key ] ) && $category_label ) { foreach ( $rating_levels as $rating_level ) { if ( $review_ratings[ $category_key ] === $rating_level['score'] ) { $value['rating'][ $category_label ] = $rating_level['label']; break; } } } } } } else { $clean_key = 'review_' . $clean_key; } $context['pluggable_data'][ $clean_key ] = $value; } $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"review_id":73,"review_user_id":1,"review_post_id":586,"review_published_as":null,"review_content":"test content","review_feed":"post_reviews","review_moderation":1,"review_repost_of":null,"review_quote_of":null,"review_created_at":"2025-02-02 05:28:00","review_edited_at":null,"review_review_score":-2,"review_like_count":0,"review_reply_count":0,"details":{"rating":[],"rating":{"rating":"Poor"}},"review_liked_by_user":false,"review_reposted_by_user":false,"review_last3_liked":[],"review_friends_reposted":[],"review_friends_liked":[]},"response_type":"sample"}', true );// @phpcs:ignore } } return $context; } /** * Get Voxel Messages Triggers Last Data * * @param array $data data. * * @return array|mixed|string */ public function search_voxel_messages_triggers_last_data( $data ) { global $wpdb; $context = []; $term = $data['search_term']; if ( 'voxel_new_message_post_created' === $term ) { $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}voxel_messages ORDER BY id DESC LIMIT %d", 1 ), ARRAY_A ); if ( ! empty( $results ) ) { $message = $results[0]; $context['pluggable_data']['sender'] = WordPress::get_user_context( $message['sender_id'] ); $context['pluggable_data']['receiver'] = WordPress::get_user_context( $message['receiver_id'] ); $context['pluggable_data']['content'] = $message['content']; $context['pluggable_data']['message_id'] = $message['id']; $context['pluggable_data']['created_at'] = $message['created_at']; $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"sender":{"wp_user_id":9,"user_login":"johndoe","display_name":"John Doe","user_firstname":"John","user_lastname":"Doe","user_email":"john@example.com","user_registered":"2025-07-18 15:01:53","user_role":["author"]},"receiver":{"wp_user_id":11,"user_login":"janedoe","display_name":"Jane Smith","user_firstname":"Jane","user_lastname":"Smith","user_email":"jane@example.com","user_registered":"2025-07-21 03:16:45","user_role":["author"]},"content":"Hello, how are you?","message_id":11,"created_at":"2025-08-06 05:27:02"},"response_type":"sample"}', true ); } } return $context; } /** * Get Late Point Customer Fields * * @param array $data data. * * @return array|void */ public function search_late_point_customer_fields( $data ) { if ( ! class_exists( 'OsCustomFieldsController' ) ) { return; } global $wpdb; $booking_fields = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}latepoint_settings WHERE name = %s", 'custom_fields_for_customer' ) ); $fields = []; if ( ! empty( $booking_fields ) ) { $fields = json_decode( $booking_fields->value, true ); } return (array) $fields; } /** * Is multi person booking * * @param array $data data. * * @return array|void */ public function search_late_point_multi_person_booking( $data ) { if ( ! class_exists( 'LatePointAddonGroupBookings' ) ) { return; } $service_id = isset( $data['dynamic'] ) ? $data['dynamic'] : '-1'; if ( -1 == $service_id ) { return; } global $wpdb; $booking_details = $wpdb->get_row( $wpdb->prepare( "SELECT capacity_max,capacity_min FROM {$wpdb->prefix}latepoint_services WHERE id= %s", intval( $service_id ) ) ); if ( ! empty( $booking_details ) ) { return (array) $booking_details; } } /** * Get Mail Mint lists * * @param array $data data. * * @return array */ public function search_mail_mint_contact_lists( $data ) { global $wpdb; $lists = $wpdb->get_results( $wpdb->prepare( 'SELECT title, id FROM ' . $wpdb->prefix . 'mint_contact_groups WHERE type = %s', 'lists' ) ); $options = []; if ( ! empty( $lists ) ) { foreach ( $lists as $list ) { $options[] = [ 'label' => $list->title, 'value' => $list->id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Mail Mint tags * * @param array $data data. * * @return array */ public function search_mail_mint_contact_tags( $data ) { global $wpdb; $lists = $wpdb->get_results( $wpdb->prepare( 'SELECT title, id FROM ' . $wpdb->prefix . 'mint_contact_groups WHERE type = %s ', 'tags' ) ); $options = []; if ( ! empty( $lists ) ) { foreach ( $lists as $list ) { $options[] = [ 'label' => $list->title, 'value' => $list->id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** Get Better Messages trigger Last Data * * @param array $data data. * * @return array|mixed|string */ public function search_better_messages_triggers_data( $data ) { $context = []; global $wpdb; if ( ! function_exists( 'Better_Messages' ) ) { return []; } $sql = "SELECT * FROM {$wpdb->prefix}bm_message_messages ORDER BY id DESC LIMIT 1"; $results = $wpdb->get_results( $sql, ARRAY_A );// @phpcs:ignore if ( ! empty( $results ) ) { $message = Better_Messages()->functions->get_message( $results[0]['id'] ); if ( is_object( $message ) ) { $message = get_object_vars( $message ); } $context['pluggable_data'] = $message; $context['pluggable_data']['sender'] = WordPress::get_user_context( $results[0]['sender_id'] ); $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"id": "21","thread_id": "11","sender_id": "79","message": "New message","date_sent": "2024-04-09 07:08:35","sender": {"wp_user_id": 79,"user_login": "johnd@gmail.com","display_name": "johnd@gmail.com","user_firstname": "John","user_lastname": "D","user_email": "johnd@gmail.com","user_role": ["customer"]}},"response_type":"sample"}', true );// @phpcs:ignore } return $context; } /** * Get Appointment Hour Booking trigger Last Data * * @param array $data data. * * @return array|mixed|string */ public function search_ahb_appointment_booked_triggers_last_data( $data ) { $context = []; global $wpdb; $sql = "SELECT * FROM {$wpdb->prefix}cpappbk_messages ORDER BY id DESC LIMIT 1"; $results = $wpdb->get_results( $sql, ARRAY_A );// @phpcs:ignore if ( ! empty( $results ) ) { $context['pluggable_data'] = unserialize( $results[0]['posted_data'] ); $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"final_price": "1.00","final_price_short": "1","request_timestamp": "04\/10\/2024 06:56:33","apps": [{"id": 1,"cancelled": "Pending","serviceindex": 0,"service": "Service 1","duration": 60,"price": 1,"date": "2024-04-13","slot": "10:00\/11:00","military": 0,"field": "fieldname1","quant": 1,"sid": ""}],"app_service_1": "Service 1","app_status_1": "Pending","app_duration_1": 60,"app_price_1": 1,"app_date_1": "04\/13\/2024","app_slot_1": "10:00\/11:00","app_starttime_1": "10:00 AM","app_endtime_1": "11:00 AM","app_quantity_1": 1,"formid": 1,"formname": "Form 1","referrer": "https:\/\/example.com\/wp-admin\/admin.php?page=cp_apphourbooking&addbk=1&cal=1&r=0.7819147291131667","fieldname1": " - 04\/13\/2024 10:00 AM - 11:00 AM (Service 1)\n","email": "johnd@yopmail.com","username": "admin","itemnumber": 1},"response_type":"sample"}', true );// @phpcs:ignore } return $context; } /** * Prepare mailmint contact status. * * @param array $data Search Params. * * @return array */ public function search_mail_mint_fetch_custom_fields( $data ) { $options = [ [ 'label' => 'Yes', 'value' => 'true', ], [ 'label' => 'No', 'value' => 'false', ], ]; return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Mail Mint custom fields * * @param array $data data. * * @return array */ public function search_mail_mint_custom_fields( $data ) { global $wpdb; $fields = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'mint_custom_fields' ); return (array) $fields; } /** * Get Mail Mint lists * * @param array $data data. * * @return array|void */ public function search_mail_mint_contacts( $data ) { if ( ! class_exists( 'Mint\MRM\DataBase\Models\ContactModel' ) ) { return []; } $contacts = ContactModel::get_all(); $options = []; if ( ! empty( $contacts ) ) { foreach ( $contacts['data'] as $contact ) { $options[] = [ 'label' => $contact['email'], 'value' => $contact['id'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get mail mint Last Data * * @param array $data data. * * @return array */ public function search_mail_mint_last_data( $data ) { if ( ! class_exists( 'Mint\MRM\DataBase\Models\ContactModel' ) || ! class_exists( 'Mint\MRM\DataBase\Models\ContactGroupModel' ) ) { return []; } $context = []; global $wpdb; $contact_id = isset( $data['filter']['contact_id']['value'] ) ? $data['filter']['contact_id']['value'] : -1; $term = $data['search_term'] ? $data['search_term'] : ''; $type = 'lists'; if ( 'mail_mint_tags_added_to_contact' === $term ) { $type = 'tags'; } $data = []; if ( -1 == $contact_id ) { $result = $wpdb->get_row( $wpdb->prepare( "SELECT relation.id as rid, relation.contact_id, cgroups.* FROM {$wpdb->prefix}mint_contact_group_relationship AS relation JOIN {$wpdb->prefix}mint_contact_groups AS cgroups ON cgroups.id = relation.group_id WHERE cgroups.type = %s ORDER BY rid DESC Limit 1", $type ) ); } else { $result = $wpdb->get_row( $wpdb->prepare( "SELECT relation.id as rid, relation.contact_id, cgroups.* FROM {$wpdb->prefix}mint_contact_group_relationship AS relation JOIN {$wpdb->prefix}mint_contact_groups AS cgroups ON cgroups.id = relation.group_id WHERE cgroups.type = %s AND relation.contact_id =%d ORDER BY rid DESC Limit 1", $type, $contact_id ) ); } if ( ! empty( $result ) ) { $contact_id = $result->contact_id; $data['contact'] = ContactModel::get( $contact_id ); $data[ $type ] = ContactGroupModel::get( $result->id ); } if ( ! empty( $data ) ) { $context['pluggable_data'] = $data; $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"contact":{"id":"10","wp_user_id":"0","hash":"96eb6293345a2b54246a3214d2419948","email":"john2@test.com","first_name":"John","last_name":"Doe","scores":"0","source":"WebHook","status":"subscribed","stage":"","last_activity":null,"created_by":"0","created_at":"2024-04-09 10:28:56","updated_at":null,"meta_fields":{"dropdown":"New","radio":"One","checkbox":["One"],"status_changed":"subscribed"}},"' . $type . '":{"id":"3","title":"new","type":"tags","data":null,"created_at":"2024-04-09 11:23:11","updated_at":null}},"response_type":"sample"}', true ); } return (array) $context; } /** * Get Simple Schedule Appointment Types * * @param array $data data. * * @return array */ public function search_simple_schedule_appointment_types( $data ) { global $wpdb; $appointment_types = $wpdb->get_results( 'SELECT title, id FROM ' . $wpdb->prefix . 'ssa_appointment_types' ); $options = []; if ( ! empty( $appointment_types ) ) { foreach ( $appointment_types as $appointment_type ) { $options[] = [ 'label' => $appointment_type->title, 'value' => $appointment_type->id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get mail mint Last Data * * @param array $data data. * * @return array */ public function search_ssa_last_data( $data ) { $context = []; global $wpdb; $appointment_type_id = isset( $data['filter']['appointment_type_id']['value'] ) ? $data['filter']['appointment_type_id']['value'] : -1; $term = $data['search_term'] ? $data['search_term'] : ''; $status = 'booked'; if ( 'ssa_appointment_cancelled' === $term ) { $status = 'canceled'; } $data = []; if ( -1 == $appointment_type_id ) { $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}ssa_appointments WHERE status = %s ORDER BY id DESC Limit 1", $status ), ARRAY_A ); } else { $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}ssa_appointments where appointment_type_id=%d AND status = %s ORDER BY id DESC Limit 1", $appointment_type_id, $status ), ARRAY_A ); } if ( ! empty( $result ) ) { $result_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}ssa_appointment_meta where appointment_id=%d", $result['id'] ) ); if ( ! empty( $result_meta ) ) { foreach ( $result_meta as $meta ) { $result[ $meta->meta_key ] = $meta->meta_value; } } } if ( ! empty( $result ) ) { $result['customer_information'] = json_decode( $result['customer_information'], true ); $context['pluggable_data'] = $result; $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"id":"4","appointment_type_id":"1","rescheduled_from_appointment_id":"0","rescheduled_to_appointment_id":"0","group_id":"0","author_id":"1","customer_id":"0","customer_information":{"Name":"John Doe","Email":"johndoe@email.com"},"customer_timezone":"Asia\/Calcutta","customer_locale":"en_US","start_date":"2024-04-22 03:30:00","end_date":"2024-04-22 04:00:00","title":"","description":"","payment_method":"","payment_received":"0.00","mailchimp_list_id":"","google_calendar_id":"","google_calendar_event_id":"","web_meeting_password":"","web_meeting_id":"","web_meeting_url":"","allow_sms":"","status":"booked","date_created":"2024-04-18 09:19:14","date_modified":"2024-04-18 09:19:14","expiration_date":"0000-00-00 00:00:00"},"response_type":"sample"}', true ); } return (array) $context; } /** * Get Simple Schedule Appointment Types * * @param array $data data. * * @return array */ public function search_simple_schedule_appointments( $data ) { global $wpdb; $appointment_types = $wpdb->get_results( 'SELECT title, id FROM ' . $wpdb->prefix . 'ssa_appointment_types' ); $options = []; if ( ! empty( $appointment_types ) ) { foreach ( $appointment_types as $appointment_type ) { $options[] = [ 'label' => $appointment_type->title, 'value' => $appointment_type->id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Sensei LMS Lessons * * @param array $data data. * * @return array */ public function search_sensei_lms_lessons( $data ) { if ( ! function_exists( 'Sensei' ) ) { return []; } $course_id = $data['dynamic']; $lessons = \Sensei()->course->course_lessons( $course_id, 'publish', 'ids' ); $options = []; if ( ! empty( $lessons ) ) { foreach ( $lessons as $lesson ) { $options[] = [ 'label' => get_the_title( $lesson ), 'value' => $lesson, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Sensei LMS Quiz List * * @param array $data data. * * @return array */ public function search_sensei_lms_quiz( $data ) { $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $quizes = get_posts( [ 'post_type' => 'lesson', 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', 'posts_per_page' => $limit, 'offset' => $offset, 'fields' => 'ids', 'meta_query' => [ 'relation' => 'AND', [ 'key' => '_lesson_quiz', 'compare' => 'EXISTS', ], [ 'key' => '_quiz_has_questions', 'value' => 1, 'compare' => '=', ], ], ] ); $options = []; $total_quizes = get_posts( [ 'post_type' => 'lesson', 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => [ 'relation' => 'AND', [ 'key' => '_lesson_quiz', 'compare' => 'EXISTS', ], [ 'key' => '_quiz_has_questions', 'value' => 1, 'compare' => '=', ], ], ] ); $count = count( $total_quizes ); if ( ! empty( $quizes ) ) { foreach ( $quizes as $quiz ) { $options[] = [ 'label' => get_the_title( $quiz ), 'value' => $quiz, ]; } } return [ 'options' => $options, 'hasMore' => $count > $limit && $count > $offset, ]; } /** * Get Sensei LMS trigger Last Data * * @param array $data data. * * @return array|mixed|string */ public function search_sensei_lms_triggers_last_data( $data ) { $context = []; global $wpdb; $term = $data['search_term']; if ( ! function_exists( 'Sensei' ) ) { return; } if ( 'course_completed' == $term ) { $comment_type = 'sensei_course_status'; $course_id = $data['filter']['sensei_course']['value']; if ( -1 === $course_id ) { $sql = "SELECT * FROM {$wpdb->prefix}comments WHERE comment_approved = %s AND comment_type = %s ORDER BY comment_ID DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'complete', $comment_type ), ARRAY_A );// @phpcs:ignore } else { $sql = "SELECT * FROM {$wpdb->prefix}comments WHERE comment_approved = %s AND comment_type = %s AND comment_post_ID = %d ORDER BY comment_ID DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'complete', $comment_type, $course_id ), ARRAY_A );// @phpcs:ignore } } elseif ( 'course_enrolled' == $term ) { $comment_type = 'sensei_course_status'; $course_id = $data['filter']['sensei_course']['value']; if ( -1 === $course_id ) { $sql = "SELECT * FROM {$wpdb->prefix}comments WHERE comment_approved = %s AND comment_type = %s ORDER BY comment_ID DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'in-progress', $comment_type ), ARRAY_A );// @phpcs:ignore } else { $sql = "SELECT * FROM {$wpdb->prefix}comments WHERE comment_approved = %s AND comment_type = %s AND comment_post_ID = %d ORDER BY comment_ID DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'in-progress', $comment_type, $course_id ), ARRAY_A );// @phpcs:ignore } } elseif ( 'lesson_completed' == $term ) { $lesson_id = $data['filter']['sensei_lesson']['value']; $course_id = $data['filter']['sensei_course']['value']; $comment_type = 'sensei_lesson_status'; if ( -1 === $lesson_id ) { $sql = "SELECT comments.*, meta.* FROM {$wpdb->prefix}comments as comments LEFT JOIN {$wpdb->prefix}postmeta as meta ON comments.comment_post_ID = meta.post_id WHERE comments.comment_approved = %s AND comments.comment_type = %s AND meta.meta_key = %s AND meta.meta_value = %d ORDER BY comments.comment_ID DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'complete', $comment_type, '_lesson_course', $course_id ), ARRAY_A );// @phpcs:ignore } else { $sql = "SELECT * FROM {$wpdb->prefix}comments WHERE comment_approved = %s AND comment_type = %s AND comment_post_ID = %d ORDER BY comment_ID DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'complete', $comment_type, $lesson_id ), ARRAY_A );// @phpcs:ignore } } elseif ( 'quiz_attempted' == $term || 'quiz_passes' == $term || 'quiz_fails' == $term ) { $quiz_id = $data['filter']['sensei_quiz']['value']; $comment_type = 'sensei_lesson_status'; if ( 'quiz_passes' == $term ) { $status = "( comment_approved = 'passed' )"; } elseif ( 'quiz_fails' == $term ) { $status = "( comment_approved = 'failed' )"; } else { $status = "( comment_approved = 'failed' OR comment_approved = 'passed' )"; } if ( -1 === $quiz_id ) { $sql = "SELECT * FROM {$wpdb->prefix}comments WHERE comment_type = %s AND $status ORDER BY comment_ID DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, $comment_type ), ARRAY_A );// @phpcs:ignore } else { $sql = "SELECT * FROM {$wpdb->prefix}comments WHERE comment_type = %s AND $status AND comment_post_ID = %d ORDER BY comment_ID DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, $comment_type, $quiz_id ), ARRAY_A );// @phpcs:ignore } } elseif ( 'quiz_completion' == $term ) { $quiz_id = $data['filter']['sensei_quiz']['value']; $comment_type = 'sensei_lesson_status'; $condition_compare = $data['filter']['condition_compare']['value']; $percentage = $data['filter']['percentage']['value']; if ( -1 === $quiz_id ) { $results = $wpdb->get_results( $wpdb->prepare( "SELECT comments.*, meta.meta_key, meta.meta_value FROM wp_comments AS comments JOIN wp_commentmeta AS meta ON comments.comment_ID = meta.comment_id WHERE meta.meta_key LIKE %s AND meta.meta_value $condition_compare %d ORDER BY comments.comment_ID DESC LIMIT 1", 'grade', $percentage ), ARRAY_A ); //phpcs:ignore } else { $results = $wpdb->get_results( $wpdb->prepare( "SELECT comments.*, meta.meta_key, meta.meta_value FROM wp_comments AS comments JOIN wp_commentmeta AS meta ON comments.comment_ID = meta.comment_id WHERE comments.comment_post_ID = %d AND meta.meta_key LIKE %s AND meta.meta_value $condition_compare %d ORDER BY comments.comment_ID DESC LIMIT 1", $quiz_id, 'grade', $percentage ), ARRAY_A ); //phpcs:ignore } } if ( ! empty( $results ) ) { $post = get_post( $results[0]['comment_post_ID'] ); $context['pluggable_data'] = WordPress::get_user_context( $results[0]['user_id'] ); if ( 'course_completed' == $term || 'course_enrolled' == $term ) { $context['pluggable_data']['sensei_course'] = $results[0]['comment_post_ID']; if ( $post instanceof \WP_Post ) { $context['pluggable_data']['course_title'] = $post->post_title; } } elseif ( 'lesson_completed' == $term ) { $context['pluggable_data']['sensei_lesson'] = $results[0]['comment_post_ID']; if ( $post instanceof \WP_Post ) { $context['pluggable_data']['lesson_title'] = $post->post_title; } } elseif ( 'quiz_attempted' == $term || 'quiz_passes' == $term || 'quiz_fails' == $term || 'quiz_completion' == $term ) { $lesson_quiz = get_post_meta( $results[0]['comment_post_ID'], '_lesson_quiz', true ); $submission = \Sensei()->quiz_submission_repository->get( $lesson_quiz, $results[0]['user_id'] ); if ( $post instanceof \WP_Post ) { $context['pluggable_data']['quiz_title'] = $post->post_title; } $context['pluggable_data']['quiz_status'] = $results[0]['comment_approved']; $context['pluggable_data']['quiz_data']['id'] = $submission->get_id(); $context['sensei_quiz'] = $submission->get_id(); $context['pluggable_data']['quiz_data']['final_grade'] = $submission->get_final_grade(); $context['pluggable_data']['quiz_data']['created_at'] = $submission->get_created_at(); } $context['response_type'] = 'live'; } else { if ( 'course_completed' == $term || 'course_enrolled' == $term ) { $context = json_decode( '{"pluggable_data":{"wp_user_id": 48,"user_login": "john@yopmail.com","display_name": "john@yopmail.com","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["subscriber"],"sensei_course": "7500","course_title": "Course 1"},"response_type":"sample"}', true );// @phpcs:ignore } elseif ( 'lesson_completed' == $term ) { $context = json_decode( '{"pluggable_data":{"wp_user_id": 48,"user_login": "john@yopmail.com","display_name": "john@yopmail.com","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["subscriber"],"sensei_lesson": "7502","lesson_title": "Lesson 1"},"response_type":"sample"}', true );// @phpcs:ignore } elseif ( 'quiz_attempted' == $term || 'quiz_passes' == $term || 'quiz_fails' == $term || 'quiz_completion' == $term ) { $context = json_decode( '{"pluggable_data":{"wp_user_id":2,"user_login":"johnd","display_name":"john d","user_firstname":"john","user_lastname":"d","user_email":"johnd@email.com","user_role":[],"quiz_title":"Lesson 2","quiz_status":"passed","quiz_data":{"id":27,"final_grade":100,"created_at":{"date":"2024-05-07 06:54:31.000000","timezone_type":1,"timezone":"+00:00"}}},"response_type":"sample"}', true );// @phpcs:ignore } } return $context; } /** * Get SurelyWP Services - SureCart Addons Last Data * * @param array $data data. * * @return array */ public function search_services_sc_triggers_last_data( $data ) { $context = []; global $wpdb; $term = $data['search_term'] ? $data['search_term'] : ''; $data = []; if ( 'new_service_created' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}surelywp_sv_services WHERE service_status LIKE 'service_created' ORDER BY service_id DESC Limit 1", ARRAY_A ); } elseif ( 'requirement_submitted' === $term ) { $result = $wpdb->get_row( "SELECT created_at FROM {$wpdb->prefix}surelywp_sv_requirements ORDER BY created_at DESC Limit 1", ARRAY_A ); } elseif ( 'message_sent' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}surelywp_sv_messages ORDER BY message_id DESC Limit 1", ARRAY_A ); } elseif ( 'message_final_delivery_sent' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}surelywp_sv_messages WHERE is_final_delivery = 1 ORDER BY message_id DESC Limit 1", ARRAY_A ); } elseif ( 'customer_request_revision' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}surelywp_sv_services WHERE service_status LIKE 'service_start' ORDER BY service_id DESC Limit 1", ARRAY_A ); } elseif ( 'customer_approves_final_delivery' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}surelywp_sv_services WHERE service_status LIKE 'service_complete' ORDER BY service_id DESC Limit 1", ARRAY_A ); } elseif ( 'delivery_date_changed' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}surelywp_sv_services WHERE delivery_date IS NOT NULL ORDER BY service_id DESC Limit 1", ARRAY_A ); } elseif ( 'service_cancel' === $term || 'service_marked_canceled' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}surelywp_sv_services WHERE service_status LIKE 'service_canceled' ORDER BY service_id DESC Limit 1", ARRAY_A ); } elseif ( 'service_completed' === $term || 'service_mark_completed' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}surelywp_sv_services WHERE service_status LIKE 'service_complete' ORDER BY service_id DESC Limit 1", ARRAY_A ); } elseif ( 'contract_signed' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}surelywp_sv_contracts ORDER BY contract_id DESC Limit 1", ARRAY_A ); } if ( ! empty( $result ) ) { if ( 'new_service_created' === $term ) { $service_data = [ 'service_setting_id' => $result['service_id'], 'order_id' => $result['order_id'], 'product_id' => $result['product_id'], 'service_status' => $result['service_status'], 'delivery_date' => $result['delivery_date'], ]; $context['pluggable_data'] = array_merge( $service_data, WordPress::get_user_context( $result['user_id'] ) ); $context['response_type'] = 'live'; } elseif ( 'requirement_submitted' === $term ) { $requirements_data = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}surelywp_sv_requirements WHERE created_at = %s", $result['created_at'] ), ARRAY_A ); $service_result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}surelywp_sv_services WHERE service_id = %d", $requirements_data[0]['service_id'] ), ARRAY_A ); $user_data = WordPress::get_user_context( $service_result['user_id'] ); unset( $service_result['user_id'] ); $context['pluggable_data'] = array_merge( $requirements_data, $service_result, $user_data ); foreach ( $requirements_data as $value ) { if ( 'file' == $value['requirement_type'] ) { $upload_dir = wp_upload_dir(); $attachment_file_names = json_decode( $value['requirement'], true ); foreach ( (array) $attachment_file_names as $attachment_file_name ) { $context['pluggable_data']['requirement_attachment_file'][] = $upload_dir['baseurl'] . '/surelywp-services-data/' . $value['service_id'] . '/requirement/' . $attachment_file_name; } } } $context['response_type'] = 'live'; } elseif ( 'message_sent' === $term || 'message_final_delivery_sent' === $term ) { $message_data = [ 'sender' => WordPress::get_user_context( $result['sender_id'] ), 'receiver' => WordPress::get_user_context( $result['receiver_id'] ), 'service_id' => $result['service_id'], 'message_text' => $result['message_text'], 'attachment_file_name' => $result['attachment_file_name'], 'is_final_delivery' => $result['is_final_delivery'], ]; $context['pluggable_data'] = $message_data; $upload_dir = wp_upload_dir(); $attachment_file_names = json_decode( $result['attachment_file_name'], true ); foreach ( (array) $attachment_file_names as $attachment_file_name ) { $context['pluggable_data']['attachment_file'][] = $upload_dir['baseurl'] . '/surelywp-services-data/' . $result['service_id'] . '/messages/' . $attachment_file_name; } $context['response_type'] = 'live'; } elseif ( 'customer_request_revision' === $term ) { $message_result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}surelywp_sv_messages WHERE service_id = %d AND is_final_delivery = %d ORDER BY message_id DESC LIMIT 1", $result['service_id'], 1 ), ARRAY_A ); if ( ! empty( $message_result ) ) { global $surelywp_sv_model; $revision_message = $surelywp_sv_model->surelywp_sv_get_customer_revision_msg( $message_result['service_id'], $message_result['message_id'] ); $context['pluggable_data'] = array_merge( $result, $revision_message ); $context['pluggable_data']['sender'] = WordPress::get_user_context( $revision_message['sender_id'] ); $context['pluggable_data']['receiver'] = WordPress::get_user_context( $revision_message['receiver_id'] ); $upload_dir = wp_upload_dir(); $attachment_file_names = json_decode( $revision_message['attachment_file_name'], true ); foreach ( (array) $attachment_file_names as $attachment_file_name ) { $context['pluggable_data']['attachment_file'][] = $upload_dir['baseurl'] . '/surelywp-services-data/' . $revision_message['service_id'] . '/messages/' . $attachment_file_name; } $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"service_id":"6","service_setting_id":"kXg4Exmj","user_id":"51","order_id":"16574f7f-66d8-466e-8716-8da9671e6668","product_id":"f59f62cc-fd70-4007-8bcf-56d07f1ac871","service_status":"service_start","delivery_date":"2024-08-29","created_at":"2024-08-25 22:42:57","updated_at":null,"message_id":"13","sender_id":"41","receiver_id":"0","message_text":"This is the final revision","attachment_file_name":"[\"test_copy-1724605977.pdf\",\"test-1724605977.pdf\"]","is_final_delivery":"0","is_approved_delivery":null,"sender":{"wp_user_id":41,"user_login":"john@example.com","display_name":"john@example.com","user_firstname":"john","user_lastname":"d","user_email":"john@example.com","user_registered":"2023-01-30 09:34:54","user_role":["customer"]},"receiver":[],"attachment_file":["https://example.com/wp-content/uploads/surelywp-services-data/6/messages/test_copy-1724605977.pdf","https://example.com/wp-content/uploads/surelywp-services-data/6/messages/test-1724605977.pdf"]},"response_type":"sample"}', true ); } } elseif ( 'customer_approves_final_delivery' === $term || 'delivery_date_changed' === $term || 'service_cancel' === $term || 'service_marked_canceled' === $term || 'service_completed' === $term || 'service_mark_completed' === $term ) { $user_data = WordPress::get_user_context( $result['user_id'] ); unset( $result['user_id'] ); $context['pluggable_data'] = array_merge( $result, $user_data ); $context['response_type'] = 'live'; } elseif ( 'contract_signed' === $term ) { $contract_data = [ 'service_id' => $result['service_id'], 'signature' => $result['signature'], 'contract_details' => $result['contract_details'], ]; $service_result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}surelywp_sv_services WHERE service_id = %d", $result['service_id'] ), ARRAY_A ); $user_data = WordPress::get_user_context( $service_result['user_id'] ); unset( $service_result['user_id'] ); $context['pluggable_data'] = array_merge( $contract_data, $user_data, $service_result ); $context['response_type'] = 'live'; } } else { if ( 'new_service_created' === $term || 'customer_request_revision' === $term || 'customer_approves_final_delivery' === $term || 'delivery_date_changed' === $term ) { $context = json_decode( '{"pluggable_data":{"service_setting_id":"3","order_id":"81ac6e4f-1f8a-4f8b-a3d1-37fba6c8f893","product_id":"f59f62cc-fd70-4007-8bcf-56d07f1ac871","service_status":"service_created","delivery_date":null,"wp_user_id":84,"user_login":"johnd@example.com","display_name":"johnd@example.com","user_firstname":"John","user_lastname":"D","user_email":"johnd@example.com","user_registered":"2023-02-02 13:08:44","user_role":["customer"]},"response_type":"sample"}', true ); } elseif ( 'requirement_submitted' === $term ) { $context = json_decode( '{"pluggable_data":{"0":{"requirement_id":"6","service_id":"7","requirement_type":"textarea","requirement_title":"TestReq","requirement_desc":"This is a testing requirement","requirement":"This is my requirements.","created_at":"2024-08-26 10:27:33","updated_at":null},"1":{"requirement_id":"7","service_id":"7","requirement_type":"file","requirement_title":"Upload Photos","requirement_desc":"Please upload reference photos","requirement":"[\"test_copy-1724648253.pdf\",\"test-1724648253.pdf\"]","created_at":"2024-08-26 10:27:33","updated_at":null},"service_id":"7","service_setting_id":"kXg4Exmj","order_id":"16574f7f-66d8-466e-8716-8da9671e6668","product_id":"f59f62cc-fd70-4007-8bcf-56d07f1ac871","service_status":"service_start","delivery_date":"2024-08-29","created_at":"2024-08-26 10:22:31","updated_at":"2024-08-26 04:57:36","wp_user_id":51,"user_login":"johnd@example.com","display_name":"johnd@example.com","user_firstname":"john","user_lastname":"d","user_email":"johnd@example.com","user_registered":"2023-02-02 07:12:46","user_role":["customer"],"requirement_attachment_file":["https://example.com/wp-content/uploads/surelywp-services-data/7/requirement/test_copy-1724648253.pdf","https://example.com/wp-content/uploads/surelywp-services-data/7/requirement/test-1724648253.pdf"]},"response_type":"sample"}', true ); } elseif ( 'message_sent' === $term || 'message_final_delivery_sent' === $term ) { $context = json_decode( '{"pluggable_data":{"sender":{"wp_user_id":84,"user_login":"johnd@example.com","display_name":"johnd@example.com","user_firstname":"john","user_lastname":"d","user_email":"johnd@example.com","user_registered":"2023-02-02 13:08:44","user_role":["customer"]},"receiver_id": {"wp_user_id":8,"user_login":"johnde@example.com","display_name":"johnde@example.com","user_firstname":"johnd","user_lastname":"ed","user_email":"johnde@example.com","user_registered":"2023-02-02 13:08:44","user_role":["admin"]},"service_id": "1","message_text": "Message Text","attachment_file_name": "Attachment File Name","is_final_delivery": "1", "attachment_file":["https://example.com/wp-content/uploads/surelywp-services-data/6/messages/test_copy-1724605977.pdf","https://example.com/wp-content/uploads/surelywp-services-data/6/messages/test-1724605977.pdf"]},"response_type":"sample"}', true ); } elseif ( 'service_cancel' === $term ) { $context = json_decode( '{"pluggable_data":{"delivery_date": null,"order_id": "a3830048-9a43-4088-a78e-285537f16ecc","product_id": "f59f62cc-fd70-4007-8bcf-56d07f1ac871","service_setting_id": "2","service_status": "service_canceled","wp_user_id":84,"user_login":"johnd@example.com","display_name":"johnd@example.com","user_firstname":"John","user_lastname":"D","user_email":"johnd@example.com","user_registered":"2023-02-02 13:08:44","user_role":["customer"]},"response_type":"sample"}', true ); } elseif ( 'service_marked_canceled' === $term || 'service_completed' === $term || 'service_mark_completed' === $term ) { $context = json_decode( '{"pluggable_data":{"delivery_date": null,"order_id": "a3830048-9a43-4088-a78e-285537f16ecc","product_id": "f59f62cc-fd70-4007-8bcf-56d07f1ac871","service_setting_id": "2","service_status": "service_completed","wp_user_id":84,"user_login":"johnd@example.com","display_name":"johnd@example.com","user_firstname":"John","user_lastname":"D","user_email":"johnd@example.com","user_registered":"2023-02-02 13:08:44","user_role":["customer"]},"response_type":"sample"}', true ); } elseif ( 'contract_signed' === $term ) { $context = json_decode( '{"pluggable_data":{"service_id":"4","signature":"signature","contract_details":"Contract Details","wp_user_id":84,"user_login":"johnd@example.com","display_name":"johnd@example.com","user_firstname":"John","user_lastname":"D","user_email":"johnd@example.com","user_registered":"2023-02-02 13:08:44","user_role":["customer"],"service_setting_id":"u2pDYtDF","user_id":"84","order_id":"8e8ca710-13cd-4c94-8de5-98a19a3b9de6","product_id":"a39c7d4f-50bd-49ba-b56c-4f17aac61306","service_status":"service_start","delivery_date":"2024-08-25","created_at":"2024-08-22 15:15:27","updated_at":"2024-08-22 09:46:02"},"response_type":"sample"}', true ); } } return (array) $context; } /** * Get SurelyWP Support Portal - SureCart Addons Last Data * * @param array $data data. * * @return array */ public function search_sc_support_portal_triggers_last_data( $data ) { $context = []; if ( ! class_exists( 'Surelywp_Support_Portal' ) ) { return []; } global $wpdb; $term = $data['search_term'] ? $data['search_term'] : ''; $data = []; if ( 'new_ticket_created' === $term || 'ticket_status_changed' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}surelywp_sp_support WHERE support_status = 1 ORDER BY support_id DESC Limit 1", ARRAY_A ); } elseif ( 'new_message_sent' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}surelywp_sp_messages ORDER BY message_id DESC Limit 1", ARRAY_A ); } elseif ( 'tickets_closed' === $term ) { $result = $wpdb->get_results( "SELECT support_id FROM {$wpdb->prefix}surelywp_sp_support WHERE support_status = 0 AND updated_at IN ( SELECT updated_at FROM {$wpdb->prefix}surelywp_sp_support WHERE support_status = 0 GROUP BY updated_at HAVING COUNT(*) > 1);", ARRAY_A ); } elseif ( 'tickets_opens' === $term ) { $result = $wpdb->get_results( "SELECT support_id FROM {$wpdb->prefix}surelywp_sp_support WHERE support_status = 3 AND updated_at IN ( SELECT updated_at FROM {$wpdb->prefix}surelywp_sp_support WHERE support_status = 3 GROUP BY updated_at HAVING COUNT(*) > 1);", ARRAY_A ); } elseif ( 'new_email_message_fetched' === $term ) { $context = json_decode( '{"pluggable_data":{"mail_id": 21,"mail_message_id": 20,"mail_references": "test","mail_subject": "test","sender_type": "admin","sender_id": 1,"receiver_id": 1,"support_id": 1,"message_text": "test","attachment_tmp_paths": "var/www","attachment_file_name": "test.png","created_at": "2024-10-10 00:00:00"},"response_type":"sample"}', true ); } if ( ! empty( $result ) ) { if ( 'new_ticket_created' === $term || 'ticket_status_changed' === $term ) { $support_res = $wpdb->get_results( $wpdb->prepare( "SELECT field_label, field_value FROM {$wpdb->prefix}surelywp_sp_support_form_fields WHERE support_id = %d", $result['support_id'] ), ARRAY_A ); $support_data = [ 'support_id' => $result['support_id'], 'order_id' => $result['order_id'], 'product_id' => $result['product_id'], 'support_title' => $result['support_title'], 'support_status' => Surelywp_Support_Portal::surelywp_sp_get_support_status( $result['support_status'] ), 'support_data' => $support_res, ]; $context['pluggable_data'] = array_merge( $support_data, WordPress::get_user_context( $result['user_id'] ) ); $context['response_type'] = 'live'; } elseif ( 'tickets_closed' === $term || 'tickets_opens' === $term ) { $support_data = []; $support_ids = $result; foreach ( $support_ids as $key => $id ) { $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}surelywp_sp_support WHERE support_id = %d", $id ), ARRAY_A ); $support_res = $wpdb->get_results( $wpdb->prepare( "SELECT field_label, field_value FROM {$wpdb->prefix}surelywp_sp_support_form_fields WHERE support_id = %d", $id ), ARRAY_A ); $support_data[ $key ] = WordPress::get_user_context( $result['user_id'] ); $support_data[ $key ] = [ 'support_id' => $result['support_id'], 'order_id' => $result['order_id'], 'product_id' => $result['product_id'], 'support_title' => $result['support_title'], 'support_status' => Surelywp_Support_Portal::surelywp_sp_get_support_status( $result['support_status'] ), 'support_data' => $support_res, ]; } $context['pluggable_data'] = $support_data; $context['response_type'] = 'live'; } elseif ( 'new_message_sent' === $term ) { $upload_dir = wp_upload_dir(); $support_data = [ 'sender_id' => $result['sender_id'], 'receiver_id' => $result['receiver_id'], 'support_id' => $result['support_id'], 'message_text' => $result['message_text'], 'sender' => WordPress::get_user_context( $result['sender_id'] ), 'receiver' => WordPress::get_user_context( $result['receiver_id'] ), ]; if ( ! empty( $result['attachment_file_name'] ) ) { $attachment_file_names = json_decode( $result['attachment_file_name'], true ); foreach ( (array) $attachment_file_names as $attachment_file_name ) { $support_data['attachment_file'][] = $upload_dir['baseurl'] . '/surelywp-support-portal-data/' . $result['support_id'] . '/messages/' . $attachment_file_name; } } $context['pluggable_data'] = $support_data; $context['response_type'] = 'live'; } } else { if ( 'new_ticket_created' === $term || 'ticket_status_changed' === $term ) { $context = json_decode( '{"pluggable_data":{"support_id":"1","order_id":"0d0c3a6a-9846-42d0-9bc2-84485985358c","product_id":"a39c7d4f-50bd-49ba-b56c-4f17aac61306","support_title":"Not Delivered","support_status":"Closed","wp_user_id":84,"user_login":"johnd@gmail.com","display_name":"john","user_firstname":"john","user_lastname":"john","user_email":"johnd@gmail.com","user_registered":"2023-02-02 13:08:44","user_role":["customer"]},"response_type":"sample"}', true ); } elseif ( 'tickets_closed' === $term || 'tickets_opens' === $term ) { $context = json_decode( '{"pluggable_data":[{"support_id":"1","order_id":"0d0c3a6a-9846-42d0-9bc2-84485985358c","product_id":"a39c7d4f-50bd-49ba-b56c-4f17aac61306","support_title":"Not Delivered","support_status":"Closed"}],"response_type":"sample"}', true ); } elseif ( 'new_message_sent' === $term ) { $context = json_decode( '{"pluggable_data":{"sender_id":"1","receiver_id":"84","support_id":"2","message_text":"
asdasd
","sender":{"wp_user_id":1,"user_login":"johnd","display_name":"johnd","user_firstname":"john","user_lastname":"d","user_email":"johnd@example.com","user_registered":"2023-01-16 09:23:31","user_role":{"0":"customer"}},"receiver":{"wp_user_id":84,"user_login":"johnd@gmail.com","display_name":"johnd","user_firstname":"johnny","user_lastname":"d","user_email":"johndd@gmail.com","user_registered":"2023-02-02 13:08:44","user_role":["customer"]}},"response_type":"sample"}', true ); } } return (array) $context; } /** * Get Fluent Boards Last Data * * @param array $data data. * * @return array */ public function search_fbs_triggers_last_data( $data ) { if ( ! class_exists( '\FluentBoards\App\Models\Stage' ) ) { return []; } global $wpdb; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; if ( ! class_exists( 'FluentBoards\App\Models\Board' ) || ! class_exists( 'FluentBoards\App\Models\User' ) ) { return []; } $context = []; $result = null; switch ( $term ) { case 'board_created': $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fbs_boards ORDER BY id DESC LIMIT 1", ARRAY_A ); break; case 'board_member_added': $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fbs_relations WHERE object_type = 'board_user' ORDER BY id DESC LIMIT 1", ARRAY_A ); break; case 'task_created': $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fbs_tasks ORDER BY id DESC LIMIT 1", ARRAY_A ); break; case 'stage_changed': $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fbs_tasks ORDER BY id DESC LIMIT 1", ARRAY_A ); break; } if ( ! empty( $result ) ) { switch ( $term ) { case 'board_created': $context['pluggable_data'] = \FluentBoards\App\Models\Board::findOrFail( $result['id'] ); $context['response_type'] = 'live'; break; case 'board_member_added': $context['pluggable_data']['board_id'] = $result['object_id']; $context['pluggable_data']['board_member'] = \FluentBoards\App\Models\User::find( $result['foreign_id'] ); $context['response_type'] = 'live'; break; case 'task_created': $stage_data = Stage::where( 'board_id', $result['board_id'] )->whereNull( 'archived_at' )->first(); $context['pluggable_data'] = [ 'id' => $result['id'], 'slug' => $result['slug'], 'title' => $result['title'], 'description' => $result['description'], 'type' => $result['type'], 'board_id' => $result['board_id'], 'stage_id' => $result['stage_id'], 'position' => $result['position'], 'priority' => $result['priority'], 'created_at' => $result['created_at'], 'created_by' => $result['created_by'], 'updated_at' => $result['updated_at'], 'settings' => unserialize( $result['settings'] ), 'stage' => $stage_data ? [ 'id' => $stage_data->id, 'slug' => $stage_data->slug, 'title' => $stage_data->title, 'type' => $stage_data->type, 'board_id' => $stage_data->board_id, 'position' => $stage_data->position, 'settings' => $stage_data->settings, 'created_at' => '', 'updated_at' => '', ] : null, ]; $context['response_type'] = 'live'; break; case 'stage_changed': $stage_data = Stage::where( 'board_id', $result['board_id'] )->whereNull( 'archived_at' )->first(); $user_result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}users ORDER BY id DESC LIMIT 1", ARRAY_A ); $context['pluggable_data'] = [ 'task' => [ 'id' => $result['id'], 'slug' => $result['slug'], 'title' => $result['title'], 'description' => $result['description'], 'type' => $result['type'], 'board_id' => $result['board_id'], 'stage_id' => $stage_data->id, 'position' => $result['position'], 'priority' => $result['priority'], 'created_at' => $result['created_at'], 'created_by' => $result['created_by'], 'updated_at' => $result['updated_at'], 'settings' => unserialize( $result['settings'] ), 'stage' => [ 'id' => $stage_data->id, 'slug' => $stage_data->slug, 'title' => $stage_data->title, 'type' => $stage_data->type, 'board_id' => $stage_data->board_id, 'position' => $stage_data->position, 'settings' => $stage_data->settings, 'created_at' => '', 'updated_at' => '', ], 'watchers' => [ [ 'ID' => $user_result['ID'], 'photo' => '', 'user_url' => $user_result['user_url'], 'user_email' => $user_result['user_email'], 'user_login' => $user_result['user_login'], 'user_status' => $user_result['user_status'], 'display_name' => $user_result['display_name'], 'user_nicename' => $user_result['user_nicename'], 'user_registered' => $user_result['user_registered'], 'pivot' => [ 'object_id' => $user_result['id'], 'created_at' => $user_result['created_at'], 'foreign_id' => $user_result['ID'], 'user_id' => $user_result['ID'], ], ], ], ], 'old_stage_id' => $stage_data->id, ]; $context['response_type'] = 'live'; break; } } else { switch ( $term ) { case 'board_created': $context = json_decode( '{"pluggable_data":{"id":2,"title":"testing","description":"This is a sample board.","type":"to-do","currency":"USD","background":{"color":"#d1d8e0","id":"solid_10"},"created_by":"1","isUserOnlyViewer":0},"response_type":"sample"}', true ); break; case 'board_member_added': $context = json_decode( '{"pluggable_data":{"board_id":"2","board_member":{"ID":1,"user_login":"johnd","display_name":"johnd"}},"response_type":"sample"}', true ); break; case 'task_created': $context = json_decode( '{"pluggable_data":{"id":"1001","slug":"sample-task","title":"Sample Task","description":"This is a sample task.","type":"task","board_id":"10","stage_id":"3","position":"1","priority":"medium","created_at":"2024-03-20 12:00:00","created_by":"1","updated_at":"2024-03-20 12:30:00","settings":[],"stage":{"id":"3","slug":"sample-stage","title":"Sample Stage","type":"default","board_id":"10","position":"1","settings":[],"created_at":"2024-03-19 10:00:00","updated_at":"2024-03-20 11:00:00"}},"response_type":"sample"}', true ); break; case 'stage_changed': $context = json_decode( '{"pluggable_data":{"id":"1002","slug":"changed-task","title":"Changed Task","description":"This task changed stages.","type":"task","board_id":"10","stage_id":"4","position":"2","priority":"high","created_at":"2024-04-01 10:00:00","created_by":"1","updated_at":"2024-04-01 12:00:00","settings":[],"stage":{"id":"4","slug":"new-stage","title":"New Stage","type":"default","board_id":"10","position":"2","settings":[],"created_at":"","updated_at":""},"old_stage_id":"3","watchers":[{"ID":71,"photo":"https://www.gravatar.com/avatar/e361de3380a6b977abf350619468ce4f?s=128&d=https%3A%2F%2Fui-avatars.com%2Fapi%2FJohn+Doe/128","user_url":"","user_email":"john@gmail.com","user_login":"john","user_status":0,"display_name":"John Doe","user_nicename":"john","user_registered":"2025-05-28 12:07:48","pivot":{"object_id":1002,"created_at":"2025-06-05T10:11:31+00:00","foreign_id":71,"user_id":71}}]},"response_type":"sample"}', true ); break; } } return (array) $context; } /** * Prepare FluentBoards Boards List. * * @param array $data Search Params. * @return array */ public function search_fbs_boards_list( $data ) { global $wpdb; $boards = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}fbs_boards", ARRAY_A ); $options = []; if ( ! empty( $boards ) ) { foreach ( $boards as $board ) { $options[] = [ 'label' => $board['title'], 'value' => $board['id'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare FluentBoards Subtask Groups List. * * @param array $data Search Params. * @return array */ public function search_fbs_subtask_groups_list( $data ) { global $wpdb; $task_id = isset( $data['dynamic'] ) ? sanitize_text_field( $data['dynamic'] ) : ''; $groups = $wpdb->get_results( $wpdb->prepare( "SELECT id, value FROM {$wpdb->prefix}fbs_task_metas WHERE task_id = %d AND `key` = %s", $task_id, 'group_name' ) ); $options = []; foreach ( $groups as $group ) { $options[] = [ 'label' => $group->value, 'value' => $group->id, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare FluentBoards Stages List. * * @param array $data Search Params. * @return array */ public function search_fbs_stages_list( $data ) { if ( ! class_exists( '\FluentBoards\App\Models\Stage' ) ) { return []; } $query = Stage::where( 'board_id', $data['dynamic'] )->whereNull( 'archived_at' ); $stages = $query->get(); $options = []; if ( ! empty( $stages ) ) { foreach ( $stages as $stage ) { $options[] = [ 'label' => $stage['title'], 'value' => $stage['id'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Profile Grid Last Data * * @param array $data data. * * @return array */ public function search_profile_grid_triggers_last_data( $data ) { $context = []; global $wpdb; $term = $data['search_term'] ? $data['search_term'] : ''; if ( 'user_added_group' === $term || 'user_removed_from_group' === $term || 'user_assigned_group_manager' === $term || 'user_unassigned_group_manager' === $term || 'membership_request_approved' === $term ) { $users = get_users( [ 'orderby' => 'meta_value', 'meta_key' => 'pm_group', 'order' => 'DESC', 'number' => 1, 'meta_query' => [ [ 'key' => 'pm_group', 'compare' => 'EXISTS', ], ], 'fields' => 'ids', ] ); } elseif ( 'payment_complete' === $term || 'payment_failed' === $term ) { $users = get_users( [ 'orderby' => 'meta_value', 'meta_key' => 'pm_group_payment_status', 'order' => 'DESC', 'number' => 1, 'meta_query' => [ [ 'key' => 'pm_group_payment_status', 'compare' => 'EXISTS', ], ], 'fields' => 'ids', ] ); } elseif ( 'membership_request' === $term ) { $results = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}promag_group_requests WHERE status = 1 ORDER BY id DESC Limit 1", ARRAY_A ); } if ( ! empty( $users ) ) { if ( 'user_added_group' === $term || 'user_removed_from_group' === $term || 'user_assigned_group_manager' === $term || 'user_unassigned_group_manager' === $term || 'payment_complete' === $term || 'payment_failed' === $term || 'membership_request_approved' === $term ) { $context = WordPress::get_user_context( $users[0] ); $user_groups = get_user_meta( $users[0], 'pm_group', true ); if ( is_array( $user_groups ) ) { $last_element = end( $user_groups ); $context['group_id'] = $last_element; $context = array_merge( $context, ProfileGrid::pg_group_details( $last_element ) ); } $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } } elseif ( ! empty( $results ) && 'membership_request' === $term ) { $context = WordPress::get_user_context( $results[0]['uid'] ); $context['group_id'] = $results[0]['gid']; $context = array_merge( $context, ProfileGrid::pg_group_details( $results[0]['gid'] ) ); $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } elseif ( 'group_manager_resets_password' === $term ) { $context = json_decode( '{"pluggable_data":{"wp_user_id":2,"user_login":"johnd@gmail.com","display_name":"JohnD","user_firstname":"johnd","user_lastname":"johnd","user_email":"johnd@gmail.com","user_registered":"2023-01-19 09:14:50","user_role":["editor"]},"response_type":"sample"}', true ); } elseif ( 'group_deleted' === $term ) { $context = json_decode( '{"pluggable_data":{"group_name":"Test Group","group_description":"Testing Group","group_id":"2"},"response_type":"sample"}', true ); } else { $context = json_decode( '{"pluggable_data":{"wp_user_id":2,"user_login":"johnd@gmail.com","display_name":"JohnD","user_firstname":"johnd","user_lastname":"johnd","user_email":"johnd@gmail.com","user_registered":"2023-01-19 09:14:50","user_role":["editor"],"group_id":"2","group_name":"Test Group","group_description":"Testing Group"},"response_type":"sample"}', true ); } return (array) $context; } /** * Get Fluent SMTP Last Data * * @param array $data data. * * @return array */ public function search_fluent_smtp_last_data( $data ) { $context = []; global $wpdb; $results = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fsmpt_email_logs WHERE status = 'failed' ORDER BY id DESC Limit 1", ARRAY_A ); if ( ! empty( $results ) ) { $context['to'] = unserialize( $results['to'] ); $context['from'] = $results['from']; $context['subject'] = $results['subject']; $context['body'] = $results['body']; $context['attachments'] = unserialize( $results['attachments'] ); $context['status'] = $results['status']; $context['response'] = unserialize( $results['response'] ); $context['headers'] = unserialize( $results['headers'] ); $context['extra'] = unserialize( $results['extra'] ); $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"to":[{"email":"johnd@example.com"}],"from":"johndThis is a sample message for the feed.
', 'type' => 'post', 'contenttype' => 'text', 'space_id' => 101, 'privacy' => 'public', 'status' => 'published', 'featuredimage' => 'https://example.com/image.jpg', 'meta' => [ 'previewdata' => 0, ], 'issticky' => false, 'commentscount' => 10, 'reactionscount' => 25, 'priority' => 'normal', 'expiredat' => null, 'scheduledat' => '2025-01-10 08:00:00', 'createdat' => '2025-01-09 09:00:00', 'updatedat' => '2025-01-09 10:00:00', 'space' => $sample_space_data, 'xprofile' => $sample_profile_data, ], ]; $context['response_type'] = 'sample'; } if ( 'space_feed_created' === $term ) { $conext['pluggable_data']['feed']['user'] = [ 'user_url' => 'https://example.com/user/profile', 'user_email' => 'user@example.com', 'user_login' => 'sampleuser', 'user_status' => 'active', 'display_name' => 'Sample User', 'user_nicename' => 'sample-user', 'user_registered' => '2024-01-01 00:00:00', ]; $context['pluggable_data']['feed']['space'] = $sample_space_data; $context['pluggable_data']['feed']['xprofile'] = $sample_profile_data; $context['response_type'] = 'sample'; } if ( 'user_joins_space' === $term ) { $context['pluggable_data'] = [ 'space' => [ $sample_space_data, 'membership' => [ 'ID' => 25, 'photo' => 'https://example.com/user-photo.jpg', 'pivot_role' => 'admin', 'pivot_status' => 'active', 'pivot_created_at' => '2025-01-24 09:00:00', 'pivot_user_id' => 25, 'pivot_space_id' => 100, 'user_url' => 'https://example.com/user-profile', 'user_email' => 'user@example.com', 'user_login' => 'sampleuser', 'user_status' => 'active', 'display_name' => 'Sample User', 'user_nicename' => 'sample-user', 'user_registered' => '2024-01-01 00:00:00', ], ], 'userId' => 1, 'by' => 'self', ]; $context['response_type'] = 'sample'; } if ( 'user_leaves_space' === $term ) { $context['pluggable_data'] = [ 'space' => $sample_space_data, 'user' => WordPress::get_sample_user_context(), 'userId' => 35, 'by' => 'self', ]; $context['response_type'] = 'sample'; } if ( 'new_comment_added' === $term || 'comment_updated' === $term ) { $context['pluggable_data'] = [ 'comment' => [ 'id' => 301, 'user_id' => 45, 'post_id' => 101, 'parent_id' => 0, 'reactions_count' => 5, 'message' => 'This is a sample comment message.', 'message_rendered' => 'This is a sample comment message.
', 'meta' => [ 'likes' => 3, 'shares' => 2, ], 'type' => 'text', 'content_type' => 'post', 'status' => 'approved', 'is_sticky' => false, 'created_at' => '2025-01-23 10:30:00', 'updated_at' => '2025-01-23 12:00:00', 'xprofile' => $sample_profile_data, ], ]; $context['response_type'] = 'sample'; } if ( 'course_deleted' === $term ) { $context['pluggable_data'] = [ 'course' => 2 ]; $context['response_type'] = 'sample'; } if ( 'comment_deleted' === $term ) { $context['pluggable_data'] = [ 'comment_id' => 1 ]; $context['response_type'] = 'sample'; } if ( 'user_enrolls_course' === $term || 'user_unenrolls_course' === $term || 'user_completes_course' === $term ) { $context['pluggable_data'] = [ 'course' => $sample_space_data, 'user' => WordPress::get_sample_user_context(), 'userId' => 1, ]; $context['response_type'] = 'sample'; } if ( 'course_created' === $term || 'course_updated' === $term || 'course_published' === $term ) { $context['pluggable_data'] = [ 'course' => $sample_space_data, ]; $context['response_type'] = 'sample'; } if ( 'user_requests_join_space' === $term ) { $context['pluggable_data'] = [ 'space' => $sample_space_data, 'user' => WordPress::get_sample_user_context(), 'userId' => 1, ]; $context['response_type'] = 'sample'; } } return (array) $context; } /** * Prepare FluentCommunity Courses List. * * @param array $data Search Params. * @return array */ public function search_fc_courses_list( $data ) { global $wpdb; $courses = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}fcom_spaces WHERE type = 'course' ", ARRAY_A ); $options = []; if ( ! empty( $courses ) ) { foreach ( $courses as $course ) { $options[] = [ 'label' => $course['title'], 'value' => $course['id'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Thrive Apprentice Courses List. * * @param array $data Search Params. * @return array */ public function search_thrive_apprentice_courses_list( $data ) { $page = isset( $data['page'] ) ? $data['page'] : 1; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); if ( ! defined( 'TVA_IS_APPRENTICE' ) && ! class_exists( 'TVA_Const' ) ) { return [ 'options' => [], 'hasMore' => false, ]; } $courses = get_terms( [ 'taxonomy' => 'tva_courses', 'hide_empty' => false, 'number' => $limit, 'offset' => $offset, ] ); $options = []; if ( ! empty( $courses ) && ! is_wp_error( $courses ) ) { foreach ( $courses as $course ) { $options[] = [ 'label' => $course->name, 'value' => $course->term_id, ]; } } $all_courses_count = get_terms( [ 'taxonomy' => 'tva_courses', 'hide_empty' => false, 'fields' => 'count', ] ); $has_more = ( $offset + $limit ) < $all_courses_count; return [ 'options' => $options, 'hasMore' => $has_more, ]; } /** * Search Thrive Apprentice Assessments List. * * @param array $data Search Params. * @return array */ public function search_thrive_apprentice_assessments_list( $data ) { $page = isset( $data['page'] ) ? $data['page'] : 1; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $course_id = isset( $data['dynamic']['course_id'] ) ? $data['dynamic']['course_id'] : ''; if ( ! defined( 'TVA_IS_APPRENTICE' ) && ! class_exists( 'TVA_Const' ) ) { return [ 'options' => [], 'hasMore' => false, ]; } if ( ! empty( $course_id ) ) { $course_post_ids = get_objects_in_term( intval( $course_id ), 'tva_courses' ); if ( empty( $course_post_ids ) || is_wp_error( $course_post_ids ) ) { return [ 'options' => [], 'hasMore' => false, ]; } $args = [ 'post_type' => 'tva_assessment', 'post_status' => 'publish', 'posts_per_page' => $limit, 'offset' => $offset, 'fields' => 'ids', 'post__in' => array_map( 'intval', $course_post_ids ), ]; } else { $args = [ 'post_type' => 'tva_assessment', 'post_status' => 'publish', 'posts_per_page' => $limit, 'offset' => $offset, 'fields' => 'ids', ]; } $assessments = get_posts( $args ); $options = []; if ( ! empty( $assessments ) ) { foreach ( $assessments as $assessment_id ) { $assessment = get_post( $assessment_id ); if ( $assessment ) { $options[] = [ 'label' => $assessment->post_title, 'value' => $assessment->ID, ]; } } } $count_args = $args; $count_args['posts_per_page'] = -1; $count_args['offset'] = 0; $all_assessments = get_posts( $count_args ); $has_more = ( $offset + $limit ) < count( $all_assessments ); return [ 'options' => $options, 'hasMore' => $has_more, ]; } /** * Search Thrive Apprentice Lessons List. * * @param array $data Search Params. * @return array */ public function search_thrive_apprentice_lessons_list( $data ) { $page = isset( $data['page'] ) ? $data['page'] : 1; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $course_id = isset( $data['dynamic']['course_id'] ) ? $data['dynamic']['course_id'] : ''; if ( ! defined( 'TVA_IS_APPRENTICE' ) && ! class_exists( 'TVA_Const' ) ) { return [ 'options' => [], 'hasMore' => false, ]; } if ( ! empty( $course_id ) ) { $course_post_ids = get_objects_in_term( intval( $course_id ), 'tva_courses' ); if ( empty( $course_post_ids ) || is_wp_error( $course_post_ids ) ) { return [ 'options' => [], 'hasMore' => false, ]; } $args = [ 'post_type' => 'tva_lesson', 'post_status' => 'publish', 'posts_per_page' => $limit, 'offset' => $offset, 'fields' => 'ids', 'post__in' => array_map( 'intval', $course_post_ids ), ]; } else { $args = [ 'post_type' => 'tva_lesson', 'post_status' => 'publish', 'posts_per_page' => $limit, 'offset' => $offset, 'fields' => 'ids', ]; } $lessons = get_posts( $args ); $options = []; if ( ! empty( $lessons ) ) { foreach ( $lessons as $lesson_id ) { $lesson = get_post( $lesson_id ); if ( $lesson ) { $options[] = [ 'label' => $lesson->post_title, 'value' => $lesson->ID, ]; } } } $count_args = $args; $count_args['posts_per_page'] = -1; $count_args['offset'] = 0; $all_lessons = get_posts( $count_args ); $has_more = ( $offset + $limit ) < count( $all_lessons ); return [ 'options' => $options, 'hasMore' => $has_more, ]; } /** * Search Thrive Apprentice Premium Courses List. * * @param array $data Search Params. * @return array */ public function search_thrive_apprentice_premium_courses_list( $data ) { $page = isset( $data['page'] ) ? $data['page'] : 1; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); if ( ! defined( 'TVA_IS_APPRENTICE' ) && ! class_exists( 'TVA_Const' ) ) { return [ 'options' => [], 'hasMore' => false, ]; } $courses = get_terms( [ 'taxonomy' => 'tva_courses', 'hide_empty' => false, 'number' => $limit, 'offset' => $offset, ] ); $options = []; if ( ! empty( $courses ) && ! is_wp_error( $courses ) ) { foreach ( $courses as $course ) { if ( class_exists( 'TVA_Course_V2' ) ) { $course_obj = new \TVA_Course_V2( $course->term_id ); $product = $course_obj->get_product(); if ( ! empty( $product ) ) { $options[] = [ 'label' => $course->name, 'value' => $course->term_id, ]; } } } } $all_courses = get_terms( [ 'taxonomy' => 'tva_courses', 'hide_empty' => false, 'fields' => 'all', ] ); $premium_count = 0; if ( ! empty( $all_courses ) && ! is_wp_error( $all_courses ) ) { foreach ( $all_courses as $course ) { if ( class_exists( 'TVA_Course_V2' ) ) { $course_obj = new \TVA_Course_V2( $course->term_id ); $product = $course_obj->get_product(); if ( ! empty( $product ) ) { $premium_count++; } } } } $has_more = ( $offset + $limit ) < $premium_count; return [ 'options' => $options, 'hasMore' => $has_more, ]; } /** * Search Thrive Apprentice Modules List. * * @param array $data Search Params. * @return array */ public function search_thrive_apprentice_modules_list( $data ) { $page = isset( $data['page'] ) ? $data['page'] : 1; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $course_id = isset( $data['dynamic']['course_id'] ) ? $data['dynamic']['course_id'] : ''; if ( ! defined( 'TVA_IS_APPRENTICE' ) && ! class_exists( 'TVA_Const' ) ) { return [ 'options' => [], 'hasMore' => false, ]; } if ( ! empty( $course_id ) ) { $course_post_ids = get_objects_in_term( intval( $course_id ), 'tva_courses' ); if ( empty( $course_post_ids ) || is_wp_error( $course_post_ids ) ) { return [ 'options' => [], 'hasMore' => false, ]; } $args = [ 'post_type' => 'tva_module', 'post_status' => 'publish', 'posts_per_page' => $limit, 'offset' => $offset, 'fields' => 'ids', 'post__in' => array_map( 'intval', $course_post_ids ), ]; } else { $args = [ 'post_type' => 'tva_module', 'post_status' => 'publish', 'posts_per_page' => $limit, 'offset' => $offset, 'fields' => 'ids', ]; } $modules = get_posts( $args ); $options = []; if ( ! empty( $modules ) ) { foreach ( $modules as $module_id ) { $module = get_post( $module_id ); if ( $module ) { $options[] = [ 'label' => $module->post_title, 'value' => $module->ID, ]; } } } if ( ! empty( $course_id ) ) { $total_count = count( $course_post_ids ); $has_more = ( $offset + $limit ) < $total_count; } else { $count_args = $args; $count_args['posts_per_page'] = -1; $count_args['offset'] = 0; $all_modules = get_posts( $count_args ); $has_more = ( $offset + $limit ) < count( $all_modules ); } return [ 'options' => $options, 'hasMore' => $has_more, ]; } /** * Search Thrive Apprentice Products List. * * @param array $data Search Params. * @return array */ public function search_thrive_apprentice_products_list( $data ) { $page = isset( $data['page'] ) ? $data['page'] : 1; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); if ( ! defined( 'TVA_IS_APPRENTICE' ) && ! class_exists( 'TVA_Const' ) ) { return [ 'options' => [], 'hasMore' => false, ]; } $products = get_terms( [ 'taxonomy' => 'tva_product', 'hide_empty' => false, 'number' => $limit, 'offset' => $offset, ] ); $options = []; if ( ! empty( $products ) && ! is_wp_error( $products ) ) { foreach ( $products as $product ) { $options[] = [ 'label' => $product->name, 'value' => $product->term_id, ]; } } $all_products_count = get_terms( [ 'taxonomy' => 'tva_product', 'hide_empty' => false, 'fields' => 'count', ] ); $has_more = ( $offset + $limit ) < $all_products_count; return [ 'options' => $options, 'hasMore' => $has_more, ]; } /** * Prepare FluentCommunity Spaces List. * * @param array $data Search Params. * @return array */ public function search_fc_spaces_list( $data ) { global $wpdb; $spaces = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}fcom_spaces WHERE type NOT IN ('course', 'space_group')", ARRAY_A ); $options = []; if ( ! empty( $spaces ) ) { foreach ( $spaces as $space ) { $options[] = [ 'label' => $space['title'], 'value' => $space['id'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare FluentCommunity Topics List. * * @param array $data Search Params. * @return array */ public function search_fc_topics_list( $data ) { if ( ! class_exists( '\FluentCommunity\App\Functions\Utility' ) ) { return []; } $space_topics = Utility::getTopicsBySpaceId( $data['dynamic'] ); $options = []; if ( ! empty( $space_topics ) ) { foreach ( $space_topics as $topic ) { $options[] = [ 'label' => $topic['title'], 'value' => $topic['id'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get WP Travel Engine Last Data * * @param array $data data. * * @return array */ public function search_wpte_triggers_last_data( $data ) { global $wpdb; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; $context = []; $result = null; switch ( $term ) { case 'enquiry_submitted': $result = $wpdb->get_row( "SELECT ID FROM {$wpdb->prefix}posts WHERE post_type = 'enquiry' ORDER BY ID DESC LIMIT 1", ARRAY_A ); if ( $result && isset( $result['ID'] ) ) { $data = get_post( $result['ID'] ); } break; case 'booking_created': case 'booking_confirmed': case 'booking_cancelled': $result = $wpdb->get_row( "SELECT ID FROM {$wpdb->prefix}posts WHERE post_type = 'booking' ORDER BY ID DESC LIMIT 1", ARRAY_A ); if ( $result && isset( $result['ID'] ) ) { $booking_id = $result['ID']; $booking_data = get_post( $booking_id ); $booking_meta = get_post_meta( $booking_id, 'wp_travel_engine_booking_setting', true ); $booking_status = get_post_meta( $booking_id, 'wp_travel_engine_booking_status', true ); // Set correct booking status based on trigger type. switch ( $term ) { case 'booking_confirmed': $booking_status = 'booked'; break; case 'booking_cancelled': $booking_status = 'cancelled'; break; } // For booking_created, include payment data as well. if ( 'booking_created' === $term ) { $payment_status = get_post_meta( $booking_id, 'wp_travel_engine_booking_payment_status', true ); $payment_gateway = get_post_meta( $booking_id, 'wp_travel_engine_booking_payment_gateway', true ); $payment_details = get_post_meta( $booking_id, 'wp_travel_engine_booking_payment_details', true ); $coupon_details = []; $cart_info = get_post_meta( $booking_id, 'cart_info', true ); if ( ! empty( $cart_info ) && is_array( $cart_info ) && isset( $cart_info['discounts'] ) ) { foreach ( $cart_info['discounts'] as $discount ) { if ( isset( $discount['name'] ) ) { $coupon_details[] = [ 'coupon_code' => $discount['name'], 'discount_type' => isset( $discount['type'] ) ? $discount['type'] : '', 'discount_value' => isset( $discount['value'] ) ? $discount['value'] : 0, ]; } } } if ( empty( $coupon_details ) ) { $coupon_details = [ [ 'coupon_code' => 'SAVE20', 'discount_type' => 'percentage', 'discount_value' => 20, ], ]; } $data = [ 'booking_data' => $booking_data, 'booking_meta' => $booking_meta, 'payment_status' => $payment_status, 'payment_gateway' => $payment_gateway, 'payment_details' => $payment_details, 'coupon_details' => $coupon_details, ]; } else { $data = [ 'booking_data' => $booking_data, 'booking_meta' => $booking_meta, 'booking_status' => $booking_status, ]; } } break; } if ( ! empty( $result ) && isset( $result['ID'] ) ) { if ( in_array( $term, [ 'booking_created', 'booking_confirmed', 'booking_cancelled' ] ) ) { $context['pluggable_data'] = $data; } else { $context['pluggable_data'] = [ 'enquiry_post_id' => $result['ID'], 'post_data' => $data, ]; } $context['response_type'] = 'live'; } else { // Helper function to generate booking sample data. $get_booking_sample_data = function( $customer, $trip, $booking_status = '', $payment_data = [] ) { $booking_data = [ 'ID' => 123, 'post_title' => $customer['fname'] . ' ' . $customer['lname'] . ' #123', 'post_name' => strtolower( $customer['fname'] . '-' . $customer['lname'] ) . '-123', 'post_date' => '2025-01-15 10:00:00', 'post_status' => 'publish', 'post_type' => 'booking', 'post_author' => 1, 'post_content' => '', 'post_excerpt' => '', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_modified' => '2025-01-15 10:00:00', 'guid' => 'http://example.com/booking/' . strtolower( $customer['fname'] . '-' . $customer['lname'] ) . '-123', ]; $booking_meta = [ 'place_order' => [ 'traveler' => 1, 'cost' => 10, 'due' => 10, 'tid' => 1308, 'tname' => 'New York', 'datetime' => '2025-08-14', 'datewithtime' => '', 'booking' => [ 'fname' => 'John', 'lname' => 'Doe', 'email' => 'john.doe@example.com', 'address' => '123 Main St', 'city' => 'New York', 'country' => 'US', ], 'tax' => '', 'tduration' => '1 days', 'tenddate' => '2025-08-14T00:00', 'trip_package' => 'Camp Trek', ], ]; $sample_data = [ 'booking_data' => $booking_data, 'booking_meta' => $booking_meta, ]; if ( $booking_status ) { $sample_data['booking_status'] = $booking_status; } if ( ! empty( $payment_data ) ) { $sample_data = array_merge( $sample_data, $payment_data ); } return $sample_data; }; // Sample data based on term. if ( in_array( $term, [ 'booking_created', 'booking_confirmed', 'booking_cancelled' ] ) ) { $sample_customer = [ 'fname' => 'John', 'lname' => 'Doe', 'email' => 'john.doe@example.com', 'address' => '123 Main St', 'city' => 'New York', 'country' => 'US', ]; $sample_trip = [ 'travelers' => '2', 'cost' => '800', 'id' => '101', 'name' => 'Sample Trip to Nepal', 'date' => '2025-03-15', ]; $booking_status = ''; // Set correct booking status based on trigger type. switch ( $term ) { case 'booking_confirmed': $booking_status = 'booked'; break; case 'booking_cancelled': $booking_status = 'cancelled'; break; } // For booking_created, include payment data as well. if ( 'booking_created' === $term ) { $payment_data = [ 'payment_status' => 'check-waiting', 'payment_gateway' => 'Check Payment', 'payment_details' => '', 'coupon_details' => [ [ 'coupon_code' => 'SAVE20', 'discount_type' => 'percentage', 'discount_value' => 20, ], ], ]; $context['pluggable_data'] = $get_booking_sample_data( $sample_customer, $sample_trip, '', $payment_data ); } else { $context['pluggable_data'] = $get_booking_sample_data( $sample_customer, $sample_trip, $booking_status ); } } else { switch ( $term ) { default: $context['pluggable_data'] = [ 'enquiry_post_id' => 123, 'post_data' => [ 'ID' => 123, 'post_title' => 'Sample Enquiry', 'post_name' => 'sample-enquiry', 'post_date' => '2025-01-01 10:00:00', 'post_status' => 'publish', 'post_type' => 'enquiry', 'post_author' => 1, 'post_content' => '', 'post_excerpt' => '', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_modified' => '2025-01-01 10:00:00', 'guid' => 'http://example.com/enquiry/sample-enquiry', ], ]; break; } $context['response_type'] = 'sample'; } } return (array) $context; } /** * Prepare WP Travel Engine Trips List. * * @param array $data Search Params. * @return array */ public function search_wte_trips_list( $data ) { $page = isset( $data['page'] ) ? max( 1, intval( $data['page'] ) ) : 1; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $query_args = [ 'post_type' => 'trip', 'post_status' => 'publish', 'posts_per_page' => $limit, 'offset' => $offset, ]; $query = new \WP_Query( $query_args ); $result = []; foreach ( $query->posts as $post ) { if ( $post instanceof \WP_Post ) { $result[] = [ 'label' => $post->post_title, 'value' => $post->ID, ]; } } $total_query = new \WP_Query( [ 'post_type' => 'trip', 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids', ] ); $posts_count = count( $total_query->posts ); return [ 'options' => $result, 'hasMore' => $posts_count > ( $offset + $limit ), ]; } /** * Get GeoDirectory trigger last data. * * @param array $data data. * @return array|mixed */ public function search_geodir_triggers_last_data( $data ) { $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; $context = []; if ( function_exists( 'geodir_get_post_info' ) ) { $args = [ 'post_type' => 'gd_place', 'posts_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC', ]; $posts = get_posts( $args ); if ( ! empty( $posts ) ) { $post = $posts[0]; $post_id = $post->ID; $user = WordPress::get_user_context( absint( $post->post_author ) ); $gd_post = function_exists( 'geodir_get_post_info' ) ? geodir_get_post_info( $post_id ) : null; $categories = []; $cat_taxonomy = $post->post_type . 'category'; if ( taxonomy_exists( $cat_taxonomy ) ) { $terms = wp_get_post_terms( $post_id, $cat_taxonomy ); if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { foreach ( $terms as $term_obj ) { $categories[] = $term_obj->name; } } } $tags = []; $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; } } GlobalSearchController::get_instance();