ults[0]['subtotal']; $context['pluggable_data']['total'] = $results[0]['total']; // Get order items. $order = \Voxel\Product_Types\Orders\Order::find( [ 'id' => $results[0]['id'], ] ); $order_items = $order->get_items(); $context['pluggable_data']['tax_amount'] = $order->get_tax_amount(); $context['pluggable_data']['discount_amount'] = $order->get_discount_amount(); $context['pluggable_data']['shipping_amount'] = $order->get_shipping_amount(); $context['pluggable_data']['order_item_count'] = $order->get_item_count(); foreach ( $order_items as $item ) { $addon_data = []; if ( is_object( $item ) && method_exists( $item, 'get_addons' ) ) { // Get addon details. $addons = $item->get_addons(); $addon_data = []; // Add the addons to the simple entry. if ( $addons && isset( $addons['summary'] ) ) { $addon_data = $addons['summary']; } } $context['pluggable_data']['order_items'][] = [ 'id' => $item->get_id(), 'type' => $item->get_type(), 'currency' => $item->get_currency(), 'quantity' => $item->get_quantity(), 'subtotal' => $item->get_subtotal(), 'product_id' => $item->get_post()->get_id(), 'product_label' => $item->get_product_label(), 'product_thumbnail_url' => $item->get_product_thumbnail_url(), 'product_link' => $item->get_product_link(), 'description' => $item->get_product_description(), 'addon_data' => $addon_data, ]; // If booking item, get booking details. if ( 'booking' === $item->get_type() ) { $details = $item->get_order_page_details(); $context['pluggable_data']['order_items']['booking_type'] = $details['booking']['type']; if ( isset( $details['booking']['count_mode'] ) ) { $context['pluggable_data']['order_items']['booking_count_mode'] = $details['booking']['count_mode']; } if ( 'date_range' === $details['booking']['type'] ) { $context['pluggable_data']['order_items']['booking_start_date'] = $details['booking']['start_date']; $context['pluggable_data']['order_items']['booking_end_date'] = $details['booking']['end_date']; } elseif ( 'single_day' === $details['booking']['type'] ) { $context['pluggable_data']['order_items']['booking_date'] = $details['booking']['date']; } elseif ( 'timeslots' === $details['booking']['type'] ) { $context['pluggable_data']['order_items']['booking_date'] = $details['booking']['date']; $context['pluggable_data']['order_items']['booking_slot_from'] = $details['booking']['slot']['from']; $context['pluggable_data']['order_items']['booking_slot_to'] = $details['booking']['slot']['to']; } } } // Get Customer. $context['pluggable_data']['customer'] = WordPress::get_user_context( $results[0]['customer_id'] ); // Get Vendor. $context['pluggable_data']['vendor'] = WordPress::get_user_context( $results[0]['vendor_id'] ); $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"id": "15","vendor_id": null,"details": {"cart": {"type": "direct_cart","items": {"6b39iruj": {"product": {"post_id": 9211,"field_key": "product"},"stock": {"quantity": 1}}}},"pricing": {"currency": "USD","subtotal": 10,"total": 10},"status": {"last_updated": "2024-05-30 06:52:05"}},"payment_method": "offline_payment","status": "pending_approval","created_at": "2024-05-30 06:50:19","subtotal": null,"total": null,"tax_amount": null,"discount_amount": null,"shipping_amount": null,"order_item_count": 1,"order_items": [{"id": 11,"type": "regular","currency": "USD","quantity": 1,"subtotal": 10,"product_id": 9211,"product_label": "Pro 1","product_thumbnail_url": null,"product_link": "https:\/\/example.com\/products\/pro-1\/","description": "","addon_data": []}],"vendor": {"wp_user_id": 1,"user_login": "admin","display_name": "Arian","user_firstname": "arian","user_lastname": "d","user_email": "johnd@gmail.com","user_role": {"0": "administrator","7": "academy_instructor","8": "tutor_instructor"}},"customer": {"wp_user_id": 98,"user_login": "johnd","display_name": "johndoe","user_firstname": "john","user_lastname": "d","user_email": "johnd@example.com","user_role": ["customer"]}},"response_type":"sample"}', true );// @phpcs:ignore } } elseif ( 'order_promotion_activated' === $term || 'order_promotion_canceled' === $term || 'order_claim_listing' === $term ) { if ( 'order_promotion_activated' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}vx_orders WHERE status = 'completed' AND details LIKE '%voxel:promotion%' ORDER BY id DESC LIMIT 1"; } elseif ( 'order_promotion_canceled' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}vx_orders WHERE status = 'canceled' AND details LIKE '%voxel:promotion%' ORDER BY id DESC LIMIT 1"; } elseif ( 'order_claim_listing' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}vx_orders WHERE details LIKE '%voxel:claim%' ORDER BY id DESC LIMIT 1"; } $results = $wpdb->get_results( $sql, ARRAY_A );// @phpcs:ignore if ( ! empty( $results ) ) { // Get Order. $context['pluggable_data']['id'] = $results[0]['id']; $context['pluggable_data']['payment_method'] = $results[0]['payment_method']; $context['pluggable_data']['status'] = $results[0]['status']; $context['pluggable_data']['created_at'] = $results[0]['created_at']; // Get order items. $order = \Voxel\Product_Types\Orders\Order::find( [ 'id' => $results[0]['id'], ] ); $order_items = $order->get_items(); $context['pluggable_data']['details'] = $order->get_details(); $context['pluggable_data']['order_item_count'] = $order->get_item_count(); foreach ( $order_items as $item ) { $context['pluggable_data']['order_items'][] = [ 'id' => $item->get_id(), 'type' => $item->get_type(), 'currency' => $item->get_currency(), 'quantity' => $item->get_quantity(), 'subtotal' => $item->get_subtotal(), 'product_id' => $item->get_post()->get_id(), 'product_label' => $item->get_product_label(), 'product_thumbnail_url' => $item->get_product_thumbnail_url(), 'product_link' => $item->get_product_link(), 'description' => $item->get_product_description(), ]; } // Get Customer. $context['pluggable_data']['customer'] = WordPress::get_user_context( $results[0]['customer_id'] ); $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"id":"22","payment_method":"offline_payment","status":"pending_approval","created_at":"2024-08-27 10:20:16","details":{"cart":{"type":"direct_cart","items":{"lzl47hyq":{"product":{"post_id":8912,"field_key":"voxel:claim"}}}},"pricing":{"currency":"USD","subtotal":5,"total":5},"order_notes":"ABDDD","status":{"last_updated":"2024-08-27 10:20:16"}},"order_item_count":1,"order_items":[{"id":22,"type":"regular","currency":"USD","quantity":null,"subtotal":5,"product_id":8912,"product_label":"Fokachio","product_thumbnail_url":"https://example.com/wp-content/uploads/2024/05/8a13537-150x150.jpg","product_link":"https://example.com/places/papas-pita-2/","description":"Claim request"}],"customer":{"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":{"8":"tutor_instructor"}}},"response_type":"sample"}', true );// @phpcs:ignore } } return $context; } /** * Get Voxel Timeline Comments Last Data * * @param array $data data. * * @return array|mixed|string */ public function search_voxel_timeline_triggers_last_data( $data ) { global $wpdb; $context = []; $term = $data['search_term']; $sql = ''; if ( 'new_comment_timeline' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}voxel_timeline_replies WHERE parent_id IS NULL ORDER BY id DESC LIMIT 1"; } elseif ( 'comment_reply_timeline' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}voxel_timeline_replies WHERE parent_id IS NOT NULL ORDER BY id DESC LIMIT 1"; } elseif ( 'comment_liked' === $term ) { $sql = "SELECT vtrl.user_id as like_user_id, vtrl.reply_id as like_reply_id, vtr.* FROM {$wpdb->prefix}voxel_timeline_reply_likes_v2 vtrl JOIN {$wpdb->prefix}voxel_timeline_replies vtr ON vtrl.reply_id = vtr.ID WHERE vtr.like_count > 0"; } elseif ( 'user_timeline_post_liked' === $term ) { $sql = "SELECT vtsl.user_id as like_user_id, vtsl.status_id as like_status_id, vtr.* FROM {$wpdb->prefix}voxel_timeline_status_likes vtsl JOIN {$wpdb->prefix}voxel_timeline vt ON vtsl.status_id = vt.id WHERE vt.like_count > 0"; } elseif ( 'user_timeline_post_quoted' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}voxel_timeline WHERE feed = %s AND quote_of IS NOT NULL ORDER BY id DESC LIMIT 1"; } elseif ( 'user_timeline_post_reposted' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}voxel_timeline WHERE feed = %s AND repost_of IS NOT NULL ORDER BY id DESC LIMIT 1"; } if ( 'user_timeline_post_reposted' === $term || 'user_timeline_post_quoted' === $term ) { $results = $wpdb->get_results( $wpdb->prepare( $sql, 'user_timeline' ), ARRAY_A );// @phpcs:ignore } else { $results = $wpdb->get_results( $sql, ARRAY_A );// @phpcs:ignore } if ( 'new_comment_timeline' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data']['comment_by'] = WordPress::get_user_context( $results[0]['user_id'] ); $context['pluggable_data']['id'] = $results[0]['id']; $context['pluggable_data']['status_id'] = $results[0]['status_id']; $context['pluggable_data']['content'] = $results[0]['content']; $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"comment_by": {"wp_user_id": 1,"user_login": "admin","display_name": "Johnd","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": {"0": "administrator","7": "academy_instructor","8": "tutor_instructor"}},"id": "16","status_id": "5","content": "Nice"},"response_type":"sample"}', true );// @phpcs:ignore } } elseif ( 'comment_reply_timeline' === $term ) { if ( ! empty( $results ) ) { $comment_sql = "SELECT * FROM {$wpdb->prefix}voxel_timeline_replies WHERE id = %d"; $comment_result = $wpdb->get_results( $wpdb->prepare( $comment_sql, $results[0]['parent_id']), ARRAY_A );// @phpcs:ignore $context['pluggable_data']['replied_by'] = WordPress::get_user_context( $results[0]['user_id'] ); $context['pluggable_data']['comment_by'] = WordPress::get_user_context( $comment_result[0]['user_id'] ); $context['pluggable_data']['comment'] = $comment_result[0]['content']; $context['pluggable_data']['comment_id'] = $results[0]['parent_id']; $context['pluggable_data']['reply_id'] = $results[0]['id']; $context['pluggable_data']['reply'] = $results[0]['content']; $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"replied_by": {"wp_user_id": 101,"user_login": "johnd","display_name": "JohnD","user_firstname": "John","user_lastname": "D","user_email": "johnd@gmail.com","user_role": ["subscriber"]},"comment_by": {"wp_user_id": 1,"user_login": "admin","display_name": "Arian","user_firstname": "Arian","user_lastname": "D","user_email": "arian2@gmail.com","user_role": ["subscriber"]},"comment": "Nice","comment_id": "16","reply_id": "17","reply": "Nice too"},"response_type":"sample"}', true );// @phpcs:ignore } } elseif ( 'comment_liked' === $term ) { if ( ! empty( $results ) ) { $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']; } $recipient_user = get_userdata( $results[0]['like_user_id'] ); if ( $recipient_user ) { $recipient_user_data = (array) $recipient_user->data; $context['pluggable_data']['recipient']['user_display_name'] = $recipient_user_data['display_name']; $context['pluggable_data']['recipient']['user_name'] = $recipient_user_data['user_nicename']; $context['pluggable_data']['recipient']['user_email'] = $recipient_user_data['user_email']; } if ( class_exists( 'Voxel\Timeline\Reply' ) ) { $reply_details = \Voxel\Timeline\Reply::get( $results[0]['id'] ); foreach ( (array) $reply_details as $key => $value ) { $clean_key = preg_replace( '/^\0.*?\0/', '', $key ); $context['pluggable_data'][ $clean_key ] = $value; } } $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"user_display_name":"test test","user_name":"test","user_email":"test@yopmail.com","recipient":{"user_display_name":"Arian","user_name":"admin","user_email":"admin@example.com"},"id":1,"user_id":2,"published_as":null,"status_id":56,"parent_id":null,"content":"@admin test","details":[],"created_at":"2025-01-22 12:46:33","edited_at":null,"like_count":1,"reply_count":0,"liked_by_user":false,"last3_liked":[{"post_id":null,"user_id":1}]},"response_type":"sample"}', true );// @phpcs:ignore } } elseif ( 'user_timeline_post_liked' === $term ) { if ( ! empty( $results ) ) { $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']; } $recipient_user = get_userdata( $results[0]['like_user_id'] ); if ( $recipient_user ) { $recipient_user_data = (array) $recipient_user->data; $context['pluggable_data']['recipient']['user_display_name'] = $recipient_user_data['display_name']; $context['pluggable_data']['recipient']['user_name'] = $recipient_user_data['user_nicename']; $context['pluggable_data']['recipient']['user_email'] = $recipient_user_data['user_email']; } if ( class_exists( 'Voxel\Timeline\Status' ) ) { $reply_details = \Voxel\Timeline\Status::get( $results[0]['id'] ); foreach ( (array) $reply_details as $key => $value ) { $clean_key = preg_replace( '/^\0.*?\0/', '', $key ); $context['pluggable_data'][ $clean_key ] = $value; } } $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"user_display_name":"test test","user_name":"test","user_email":"test@yopmail.com","recipient":{"user_display_name":"Arian","user_name":"admin","user_email":"admin@example.com"},"id":51,"user_id":2,"post_id":null,"published_as":null,"content":"test","feed":"user_timeline","moderation":0,"repost_of":null,"quote_of":null,"created_at":"2025-01-22 11:10:06","edited_at":null,"review_score":null,"like_count":0,"reply_count":0,"details":{"files":"541"},"liked_by_user":false,"reposted_by_user":false,"last3_liked":[],"friends_reposted":[],"friends_liked":[]},"response_type":"sample"}', true );// @phpcs:ignore } } elseif ( 'user_timeline_post_reposted' === $term || 'user_timeline_post_quoted' === $term ) { if ( ! empty( $results ) ) { $author = get_userdata( $results[0]['user_id'] ); if ( $author ) { $author_data = (array) $author->data; $context['pluggable_data']['author_display_name'] = $author_data['display_name']; $context['pluggable_data']['author_name'] = $author_data['user_nicename']; $context['pluggable_data']['author_email'] = $author_data['user_email']; } $column = 'user_timeline_post_reposted' === $term ? 'repost_of' : 'quote_of'; $recipient_sql = "SELECT user_id FROM {$wpdb->prefix}voxel_timeline WHERE id = %d"; $recipient_results = $wpdb->get_results( $wpdb->prepare( $recipient_sql, $results[0][$column] ), ARRAY_A ); // @phpcs:ignore if ( ! empty( $recipient_results ) ) { $recipient_user = get_userdata( $recipient_results[0]['user_id'] ); if ( $recipient_user ) { $recipient_user_data = (array) $recipient_user->data; $context['pluggable_data']['recipient']['user_display_name'] = $recipient_user_data['display_name']; $context['pluggable_data']['recipient']['user_name'] = $recipient_user_data['user_nicename']; $context['pluggable_data']['recipient']['user_email'] = $recipient_user_data['user_email']; } } if ( class_exists( 'Voxel\Timeline\Status' ) ) { $status_details = \Voxel\Timeline\Status::get( $results[0]['id'] ); $details_column = 'user_timeline_post_reposted' === $term ? 'repost_of' : 'quote_of'; $related_details = \Voxel\Timeline\Status::get( $results[0][ $details_column ] ); foreach ( [ 'status' => $status_details, $details_column => $related_details, ] as $key => $details ) { foreach ( (array) $details as $sub_key => $value ) { $clean_key = preg_replace( '/^\0.*?\0/', '', $sub_key ); $context['pluggable_data'][ $key ][ $clean_key ] = $value; } } } $context['response_type'] = 'live'; } else { if ( 'user_timeline_post_reposted' === $term ) { $context = json_decode( '{"pluggable_data":{"author_display_name":"test test","author_name":"test","author_email":"test@yopmail.com","recipient":{"user_display_name":"Arian","user_name":"admin","user_email":"admin@example.com"},"status":{"id":59,"user_id":2,"post_id":null,"published_as":null,"content":"","feed":"user_timeline","moderation":1,"repost_of":12,"quote_of":null,"created_at":"2025-01-23 04:02:45","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":[]},"repost_of":{"id":12,"user_id":1,"post_id":447,"published_as":null,"content":"hello\n\nhttps://example.com/mountain-bike/","feed":"post_wall","moderation":1,"repost_of":null,"quote_of":null,"created_at":"2025-01-17 05:26:23","edited_at":null,"review_score":null,"like_count":0,"reply_count":0,"details":{"link_preview":{"url":"https://example.com/mountain-bike/","title":"Mountain Bike - spacesdemo.wp1.sh","image":"https://example.comt/uploads/2025/01/test.jpg"}},"liked_by_user":false,"reposted_by_user":false,"last3_liked":[],"friends_reposted":[],"friends_liked":[]}},"response_type":"sample"}', true );// @phpcs:ignore } else { $context = json_decode( '{"pluggable_data":{"author_display_name":"test test","author_name":"test","author_email":"test@yopmail.com","recipient":{"user_display_name":"Arian","user_name":"admin","user_email":"admin@example.com"},"status":{"id":59,"user_id":2,"post_id":null,"published_as":null,"content":"","feed":"user_timeline","moderation":1,"quote_of":12,"quote_of":null,"created_at":"2025-01-23 04:02:45","edited_at":null,"review_score":null,"like_count":0,"reply_count":0,"details":[],"liked_by_user":false,"quoted_by_user":false,"last3_liked":[],"friends_quoted":[],"friends_liked":[]},"quote_of":{"id":12,"user_id":1,"post_id":447,"published_as":null,"content":"hello\n\nhttps://example.com/mountain-bike/","feed":"post_wall","moderation":1,"quote_of":null,"quote_of":null,"created_at":"2025-01-17 05:26:23","edited_at":null,"review_score":null,"like_count":0,"reply_count":0,"details":{"link_preview":{"url":"https://example.com/mountain-bike/","title":"Mountain Bike - spacesdemo.wp1.sh","image":"https://example.comt/uploads/2025/01/test.jpg"}},"liked_by_user":false,"quoted_by_user":false,"last3_liked":[],"friends_quoted":[],"friends_liked":[]}},"response_type":"sample"}', true );// @phpcs:ignore } } } return $context; } /** * Get Voxel Timeline Comments Last Data * * @param array $data data. * * @return array|mixed|string */ public function search_voxel_posts_triggers_last_data( $data ) { $context = []; global $wpdb; $post_type = 'post'; $term = $data['search_term']; if ( isset( $data['filter']['post_type']['value'] ) ) { $post_type = $data['filter']['post_type']['value']; } $results = []; if ( 'post_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, $post_type, 'publish'), ARRAY_A );// @phpcs:ignore } elseif ( 'post_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, $post_type, 'rejected'), ARRAY_A );// @phpcs:ignore } elseif ( 'post_reviewed' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}voxel_timeline vt JOIN {$wpdb->prefix}posts p ON vt.post_id = p.ID JOIN {$wpdb->prefix}postmeta pm ON vt.post_id = pm.post_id WHERE pm.meta_key LIKE '%voxel:review_stats%' AND p.post_type LIKE %s AND vt.details IS NOT NULL AND vt.details LIKE %s"; $results = $wpdb->get_results( $wpdb->prepare( $sql, $post_type, '%rating%' ), ARRAY_A );// @phpcs:ignore } elseif ( 'post_review_approved' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}voxel_timeline vt JOIN {$wpdb->prefix}posts p ON vt.post_id = p.ID JOIN {$wpdb->prefix}postmeta pm ON vt.post_id = pm.post_id WHERE vt.moderation = %d AND pm.meta_key LIKE '%voxel:review_stats%' AND p.post_type LIKE %s AND vt.details IS NOT NULL AND vt.details LIKE %s AND vt.feed = %s"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 1, $post_type, '%rating%', 'post_reviews' ), ARRAY_A );// @phpcs:ignore } elseif ( 'post_submitted' === $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, $post_type), ARRAY_A );// @phpcs:ignore } elseif ( 'post_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, $post_type ), ARRAY_A );// @phpcs:ignore } elseif ( 'collection_post_submitted' === $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, 'collection' ), ARRAY_A );// @phpcs:ignore } elseif ( 'collection_post_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, 'collection' ), ARRAY_A );// @phpcs:ignore } elseif ( 'new_wall_post_by_user' === $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 %s AND vt.details IS NOT NULL AND vt.details NOT LIKE %s ORDER BY vt.id DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, $post_type, '%rating%' ), ARRAY_A );// @phpcs:ignore } elseif ( 'wall_post_approved' === $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 vt.feed = %s AND p.post_type LIKE %s AND vt.moderation = %d AND vt.details IS NOT NULL ORDER BY vt.id DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'post_wall', $post_type, 1 ), ARRAY_A );// @phpcs:ignore } elseif ( 'timeline_post_approved' === $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 vt.feed = %s AND vt.moderation = %d AND p.post_type LIKE %s ORDER BY vt.id DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'post_timeline', 1, $post_type ), ARRAY_A );// @phpcs:ignore } elseif ( 'taxonomy_updated' === $term ) { $sql = "SELECT tr.object_id as post_id, tt.taxonomy, tr.term_taxonomy_id FROM {$wpdb->prefix}term_relationships tr JOIN {$wpdb->prefix}term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id JOIN {$wpdb->prefix}posts p ON tr.object_id = p.ID WHERE p.post_type LIKE %s ORDER BY tr.object_id DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, $post_type ), ARRAY_A );// @phpcs:ignore } elseif ( 'post_followed' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}voxel_followers WHERE object_type = %s LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'post' ), ARRAY_A );// @phpcs:ignore } if ( 'post_approved' === $term || 'post_rejected' === $term || 'post_submitted' === $term || 'post_updated' === $term || 'timeline_post_approved' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data'] = WordPress::get_post_context( $results[0]['ID'] ); $context['pluggable_data']['post'] = Voxel::get_post_fields( $results[0]['ID'] ); $context['response_type'] = 'live'; } else { $context['pluggable_data'] = [ 'ID' => 557, 'post' => 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' => 'published', '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', ]; $context['response_type'] = 'sample'; } } elseif ( 'post_reviewed' === $term || 'post_review_approved' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data'] = WordPress::get_post_context( $results[0]['post_id'] ); $context['pluggable_data']['post'] = Voxel::get_post_fields( $results[0]['post_id'] ); $context['pluggable_data']['review_content'] = $results[0]['content']; $context['pluggable_data']['review_created_at'] = $results[0]['created_at']; $context['pluggable_data']['review_details'] = json_decode( $results[0]['details'], true ); $context['pluggable_data']['review_by'] = WordPress::get_user_context( $results[0]['user_id'] ); $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"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","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 = isset( $data['filter']['condition_compare']['value'] ) ? $data['filter']['condition_compare']['value'] : '='; $allowed_operators = [ '=', '!=', '>', '<', '>=', '<=' ]; $condition_compare = in_array( $condition_compare, $allowed_operators, true ) ? $condition_compare : '='; $percentage = $data['filter']['percentage']['value']; if ( -1 === $quiz_id ) { $results = $wpdb->get_results( $wpdb->prepare( "SELECT comments.*, meta.meta_key, meta.meta_value FROM {$wpdb->comments} AS comments JOIN {$wpdb->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 {$wpdb->comments} AS comments JOIN {$wpdb->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; case 'task_updated': $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fbs_tasks ORDER BY updated_at DESC LIMIT 1", ARRAY_A ); break; case 'stage_updated': $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fbs_board_terms ORDER BY updated_at DESC LIMIT 1", ARRAY_A ); break; case 'assignees_updated': $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fbs_tasks ORDER BY updated_at 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; case 'task_updated': $stage_data = Stage::where( 'board_id', $result['board_id'] )->whereNull( 'archived_at' )->first(); $context['pluggable_data'] = [ 'task' => [ 'id' => $result['id'], 'parent_id' => $result['parent_id'], 'board_id' => $result['board_id'], 'title' => $result['title'], 'slug' => $result['slug'], 'type' => $result['type'], 'status' => $result['status'], 'stage_id' => $result['stage_id'], 'source' => $result['source'], 'priority' => $result['priority'], 'description' => $result['description'], 'position' => $result['position'], 'created_by' => $result['created_by'], 'created_at' => $result['created_at'], 'updated_at' => $result['updated_at'], 'due_at' => $result['due_at'], 'started_at' => $result['started_at'], 'settings' => maybe_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, ] : null, ], 'column' => 'description', 'old_task' => [ 'id' => $result['id'], 'parent_id' => $result['parent_id'], 'board_id' => $result['board_id'], 'title' => $result['title'], 'slug' => $result['slug'], 'type' => $result['type'], 'status' => $result['status'], 'stage_id' => $result['stage_id'], 'source' => $result['source'], 'priority' => $result['priority'], 'description' => $result['description'], 'position' => $result['position'], 'created_by' => $result['created_by'], 'created_at' => $result['created_at'], 'updated_at' => $result['updated_at'], 'due_at' => $result['due_at'], 'started_at' => $result['started_at'], 'settings' => maybe_unserialize( $result['settings'] ), ], ]; $context['response_type'] = 'live'; break; case 'stage_updated': $context['pluggable_data'] = [ 'board_id' => $result['board_id'], 'updated_stage' => [ 'title' => $result['title'], 'cover_bg' => $result['bg_color'], ], 'stage_before_update' => [ 'id' => $result['id'], 'board_id' => $result['board_id'], 'title' => $result['title'], 'slug' => $result['slug'], 'type' => $result['type'], 'position' => $result['position'], 'color' => $result['color'], 'bg_color' => $result['bg_color'], 'settings' => maybe_unserialize( $result['settings'] ), 'archived_at' => $result['archived_at'], 'created_at' => $result['created_at'], 'updated_at' => $result['updated_at'], ], ]; $context['response_type'] = 'live'; break; case 'assignees_updated': $stage_data = Stage::where( 'board_id', $result['board_id'] )->whereNull( 'archived_at' )->first(); $assignee_rel = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fbs_relations WHERE object_id = %d AND object_type = 'task_assignee' ORDER BY id DESC LIMIT 1", $result['id'] ), ARRAY_A ); $assignee_id = ! empty( $assignee_rel ) ? $assignee_rel['foreign_id'] : 0; $assignee_user = $assignee_id ? $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}users WHERE ID = %d", $assignee_id ), ARRAY_A ) : null; $context['pluggable_data'] = [ 'task' => [ 'id' => $result['id'], 'parent_id' => $result['parent_id'], 'board_id' => $result['board_id'], 'title' => $result['title'], 'slug' => $result['slug'], 'type' => $result['type'], 'status' => $result['status'], 'stage_id' => $result['stage_id'], 'source' => $result['source'], 'priority' => $result['priority'], 'description' => $result['description'], 'position' => $result['position'], 'created_by' => $result['created_by'], 'created_at' => $result['created_at'], 'updated_at' => $result['updated_at'], 'due_at' => $result['due_at'], 'started_at' => $result['started_at'], 'settings' => maybe_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, ] : null, 'assignees' => $assignee_user ? [ [ 'ID' => $assignee_user['ID'], 'user_login' => $assignee_user['user_login'], 'user_nicename' => $assignee_user['user_nicename'], 'user_email' => $assignee_user['user_email'], 'user_url' => $assignee_user['user_url'], 'user_registered' => $assignee_user['user_registered'], 'user_status' => $assignee_user['user_status'], 'display_name' => $assignee_user['display_name'], ], ] : [], ], 'assignee_id' => $assignee_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; case 'task_updated': $context = json_decode( '{"pluggable_data":{"task":{"id":"1001","parent_id":null,"board_id":"10","title":"Sample Task","slug":"sample-task","type":"task","status":"open","stage_id":"3","source":"web","priority":"medium","description":"

Updated task description

","position":"1","created_by":"1","created_at":"2024-03-20 12:00:00","updated_at":"2024-03-20 12:30:00","due_at":"2024-03-25 23:45:00","started_at":null,"settings":[],"stage":{"id":"3","slug":"sample-stage","title":"Sample Stage","type":"default","board_id":"10","position":"1","settings":[]}},"column":"description","old_task":{"id":"1001","parent_id":null,"board_id":"10","title":"Sample Task","slug":"sample-task","type":"task","status":"open","stage_id":"3","source":"web","priority":"medium","description":"

Original task description

","position":"1","created_by":"1","created_at":"2024-03-20 12:00:00","updated_at":"2024-03-20 12:00:00","due_at":"2024-03-25 23:45:00","started_at":null,"settings":[]}},"response_type":"sample"}', true ); break; case 'stage_updated': $context = json_decode( '{"pluggable_data":{"board_id":"1","updated_stage":{"title":"New Stage","cover_bg":"#4bce97"},"stage_before_update":{"id":"9","board_id":"1","title":"New Stage","slug":"","type":"stage","position":"4.00","color":"","bg_color":"","settings":{"default_task_status":"open","default_task_assignees":[]},"archived_at":null,"created_at":"2024-03-18 13:36:57","updated_at":"2024-03-18 13:36:57"}},"response_type":"sample"}', true ); break; case 'assignees_updated': $context = json_decode( '{"pluggable_data":{"task":{"id":"1","parent_id":null,"board_id":"1","title":"Sample Task","slug":"sample-task","type":"task","status":"open","stage_id":"7","source":"web","priority":"low","description":"

Sample task description

","position":"1.00","created_by":"1","created_at":"2024-03-18 13:19:31","updated_at":"2024-03-18 13:50:59","due_at":"2024-03-19 23:45:00","started_at":null,"settings":{"cover":{"backgroundColor":""},"subtask_count":0,"attachment_count":0,"subtask_completed_count":0},"stage":{"id":"7","slug":"sample-stage","title":"Sample Stage","type":"stage","board_id":"1","position":"1","settings":{}},"assignees":[{"ID":88,"user_login":"active","user_nicename":"active","user_email":"active@gmail.com","user_url":"","user_registered":"2025-11-10 04:09:05","user_status":"0","display_name":"active"}]},"assignee_id":88},"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":"johnd ","subject":"We received your message","body":"Your message has been successfully sent. We appreciate you contacting us and we will be in touch soon.\n

","attachments":[],"status":"failed","response":{"code":422,"message":"SMTP Error: data not accepted.","errors":["SMTP Error: data not accepted."]},"headers":{"reply-to":[{"email":"johnd@example.com"}],"cc":[],"bcc":[],"content-type":"text/html"},"extra":{"provider":"smtp"}},"response_type":"sample"}', true ); } return (array) $context; } /** * Get Fluent Community Last Data * * @param array $data data. * * @return array */ public function search_fc_triggers_last_data( $data ) { $context = []; $space_result = []; $profile_result = []; $user_result = []; $feed_data = []; $course_result = []; global $wpdb; $term = $data['search_term'] ? $data['search_term'] : ''; $data = []; if ( 'space_created' === $term || 'user_leaves_space' === $term || 'user_requests_join_space' === $term || 'feed_created' === $term || 'feed_updated' === $term || 'space_feed_created' === $term || 'user_joins_space' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fcom_spaces ORDER BY id DESC LIMIT 1", ARRAY_A ); $space_result = [ 'id' => $result['id'], 'slug' => $result['slug'], 'title' => $result['title'], 'description' => $result['description'], 'type' => $result['type'], 'privacy' => $result['privacy'], 'status' => $result['status'], 'serial' => $result['serial'], 'created_at' => $result['created_at'], 'created_by' => $result['created_by'], 'updated_at' => $result['updated_at'], 'settings' => unserialize( $result['settings'] ), ]; } if ( 'feed_created' === $term || 'feed_updated' === $term || 'space_feed_created' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fcom_posts ORDER BY id DESC LIMIT 1", ARRAY_A ); $profile_result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fcom_xprofile ORDER BY id DESC LIMIT 1", ARRAY_A ); $user_result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}users ORDER BY id DESC LIMIT 1", ARRAY_A ); $feed_data = [ 'feed' => [ 'id' => $result['id'], 'user_id' => $result['user_id'], 'parentid' => $result['parent_id'], 'title' => $result['title'], 'slug' => $result['slug'], 'message' => $result['message'], 'message_rendered' => $result['message_rendered'], 'type' => $result['type'], 'content_type' => $result['content_type'], 'space_id' => $result['space_id'], 'privacy' => $result['privacy'], 'status' => $result['status'], 'featured_image' => $result['featured_image'], 'meta' => unserialize( $result['meta'] ), 'issticky' => $result['issticky'], 'comments_count' => $result['comments_count'], 'reactions_count' => $result['reactions_count'], 'priority' => $result['priority'], 'expiredat' => $result['expired_at'], 'scheduledat' => $result['scheduled_at'], 'created_at' => $result['created_at'], 'updated_at' => $result['updated_at'], 'space' => $space_result, 'xprofile' => [ 'id' => $profile_result['id'], 'user_id' => $profile_result['user_id'], 'total_points' => $profile_result['total_points'], 'username' => $profile_result['username'], 'status' => $profile_result['status'], 'is_verified' => $profile_result['is_verified'], 'display_name' => $profile_result['display_name'], 'avatar' => $profile_result['avatar'], 'short_description' => $profile_result['short_description'], 'last_activity' => $profile_result['last_activity'], 'meta' => unserialize( $profile_result['meta'] ), 'created_at' => $profile_result['created_at'], 'updated_at' => $profile_result['updated_at'], ], ], ]; } if ( 'user_joins_space' === $term ) { $user_result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}users ORDER BY id DESC LIMIT 1", ARRAY_A ); } if ( 'course_created' === $term || 'course_published' === $term || 'course_updated' === $term || 'user_enrolls_course' === $term || 'user_unenrolls_course' === $term || 'user_completes_course' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fcom_spaces WHERE type = 'course' ORDER BY id DESC LIMIT 1", ARRAY_A ); $course_result = [ 'id' => $result['id'], 'slug' => $result['slug'], 'title' => $result['title'], 'serial' => $result['serial'], 'status' => $result['status'], 'privacy' => $result['privacy'], 'created_at' => $result['created_at'], 'created_by' => $result['created_by'], 'updated_at' => $result['updated_at'], 'description' => $result['description'], 'settings' => unserialize( $result['settings'] ), ]; } if ( 'course_deleted' === $term ) { $result = $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}fcom_spaces WHERE type = 'course' ORDER BY id DESC LIMIT 1" ); } if ( 'new_comment_added' === $term || 'comment_updated' === $term ) { $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fcom_post_comments ORDER BY id DESC LIMIT 1", ARRAY_A ); $profile_result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}fcom_xprofile ORDER BY id DESC Limit 1", ARRAY_A ); } if ( 'comment_deleted' === $term ) { $result = $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}fcom_post_comments ORDER BY id DESC LIMIT 1" ); } if ( ! empty( $result ) ) { if ( 'space_created' === $term ) { $context['pluggable_data'] = [ 'space' => $space_result ]; $context['response_type'] = 'live'; } if ( 'feed_created' === $term || 'feed_updated' === $term ) { $context['pluggable_data'] = $feed_data; $context['response_type'] = 'live'; } if ( 'space_feed_created' === $term ) { $feed_data['feed']['user'] = [ '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'], ]; $context['pluggable_data'] = $feed_data; $context['response_type'] = 'live'; } if ( 'user_joins_space' === $term ) { $context['pluggable_data'] = [ 'space' => [ 'id' => $result['id'], 'slug' => $result['slug'], 'title' => $result['title'], 'description' => $result['description'], 'type' => $result['type'], 'privacy' => $result['privacy'], 'status' => $result['status'], 'serial' => $result['serial'], 'created_at' => $result['created_at'], 'created_by' => $result['created_by'], 'updated_at' => $result['updated_at'], 'settings' => unserialize( $result['settings'] ), 'membership' => [ 'ID' => $user_result['ID'], 'photo' => '', 'pivot_role' => 'admin', 'pivot_status' => 'active', 'pivot_created_at' => $result['created_at'], 'pivot_user_id' => $user_result['ID'], 'pivot_space_id' => $result['id'], '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'], ], ], 'userId' => 1, 'by' => 'self', ]; $context['response_type'] = 'live'; } if ( 'user_leaves_space' === $term ) { $context['pluggable_data'] = [ 'space' => $space_result, 'user' => WordPress::get_sample_user_context(), 'userId' => 1, 'by' => 'self', ]; $context['response_type'] = 'live'; } if ( 'course_created' === $term || 'course_updated' === $term || 'course_published' === $term ) { $context['pluggable_data'] = [ 'course' => $course_result, ]; $context['response_type'] = 'live'; } if ( 'course_deleted' === $term ) { $context['pluggable_data'] = [ 'course' => $result ]; $context['response_type'] = 'live'; } if ( 'comment_deleted' === $term ) { $context['pluggable_data'] = [ 'comment_id' => $result ]; $context['response_type'] = 'live'; } if ( 'new_comment_added' === $term || 'comment_updated' === $term ) { $context['pluggable_data'] = [ 'comment' => [ 'id' => $result['id'], 'user_id' => $result['user_id'], 'post_id' => $result['post_id'], 'parent_id' => $result['parent_id'], 'reactions_count' => $result['reactions_count'], 'message' => $result['message'], 'message_rendered' => $result['message_rendered'], 'meta' => unserialize( $result['meta'] ), 'type' => $result['type'], 'content_type' => $result['content_type'], 'status' => $result['status'], 'is_sticky' => $result['is_sticky'], 'created_at' => $result['created_at'], 'updated_at' => $result['updated_at'], 'xprofile' => [ 'id' => $profile_result['id'], 'user_id' => $profile_result['user_id'], 'total_points' => $profile_result['total_points'], 'username' => $profile_result['username'], 'status' => $profile_result['status'], 'is_verified' => $profile_result['is_verified'], 'display_name' => $profile_result['display_name'], 'avatar' => $profile_result['avatar'], 'short_description' => $profile_result['short_description'], 'last_activity' => $profile_result['last_activity'], 'meta' => unserialize( $profile_result['meta'] ), 'created_at' => $profile_result['created_at'], 'updated_at' => $profile_result['updated_at'], ], ], ]; $context['response_type'] = 'live'; } if ( 'user_enrolls_course' === $term || 'user_unenrolls_course' === $term || 'user_completes_course' === $term ) { $context['pluggable_data'] = [ 'course' => $course_result, 'user' => WordPress::get_sample_user_context(), 'userId' => 1, ]; $context['response_type'] = 'live'; } if ( 'user_requests_join_space' === $term ) { $context['pluggable_data'] = [ 'space' => $space_result, 'user' => WordPress::get_sample_user_context(), 'userId' => 1, ]; $context['response_type'] = 'live'; } } else { $sample_space_data = [ 'id' => 101, 'slug' => 'sample-space', 'title' => 'Sample Space', 'description' => 'This is a sample space description.', 'type' => 'community', 'privacy' => 'public', 'status' => 'active', 'serial' => 'SP101', 'created_at' => '2025-01-01 10:00:00', 'created_by' => 1, 'updated_at' => '2025-01-05 12:00:00', 'settings' => [ 'coursetype' => 'self_paced', 'emoji' => '😍', 'shapesvg' => null, 'disablecomments' => 'no', 'hidememberscount' => 'no', ], ]; $sample_profile_data = [ 'id' => 1, 'user_id' => 1, 'total_points' => 100, 'username' => 'sampleuser', 'status' => 'active', 'is_verified' => true, 'display_name' => 'Sample User', 'avatar' => 'https://example.com/avatar.jpg', 'short_description' => 'This is a sample user.', 'last_activity' => '2025-01-08 15:00:00', 'meta' => [ 'website' => 'https://example.com', 'coverphoto' => 'https://example.com/coverphoto.jpg', ], 'created_at' => '2025-01-01 10:00:00', 'updated_at' => '2025-01-05 12:00:00', ]; if ( 'feed_created' === $term || 'feed_updated' === $term || 'space_feed_created' === $term ) { $context['pluggable_data'] = [ 'feed' => [ 'id' => 1, 'userid' => 1, 'parentid' => null, 'title' => 'Sample Feed', 'slug' => 'sample-feed', 'message' => 'This is a sample message for the feed.', 'messagerendered' => '

This 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; } /** * Get WPCafe Branch List. * * @param array $data data. * * @return array */ public function search_wpcafe_branch_list( $data ) { $options = []; if ( ! class_exists( 'WpCafe\Models\Location_Model' ) ) { return [ 'options' => $options, 'hasMore' => false, ]; } $locations = \WpCafe\Models\Location_Model::all(); if ( ! empty( $locations ) ) { foreach ( $locations as $location ) { $options[] = [ 'label' => $location->restaurant_name, 'value' => $location->term_id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Kadence Forms. * * @param array $data data. * @return array */ public function search_kadence_forms( $data ) { $options = []; $args = [ 'post_type' => 'kadence_form', 'post_status' => 'publish', 'numberposts' => -1, ]; $forms = get_posts( $args ); if ( ! empty( $forms ) ) { foreach ( $forms as $form ) { $options[] = [ 'label' => $form->post_title, 'value' => $form->ID, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Code Snippets list. * * @param array $data data. * * @return array */ public function search_code_snippets_list( $data ) { $options = []; if ( ! function_exists( 'Code_Snippets\get_snippets' ) ) { return [ 'options' => $options, 'hasMore' => false, ]; } $all_snippets = \Code_Snippets\get_snippets(); $search_term = isset( $data['search_term'] ) ? strtolower( $data['search_term'] ) : ''; foreach ( $all_snippets as $snippet ) { if ( ! is_object( $snippet ) || empty( $snippet->id ) ) { continue; } $name = isset( $snippet->name ) ? $snippet->name : ''; if ( ! empty( $search_term ) && false === strpos( strtolower( $name ), $search_term ) ) { continue; } $options[] = [ 'label' => $name, 'value' => (string) $snippet->id, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } } GlobalSearchController::get_instance();