onse_type'] = 'live'; } else { $role = 'subscriber'; $context['pluggable_data'] = [ 'wp_user_id' => 1, 'user_login' => 'test', 'display_name' => 'Test User', 'user_firstname' => 'Test', 'user_lastname' => 'User', 'user_email' => 'testuser@gmail.com', 'user_role' => [ $role ], ]; $context['response_type'] = 'sample'; } return $context; } /** * Get last data for Ultimate Member Register trigger. * * @param array $data data. * @return mixed */ public function search_ultimate_member_user_inactive( $data ) { $context = []; $args = [ 'orderby' => 'user_id', 'meta_key' => 'account_status', 'meta_value' => 'inactive', 'order' => 'ASC', 'number' => 1, ]; $users = get_users( $args ); if ( ! empty( $users ) ) { $user = $users[0]; $pluggable_data = []; $pluggable_data[] = WordPress::get_user_context( $user->ID ); $pluggable_data['user_account_status'] = 'inactive'; $context['pluggable_data'] = $pluggable_data; $context['response_type'] = 'live'; } else { $role = 'subscriber'; $context['pluggable_data'] = [ 'wp_user_id' => 1, 'user_login' => 'test', 'display_name' => 'Test User', 'user_firstname' => 'Test', 'user_lastname' => 'User', 'user_email' => 'testuser@gmail.com', 'user_role' => [ $role ], 'user_account_status' => 'inactive', ]; $context['response_type'] = 'sample'; } return $context; } /** * Get last data for Ultimate Member Change Role trigger. * * @param array $data data. * @return mixed */ public function search_ultimate_member_user_role_change( $data ) { $context = []; $role = $data['filter']['role']['value']; $args = [ 'number' => 1, 'role' => $role, ]; $users = get_users( $args ); shuffle( $users ); if ( ! empty( $users ) ) { $user = $users[0]; $pluggable_data = WordPress::get_user_context( $user->ID ); $context['pluggable_data'] = $pluggable_data; $context['response_type'] = 'live'; } else { $role = isset( $args['role'] ) ? $args['role'] : 'subscriber'; $context['pluggable_data'] = [ 'wp_user_id' => 1, 'user_login' => 'test', 'display_name' => 'Test User', 'user_firstname' => 'Test', 'user_lastname' => 'User', 'user_email' => 'testuser@gmail.com', 'user_role' => [ $role ], 'user_account_status' => 'inactive', ]; $context['response_type'] = 'sample'; } return $context; } /** * Get JetEngine WP Posttypes. * * @param array $data data. * * @return array */ public function search_je_posttype_list( $data ) { $post_types = get_post_types( [ 'public' => true ], 'objects' ); $post_types = apply_filters( 'suretriggers_post_types', $post_types ); if ( isset( $post_types['attachment'] ) ) { unset( $post_types['attachment'] ); } $options = []; foreach ( $post_types as $post_type => $details ) { $options[] = [ 'label' => $details->label, 'value' => $post_type, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get JetEngine WP fields. * * @param array $data data. * * @return array */ public function search_je_field_list( $data ) { $post_type = $data['dynamic']; $metaboxes = (array) get_option( 'jet_engine_meta_boxes', [] ); $post_fields = array_filter( $metaboxes, function( $metabox ) { /** * * Ignore line * * @phpstan-ignore-next-line */ return 'post' === $metabox['args']['object_type']; } ); $post_fields_count = count( $post_fields ); $options = []; if ( ! empty( $post_fields ) ) { if ( is_array( $post_fields ) ) { foreach ( $post_fields as $post_field ) { if ( in_array( $post_type, $post_field['args']['allowed_post_type'], true ) ) { foreach ( $post_field['meta_fields'] as $meta_field ) { $options[] = [ 'label' => $meta_field['title'], 'value' => $meta_field['name'], ]; } } } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Last Updated Field Data. * * @param array $data data. * @return array */ public function search_jet_engine_field_data( $data ) { global $wpdb; $context = []; $field = (int) ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); $post_type = $data['filter']['wp_post_type']['value']; if ( -1 === $field ) { $metaboxes = (array) get_option( 'jet_engine_meta_boxes', [] ); $post_fields = array_filter( $metaboxes, function( $metabox ) { /** * * Ignore line * * @phpstan-ignore-next-line */ return 'post' === $metabox['args']['object_type']; } ); $options = []; if ( ! empty( $post_fields ) ) { if ( is_array( $post_fields ) ) { foreach ( $post_fields as $post_field ) { if ( in_array( $post_type, $post_field['args']['allowed_post_type'], true ) ) { foreach ( $post_field['meta_fields'] as $meta_field ) { $options[] = $meta_field['name']; } } } } } $random_key = array_rand( $options ); $random_value = $options[ $random_key ]; $string = '%' . $random_value . '%'; } else { $string = '%' . $data['filter']['field_id']['value'] . '%'; } $result = $wpdb->get_results( $wpdb->prepare( 'SELECT post_id FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key LIKE %s', [ $string ] ), ARRAY_A ); $ids = []; if ( ! empty( $result ) ) { foreach ( $result as $val ) { $ids[] = $val['post_id']; } } $lastupdated_args = [ 'post_type' => $post_type, 'orderby' => 'modified', 'post__in' => $ids, 'posts_per_page' => 1, ]; $lastupdated_loop = get_posts( $lastupdated_args ); $response = []; if ( ! empty( $result ) ) { $context['post'] = $lastupdated_loop[0]; $meta_value = get_post_meta( $lastupdated_loop[0]->ID, sprintf( '%s', $data['filter']['field_id']['value'] ), true ); $meta_key = sprintf( '%s', $data['filter']['field_id']['value'] ); $context[ $meta_key ] = $meta_value; $response['pluggable_data'] = $context; $response['response_type'] = 'live'; } else { $response = json_decode( '{"response_type":"sample","pluggable_data":{"post":{"ID":198,"post_author":"1","post_date":"2023-02-08 13:31:13","post_date_gmt":"2023-02-08 13:31:13","post_content":"New Category1 - content","post_title":"jennjennn - Post - jenn","post_excerpt":"","post_status":"publish","comment_status":"open","ping_status":"open","post_password":"","post_name":"jennjennn-post-jenn","to_ping":"","pinged":"","post_modified":"2023-04-10 06:23:40","post_modified_gmt":"2023-04-10 06:23:40","post_content_filtered":"","post_parent":0,"guid":"https:\/\/examplewp.local\/jennjennn-post-jenn\/","menu_order":0,"post_type":"post","post_mime_type":"","comment_count":"0","filter":"raw"},"enter-post-extra-content-title":"dummy"}}', true ); } return $response; } /** * Get Formidable Forms. * * @param array $data data. * * @return array|void */ public function search_formidable_form_list( $data ) { if ( ! class_exists( 'FrmForm' ) ) { return; } $page = $data['page']; $term = $data['search_term']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $per_page = 10; $query = [ [ 'or' => 1, 'name LIKE' => $term, 'parent_form_id' => null, ], ]; $query['is_template'] = 0; $query['status !'] = 'trash'; $forms_list = FrmForm::getAll( $query, '', $offset . ',' . $per_page ); $form_count = FrmForm::getAll( $query ); $form_count = count( $form_count ); $options = []; if ( ! empty( $forms_list ) ) { if ( is_array( $forms_list ) ) { foreach ( $forms_list as $form ) { $options[] = [ 'label' => $form->name, 'value' => $form->id, ]; } } } return [ 'options' => $options, 'hasMore' => $form_count > $limit && $form_count > $offset, ]; } /** * Get JetFormBuilder Form List. * * @param array $data data. * * @return array|void */ public function search_jetform_list( $data ) { if ( ! class_exists( '\Jet_Form_Builder\Classes\Tools' ) ) { return; } $forms = \Jet_Form_Builder\Classes\Tools::get_forms_list_for_js(); $options = []; foreach ( $forms as $form ) { if ( ! empty( $form['value'] ) ) { $options[] = [ 'label' => esc_html( $form['label'] ), 'value' => esc_attr( $form['value'] ), ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Forminator Form List. * * @param array $data data. * * @return array|void */ public function search_forminator_form_list( $data ) { if ( ! class_exists( 'Forminator_API' ) ) { return; } $forms = Forminator_API::get_forms( null, 1, 10 ); $options = []; foreach ( $forms as $form ) { $options[] = [ 'label' => isset( $form->settings ) && isset( $form->settings['form_name'] ) ? $form->settings['form_name'] : $form->name, 'value' => $form->id, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get BbPress topics list. * * @param array $data data. * * @return array|void */ public function search_bbp_topic_list( $data ) { $page = $data['page']; $forum_id = $data['dynamic']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $args = [ 'post_type' => 'topic', 'offset' => $offset, 'meta_query' => [ [ 'key' => '_bbp_forum_id', 'value' => $forum_id, 'compare' => '==', ], ], ]; $topics = get_posts( $args ); $topics_count = wp_count_posts( 'topic' )->publish; $options = []; if ( ! empty( $topics ) ) { if ( is_array( $topics ) ) { foreach ( $topics as $topic ) { $options[] = [ 'label' => $topic->post_title, 'value' => $topic->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $topics_count > $limit && $topics_count > $offset, ]; } /** * Search Last Updated Field Data. * * @param array $data data. * @return array */ public function search_bbp_last_data( $data ) { global $wpdb; $post_type = $data['post_type']; $trigger = $data['search_term']; $context = []; if ( 'topic' === $post_type ) { $post_id = $data['filter']['forum']['value']; if ( -1 === $post_id ) { $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID = postmeta.post_id WHERE posts.post_type = 'topic' AND postmeta.meta_key= '_bbp_forum_id' ORDER BY posts.ID DESC LIMIT 1" ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID=postmeta.post_id WHERE posts.post_type ='topic' AND postmeta.meta_key= '_bbp_forum_id' AND postmeta.meta_value=%s ORDER BY posts.ID DESC LIMIT 1", $post_id ) ); } } elseif ( 'reply' === $post_type ) { $post_id = $data['filter']['topic']['value']; if ( -1 === $post_id ) { $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID = postmeta.post_id WHERE posts.post_type = 'reply' AND postmeta.meta_key= '_bbp_topic_id' ORDER BY posts.ID DESC LIMIT 1" ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID=postmeta.post_id WHERE posts.post_type ='reply' AND postmeta.meta_key= '_bbp_topic_id' AND postmeta.meta_value=%s ORDER BY posts.ID DESC LIMIT 1", $post_id ) ); } } $response = []; if ( ! empty( $result ) ) { if ( 'bbpress_topic_created' === $trigger ) { $topic_id = $result[0]->post_id; $forum_id = $result[0]->meta_value; $topic = get_the_title( $topic_id ); $topic_link = get_the_permalink( $topic_id ); $topic_description = get_the_content( null, false, $topic_id ); $topic_status = get_post_status( $topic_id ); $forum = get_the_title( $forum_id ); $forum_link = get_the_permalink( $forum_id ); $forum_description = get_the_content( null, false, $forum_id ); $forum_status = get_post_status( $forum_id ); $forum = [ 'forum' => $forum_id, 'forum_title' => $forum, 'forum_link' => $forum_link, 'forum_description' => $forum_description, 'forum_status' => $forum_status, ]; $topic = [ 'topic' => $topic_id, 'topic_title' => $topic, 'topic_link' => $topic_link, 'topic_description' => $topic_description, 'topic_status' => $topic_status, ]; $user_id = $result[0]->post_author; if ( '0' != $user_id ) { $context = array_merge( WordPress::get_user_context( $user_id ), $forum, $topic ); } else { $anonymous_data = [ 'bbp_anonymous_name' => get_post_meta( $result[0]->ID, '_bbp_anonymous_name', true ), 'bbp_anonymous_email' => get_post_meta( $result[0]->ID, '_bbp_anonymous_email', true ), 'bbp_anonymous_website' => get_post_meta( $result[0]->ID, '_bbp_anonymous_website', true ), ]; $context = array_merge( $anonymous_data, $forum, $topic ); } $response['pluggable_data'] = $context; $response['response_type'] = 'live'; } else { $reply_id = $result[0]->post_id; $topic_id = $result[0]->meta_value; $forum_id = get_post_meta( $topic_id, '_bbp_forum_id', true ); $forum_id = intval( '"' . $forum_id . '"' ); $reply = get_the_title( $reply_id ); $reply_link = get_the_permalink( $reply_id ); $reply_description = get_the_content( null, false, $reply_id ); $reply_status = get_post_status( $reply_id ); $topic = get_the_title( $topic_id ); $topic_link = get_the_permalink( $topic_id ); $topic_description = get_the_content( null, false, $topic_id ); $topic_status = get_post_status( $topic_id ); $forum = get_the_title( $forum_id ); $forum_link = get_the_permalink( $forum_id ); $forum_description = get_the_content( null, false, $forum_id ); $forum_status = get_post_status( $forum_id ); $forum = [ 'forum' => $forum_id, 'forum_title' => $forum, 'forum_link' => $forum_link, 'forum_description' => $forum_description, 'forum_status' => $forum_status, ]; $topic = [ 'topic' => $topic_id, 'topic_title' => $topic, 'topic_link' => $topic_link, 'topic_description' => $topic_description, 'topic_status' => $topic_status, ]; $reply = [ 'reply_title' => $reply, 'reply_link' => $reply_link, 'reply_description' => $reply_description, 'reply_status' => $reply_status, ]; $user_id = $result[0]->post_author; if ( '0' != $user_id ) { $context = array_merge( WordPress::get_user_context( $user_id ), $forum, $topic, $reply ); } else { $anonymous_data = [ 'bbp_anonymous_name' => get_post_meta( $result[0]->ID, '_bbp_anonymous_name', true ), 'bbp_anonymous_email' => get_post_meta( $result[0]->ID, '_bbp_anonymous_email', true ), 'bbp_anonymous_website' => get_post_meta( $result[0]->ID, '_bbp_anonymous_website', true ), ]; $context = array_merge( $anonymous_data, $forum, $topic, $reply ); } $response['pluggable_data'] = $context; $response['response_type'] = 'live'; } } return $response; } /** * Search Last Updated Field Data. * * @param array $data data. * @return array|void */ public function search_happyform_list( $data ) { if ( ! function_exists( 'happyforms_get_form_controller' ) ) { return; } $form_controller = happyforms_get_form_controller(); $forms = $form_controller->do_get(); $options = []; if ( ! empty( $forms ) ) { foreach ( $forms as $form ) { $options[] = [ 'label' => $form['post_title'], 'value' => $form['ID'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Memberpress Course List. * * @param array $data data. * * @return array|void */ public function search_mpc_lessons_list( $data ) { if ( ! class_exists( '\memberpress\courses\models\Lesson' ) ) { return; } global $wpdb; $options = []; $course_id = $data['dynamic']; $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mpcs_sections WHERE course_id =%s", $course_id ) ); $sections = []; foreach ( $result as $rec ) { $sections[] = [ 'id' => $rec->id, 'title' => $rec->title, ]; } if ( is_array( $sections ) && count( $sections ) > 0 ) { foreach ( $sections as $section ) { $post_types = \memberpress\courses\models\Lesson::lesson_cpts(); $placeholders = implode( ', ', array_fill( 0, count( $post_types ), '%s' ) ); $sql = "SELECT * FROM {$wpdb->posts} AS p JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id AND pm.meta_key = %s AND pm.meta_value = %s JOIN {$wpdb->postmeta} AS pm_order ON p.ID = pm_order.post_id AND pm_order.meta_key = %s WHERE p.post_type in ( {$placeholders} ) AND p.post_status <> 'trash' ORDER BY pm_order.meta_value * 1"; $args = array_merge( [ models\Lesson::$section_id_str, $section['id'], models\Lesson::$lesson_order_str, ], $post_types ); $query = $wpdb->prepare( $sql, $args ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $db_lessons = $wpdb->get_results( $query ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared foreach ( $db_lessons as $lesson ) { $options[] = [ 'label' => $section['title'] . '->' . $lesson->post_title, 'value' => $lesson->ID, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Memberpress Course List. * * @param array $data data. * * @return array|void */ public function search_gp_rank_type_list( $data ) { global $wpdb; $posts = $wpdb->get_results( "SELECT ID, post_name, post_title, post_type FROM $wpdb->posts WHERE post_type LIKE 'rank-type' AND post_status = 'publish' ORDER BY post_title ASC" ); $posts_count = count( $posts ); $options = []; if ( $posts ) { foreach ( $posts as $post ) { $options[] = [ 'label' => $post->post_title, 'value' => $post->post_name, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get MPC last data. * * @param array $data data. * * @return array */ public function search_mpc_last_data( $data ) { global $wpdb; $trigger = $data['search_term']; $course_data = []; $lesson_data = []; $context = []; if ( 'mpc_course_completed' === $trigger ) { $course_id = (int) ( isset( $data['filter']['course']['value'] ) ? $data['filter']['course]']['value'] : '-1' ); if ( $course_id > 0 ) { $course = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE ID= %s ORDER BY id DESC LIMIT 1", $course_id ) ); } else { $course = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}posts where post_type = 'mpcs-course' ORDER BY id DESC LIMIT 1" ); } if ( ! empty( $course ) ) { $course_data = [ 'course_id' => $course->ID, 'course_title' => get_the_title( $course_id ), 'course_url' => get_permalink( $course_id ), 'course_featured_image_id' => get_post_meta( $course_id, '_thumbnail_id', true ), 'course_featured_image_url' => get_the_post_thumbnail_url( $course_id ), ]; } $user_progress = $wpdb->get_row( $wpdb->prepare( "SELECT user_id FROM {$wpdb->prefix}mpcs_user_progress WHERE course_id=%s", $course_id ) ); if ( ! empty( $user_progress ) ) { $context['response_type'] = 'live'; $context['pluggable_data'] = array_merge( WordPress::get_user_context( $user_progress->user_id ), $course_data, $lesson_data ); } else { $sample_data = '{"pluggable_data":{"wp_user_id":1,"user_login":"johnd","display_name":"johnd","user_firstname":"johnd","user_lastname":"johnd","user_email":"hello@example.io","user_role":["administrator","subscriber","tutor_instructor","bbp_keymaster"],"course_id":617,"course_title":"Course One","course_url":"https:\/\/connector.com\/courses\/course-one\/","course_featured_image_id":"","course_featured_image_url":false} ,"response_type":"sample"} '; $context = json_decode( $sample_data, true ); } } elseif ( 'mpc_lesson_completed' === $trigger ) { $lesson_id = (int) ( isset( $data['filter']['lesson']['value'] ) ? $data['filter']['lesson']['value'] : '-1' ); $course_id = (int) $data['filter']['course']['value']; if ( $lesson_id > 0 ) { $lesson = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE ID= %s ORDER BY id DESC LIMIT 1", $lesson_id ) ); } else { $lesson = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}posts where post_type = 'mpcs-lesson' ORDER BY id DESC LIMIT 1" ); } if ( ! empty( $lesson ) ) { $lesson_data = [ 'lesson_id' => $lesson->ID, 'lesson_title' => get_the_title( $lesson_id ), 'lesson_url' => get_permalink( $lesson_id ), 'lesson_featured_image_id' => get_post_meta( $lesson_id, '_thumbnail_id', true ), 'lesson_featured_image_url' => get_the_post_thumbnail_url( $lesson_id ), ]; $lesson_section_id = get_post_meta( $lesson->ID, '_mpcs_lesson_section_id', true ); $section = $wpdb->get_row( $wpdb->prepare( "SELECT course_id FROM {$wpdb->prefix}mpcs_sections WHERE ID= %s", $lesson_section_id ) ); $course_data = [ 'course_id' => $course_id, 'course_title' => get_the_title( $course_id ), 'course_url' => get_permalink( $course_id ), 'course_featured_image_id' => get_post_meta( $course_id, '_thumbnail_id', true ), 'course_featured_image_url' => get_the_post_thumbnail_url( $section->course_id ), ]; } $user_progress = $wpdb->get_row( $wpdb->prepare( "SELECT user_id FROM {$wpdb->prefix}mpcs_user_progress WHERE lesson_id= %s AND course_id=%s", $lesson_id, $course_id ) ); if ( ! empty( $user_progress ) ) { $context['response_type'] = 'live'; $context['pluggable_data'] = array_merge( WordPress::get_user_context( $user_progress->user_id ), $course_data, $lesson_data ); } else { $sample_data = '{"pluggable_data":{"wp_user_id":1,"user_login":"johnd","display_name":"johnd","user_firstname":"john","user_lastname":"dev","user_email":"johnd@example.com","user_role":["administrator","subscriber","tutor_instructor","bbp_keymaster"],"lesson_id":620,"lesson_title":"second section","lesson_url":"https:\/\/connector.com\/courses\/course-one\/lessons\/second-section\/","lesson_featured_image_id":"","lesson_featured_image_url":false,"course_id":617,"course_title":"Course One","course_url":"https:\/\/connector.com\/courses\/course-one\/","course_featured_image_id":"","course_featured_image_url":false},"response_type":"sample"}'; $context = json_decode( $sample_data, true ); } } return $context; } /** Get GamiPress Rank List. * * @param array $data data. * * @return array|void */ public function search_gp_rank_list( $data ) { global $wpdb; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $args = [ 'post_type' => $data['dynamic']['rank_type'], 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', 's' => $data['search_term'], ]; $rank_type = get_posts( $args ); $count_args = [ 'post_type' => $data['dynamic']['rank_type'], 'posts_per_page' => -1, 'post_status' => 'publish', 's' => $data['search_term'], ]; $rank_posts = get_posts( $count_args ); $rank_type_count = count( $rank_posts ); $options = []; if ( $rank_type ) { foreach ( $rank_type as $rank ) { $options[] = [ 'label' => $rank->post_title, 'value' => $rank->ID, ]; } } return [ 'options' => $options, 'hasMore' => $rank_type_count > $limit && $rank_type_count > $offset, ]; } /** * Get GamiPress PointType List. * * @param array $data data. * * @return array|void */ public function search_gp_point_type_list( $data ) { global $wpdb; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $args = [ 'post_type' => 'points-type', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', 's' => $data['search_term'], ]; $point_type = get_posts( $args ); $count_args = [ 'post_type' => 'points-type', 'posts_per_page' => -1, 'post_status' => 'publish', 's' => $data['search_term'], ]; $count_point_type = get_posts( $count_args ); $point_type_count = count( $count_point_type ); $options = []; if ( $point_type ) { foreach ( $point_type as $point ) { $options[] = [ 'label' => $point->post_title, 'value' => $point->ID, ]; } } return [ 'options' => $options, 'hasMore' => $point_type_count > $limit && $point_type_count > $offset, ]; } /** * Get GamiPress AchievementType List. * * @param array $data data. * * @return array|void */ public function search_gp_achivement_type_list( $data ) { global $wpdb; $posts = $wpdb->get_results( "SELECT ID, post_name, post_title, post_type FROM $wpdb->posts WHERE post_type LIKE 'achievement-type' AND post_status = 'publish' ORDER BY post_title ASC" ); $posts_count = count( $posts ); $options = []; if ( $posts ) { foreach ( $posts as $post ) { $options[] = [ 'label' => $post->post_title, 'value' => $post->post_name, ]; } } $options[] = [ 'label' => 'Points awards', 'value' => 'points-award', ]; $options[] = [ 'label' => 'Step', 'value' => 'step', ]; $options[] = [ 'label' => 'Rank requirement', 'value' => 'rank-requirement', ]; return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get GamiPress Award List. * * @param array $data data. * * @return array|void */ public function search_gp_award_list( $data ) { global $wpdb; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $args = [ 'post_type' => $data['dynamic']['achivement_type'], 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', 's' => $data['search_term'], ]; $award_type = get_posts( $args ); $count_args = [ 'post_type' => $data['dynamic']['achivement_type'], 'posts_per_page' => -1, 'post_status' => 'publish', 's' => $data['search_term'], ]; $count_award_type = get_posts( $count_args ); $award_type_count = count( $count_award_type ); $options = []; if ( $award_type ) { foreach ( $award_type as $award ) { $options[] = [ 'label' => $award->post_title, 'value' => $award->ID, ]; } } return [ 'options' => $options, 'hasMore' => $award_type_count > $limit && $award_type_count > $offset, ]; } /** * Get Woocommerce Subscription Product List. * * @param array $data data. * * @return array|void */ public function search_wc_subscription_product_list( $data ) { global $wpdb; $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT posts.ID, posts.post_title FROM $wpdb->posts as posts LEFT JOIN $wpdb->term_relationships as rel ON (posts.ID = rel.object_id) WHERE rel.term_taxonomy_id IN (SELECT term_id FROM $wpdb->terms WHERE slug IN ('subscription','variable-subscription')) AND posts.post_type = %s AND posts.post_status = %s UNION ALL SELECT ID, post_title FROM $wpdb->posts WHERE post_type = %s AND post_status = %s ORDER BY post_title", 'product', 'publish', 'shop_subscription', 'publish' ) ); $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $subscriptions_products = []; $subscription_products_count = 10; if ( function_exists( 'wc_get_products' ) ) { $product_query = wc_get_products( [ 'type' => [ 'subscription', 'variable-subscription' ], 'posts_per_page' => $limit, 'offset' => $offset, 'paginate' => true, ] ); if ( is_object( $product_query ) ) { $subscriptions_products = $product_query->products; $subscription_products_count = $product_query->total; } } $options = []; if ( $subscriptions ) { foreach ( $subscriptions as $post ) { $options[] = [ 'label' => $post->post_title, 'value' => $post->ID, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } elseif ( $subscriptions_products ) { foreach ( $subscriptions_products as $product ) { $title = $product->get_name(); $options[] = [ 'label' => ! empty( $title ) ? $title : $product->get_id(), 'value' => $product->get_id(), ]; } return [ 'options' => $options, 'hasMore' => $subscription_products_count > $limit && $subscription_products_count > $offset, ]; } else { return [ 'options' => $options, 'hasMore' => false, ]; } } /** * Get Woocommerce Subscriptions Variation list. * * @param array $data data. * * @return array|void */ public function search_wc_variable_subscription_list( $data ) { global $wpdb; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); if ( ! function_exists( 'wc_get_products' ) ) { return; } $subscription_products = wc_get_products( [ 'type' => [ 'variable-subscription' ], 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'date', 'order' => 'DESC', ] ); $subscription_products_count = count( (array) $subscription_products ); $options = []; if ( $subscription_products ) { foreach ( (array) $subscription_products as $product ) { $options[] = [ 'label' => $product->get_title(), 'value' => $product->get_id(), ]; } } return [ 'options' => $options, 'hasMore' => $subscription_products_count > $limit && $subscription_products_count > $offset, ]; } /** * Get Woocommerce Variation list. * * @param array $data data. * * @return array|void */ public function search_wc_variation_list( $data ) { global $wpdb; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $args = [ 'post_type' => 'product_variation', 'post_parent' => $data['dynamic']['variable_subscription'], 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'ID', 'order' => 'ASC', 'post_status' => 'publish', ]; $variation = get_posts( $args ); $variation_count = count( $variation ); $options = []; if ( $variation ) { foreach ( $variation as $product ) { $options[] = [ 'label' => ! empty( $product->post_excerpt ) ? $product->post_excerpt : $product->post_title, 'value' => $product->ID, ]; } } return [ 'options' => $options, 'hasMore' => $variation_count > $limit && $variation_count > $offset, ]; } /** * Get Membership List. * * @param array $data data. * * @return array */ public function search_membership_list( $data ) { global $wpdb; $levels = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}pmpro_membership_levels ORDER BY id ASC" ); $options = []; if ( $levels ) { foreach ( $levels as $level ) { $options[] = [ 'label' => $level->name, 'value' => $level->id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get EventsManager last data. * * @param array $data data. * * @return array */ public function search_events_manager_data( $data ) { global $wpdb; $trigger = $data['search_term']; $context = []; $post_id = (int) ( isset( $data['filter']['post_id']['value'] ) ? $data['filter']['post_id']['value'] : '-1' ); if ( 'em_user_register_in_event' === $trigger ) { if ( $post_id > 0 ) { $event_id_id = get_post_meta( $post_id, '_event_id', true ); $all_bookings = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status NOT IN (2,3) AND b.event_id = %s AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1", $event_id_id ) ); } else { $all_bookings = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status NOT IN (2,3) AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1" ); } if ( ! empty( $all_bookings ) ) { $user_id = $all_bookings->person_id; $location = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_locations as b WHERE b.location_id = %s", $all_bookings->location_id ) ); $bookings = json_decode( (string) wp_json_encode( $all_bookings ), true ); $context['pluggable_data'] = array_merge( WordPress::get_user_context( $user_id ), is_array( $bookings ) ? $bookings : [] ); if ( ! empty( $location ) ) { $locations = json_decode( (string) wp_json_encode( $location ), true ); $context['pluggable_data'] = array_merge( $context['pluggable_data'], is_array( $locations ) ? $locations : [] ); } $context['response_type'] = 'live'; } } elseif ( 'em_user_unregister_from_event' === $trigger ) { if ( $post_id > 0 ) { $event_id_id = get_post_meta( $post_id, '_event_id', true ); $all_bookings = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status IN (2,3) AND b.event_id = %s AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1", $event_id_id ) ); } else { $all_bookings = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status IN (2,3) AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1" ); } if ( ! empty( $all_bookings ) ) { $user_id = $all_bookings->person_id; $bookings = json_decode( (string) wp_json_encode( $all_bookings ), true ); $context['pluggable_data'] = array_merge( WordPress::get_user_context( $user_id ), is_array( $bookings ) ? $bookings : [] ); $context['response_type'] = 'live'; } } elseif ( 'em_user_booking_approved' === $trigger ) { if ( $post_id > 0 ) { $event_id_id = get_post_meta( $post_id, '_event_id', true ); $all_bookings = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status=1 AND b.event_id = %s AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1", $event_id_id ) ); } else { $all_bookings = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status=1 AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1" ); } if ( ! empty( $all_bookings ) ) { $user_id = $all_bookings->person_id; $location = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_locations as b WHERE b.location_id = %s", $all_bookings->location_id ) ); $bookings = json_decode( (string) wp_json_encode( $all_bookings ), true ); $context['pluggable_data'] = array_merge( WordPress::get_user_context( $user_id ), is_array( $bookings ) ? $bookings : [] ); if ( ! empty( $location ) ) { $locations = json_decode( (string) wp_json_encode( $location ), true ); $context['pluggable_data'] = array_merge( $context['pluggable_data'], is_array( $locations ) ? $locations : [] ); } $context['response_type'] = 'live'; } } elseif ( 'em_user_registers_event_with_specific_ticket' === $trigger ) { if ( $post_id > 0 ) { $event_id_id = get_post_meta( $post_id, '_event_id', true ); $all_bookings = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status NOT IN (2,3) AND b.event_id = %s AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1", $event_id_id ) ); } if ( ! empty( $all_bookings ) ) { $ticket_id = (int) $data['filter']['ticket_id']['value']; $all_ticket_bookings = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_tickets_bookings as b INNER JOIN {$wpdb->prefix}em_tickets as e ON b.ticket_id = e.ticket_id WHERE b.booking_id = %d AND e.ticket_id = %d ORDER BY b.ticket_booking_id DESC LIMIT 1", $all_bookings->booking_id, $ticket_id ) ); if ( ! empty( $all_ticket_bookings ) ) { $user_id = $all_bookings->person_id; $location = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_locations as b WHERE b.location_id = %s", $all_bookings->location_id ) ); $bookings_str = wp_json_encode( $all_bookings ); $ticket_bookings_str = wp_json_encode( $all_ticket_bookings ); $context['pluggable_data'] = array_merge( WordPress::get_user_context( $user_id ) ); if ( is_string( $bookings_str ) && is_string( $ticket_bookings_str ) ) { $bookings_arr = json_decode( $bookings_str, true ); $ticket_bookings_arr = json_decode( $ticket_bookings_str, true ); if ( is_array( $bookings_arr ) && is_array( $ticket_bookings_arr ) ) { $context['pluggable_data'] = array_merge( $context['pluggable_data'], $bookings_arr, $ticket_bookings_arr ); } } if ( ! empty( $location ) ) { $location_str = wp_json_encode( $location ); if ( is_string( $location_str ) ) { $location_arr = json_decode( $location_str, true ); if ( is_array( $location_arr ) ) { $context['pluggable_data'] = array_merge( $context['pluggable_data'], $location_arr ); } } } $context['response_type'] = 'live'; } } } return $context; } /** * Get Events Manager Events Ticket list. * * @param array $data data. * * @return array|void */ public function search_em_event_tickets( $data ) { global $wpdb; $options = []; $event = $data['dynamic']['post_id']; $event_id = $wpdb->get_var( $wpdb->prepare( "SELECT event_id FROM {$wpdb->prefix}em_events WHERE post_id = %d", $event ) ); $tickets = $wpdb->get_results( $wpdb->prepare( "SELECT ticket_id,ticket_name FROM {$wpdb->prefix}em_tickets WHERE event_id = %d ORDER BY ticket_id", $event_id[0] ) ); if ( $tickets ) { foreach ( $tickets as $ticket ) { $options[] = [ 'label' => $ticket->ticket_name, 'value' => $ticket->ticket_id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get learnpress last data. * * @param array $data data. * * @return array */ public function search_learnpress_lms_last_data( $data ) { global $wpdb; $trigger = $data['search_term']; $course_data = []; $lesson_data = []; $context = []; if ( 'learnpress_course_completed' === $trigger ) { $course_id = (int) ( isset( $data['filter']['course']['value'] ) ? $data['filter']['course']['value'] : '-1' ); if ( $course_id > 0 ) { $course = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_id= %s && user_id>0 && status= 'finished' ORDER BY item_id DESC LIMIT 1", $course_id ) ); } else { $course = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_type= 'lp_course' && user_id>0 && status= 'finished' ORDER BY item_id DESC LIMIT 1" ); } if ( ! empty( $course ) ) { $course_data = array_merge( WordPress::get_user_context( $course->user_id ), LearnPress::get_lpc_course_context( $course->item_id ) ); $context['response_type'] = 'live'; $context['pluggable_data'] = $course_data; } } elseif ( 'learnpress_lesson_completed' === $trigger ) { $lesson_id = (int) ( isset( $data['filter']['lesson']['value'] ) ? $data['filter']['lesson']['value'] : '-1' ); if ( $lesson_id > 0 ) { $lesson = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_id= %s && user_id>0 && status= 'completed' ORDER BY item_id DESC LIMIT 1", $lesson_id ) ); } else { $lesson = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_type= 'lp_lesson' && user_id>0 && status= 'completed' ORDER BY item_id DESC LIMIT 1" ); } if ( ! empty( $lesson ) ) { $lesson_data = array_merge( WordPress::get_user_context( $lesson->user_id ), LearnPress::get_lpc_lesson_context( $lesson->item_id ), LearnPress::get_lpc_course_context( $lesson->ref_id ) ); $context['response_type'] = 'live'; $context['pluggable_data'] = $lesson_data; } } elseif ( 'learnpress_user_enrolled_in_course' === $trigger ) { $course_id = (int) ( isset( $data['filter']['course']['value'] ) ? $data['filter']['course']['value'] : '-1' ); if ( $course_id > 0 ) { $course = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_id= %s && status= 'enrolled' ORDER BY item_id DESC LIMIT 1", $course_id ) ); } else { $course = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_type= 'lp_course' && user_id>0 && status= 'enrolled' ORDER BY item_id DESC LIMIT 1" ); } if ( ! empty( $course ) ) { $course_data = array_merge( WordPress::get_user_context( $course->user_id ), LearnPress::get_lpc_course_context( $course->item_id ) ); $context['response_type'] = 'live'; $context['pluggable_data'] = $course_data; } } return $context; } /** * Get Woocommerce Memberships Plan List. * * @param array $data data. * * @return array|void */ public function search_wc_membership_plan_list( $data ) { global $wpdb; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $args = [ 'post_type' => 'wc_membership_plan', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', 'fields' => 'ids', ]; $loop = new WP_Query( $args ); $plans = (array) $loop->posts; $plans_count = wp_count_posts( 'wc_membership_plan' )->publish; $options = []; if ( ! empty( $plans ) ) { if ( is_array( $plans ) ) { foreach ( $plans as $plan_id ) { $options[] = [ 'label' => get_the_title( $plan_id ), 'value' => $plan_id, ]; } } } return [ 'options' => $options, 'hasMore' => $plans_count > $limit && $plans_count > $offset, ]; } /** * Get BuddyPress Private group. * * @param array $data data. * * @return array|void */ public function search_bp_private_group_list( $data ) { global $wpdb; $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups WHERE status = 'private'" ); $options = []; if ( $groups ) { foreach ( $groups as $group ) { $options[] = [ 'label' => $group->name, 'value' => $group->id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get BuddyPress Public group. * * @param array $data data. * * @return array|void */ public function search_bp_public_group_list( $data ) { global $wpdb; $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups WHERE status = 'public'" ); $options = []; if ( $groups ) { foreach ( $groups as $group ) { $options[] = [ 'label' => $group->name, 'value' => $group->id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get BuddyPress group. * * @param array $data data. * * @return array|void */ public function search_bp_group_list( $data ) { global $wpdb; $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups" ); $options = []; if ( $groups ) { foreach ( $groups as $group ) { $options[] = [ 'label' => $group->name, 'value' => $group->id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get BuddyPress field. * * @param array $data data. * * @return array|void */ public function search_bp_field_list( $data ) { global $wpdb; $base_group_id = 1; if ( function_exists( 'bp_xprofile_base_group_id' ) ) { $base_group_id = bp_xprofile_base_group_id(); } $xprofile_fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}bp_xprofile_fields WHERE parent_id = 0 AND group_id = %d ORDER BY field_order ASC", $base_group_id ) ); $options = []; if ( ! empty( $xprofile_fields ) ) { foreach ( $xprofile_fields as $xprofile_field ) { $options[] = [ 'label' => $xprofile_field->name, 'value' => $xprofile_field->id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get BuddyPress member type. * * @param array $data data. * * @return array|void */ public function search_bp_member_type_list( $data ) { $options = []; if ( function_exists( 'bp_get_member_types' ) ) { $types = bp_get_member_types( [] ); if ( $types ) { foreach ( $types as $key => $type ) { $options[] = [ 'label' => $type, 'value' => $key, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get last data for WP All Import. * * @param array $data data. * @return mixed */ public function search_wp_all_import_last_data( $data ) { global $wpdb; $post_type = $data['filter']['post_type']['value']; $trigger = $data['search_term']; if ( 'wp_all_import_post_type_imported' === $trigger ) { if ( -1 == $post_type ) { $imports = $wpdb->get_row( "SELECT post_id FROM {$wpdb->prefix}pmxi_posts ORDER BY id DESC LIMIT 1", ARRAY_A ); $posts[0] = $imports['post_id']; } else { $imports = $wpdb->get_results( "SELECT post_id FROM {$wpdb->prefix}pmxi_posts", ARRAY_A ); $imports = array_column( $imports, 'post_id' ); $args = [ 'posts_per_page' => 1, 'post_type' => $post_type, 'post__in' => $imports, ]; $posts = get_posts( $args ); } } elseif ( 'wp_all_import_completed' === $trigger ) { $imports = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}pmxi_imports WHERE failed = 0 ORDER BY id DESC LIMIT 1", ARRAY_A ); } elseif ( 'wp_all_import_failed' === $trigger ) { $imports = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}pmxi_imports WHERE failed = 1 ORDER BY id DESC LIMIT 1", ARRAY_A ); } if ( 'wp_all_import_post_type_imported' === $trigger && empty( $imports ) ) { $context = json_decode( '{"response_type":"sample","pluggable_data":{"ID": 1,"post_author": "1","post_date": "2023-07-12 06:31:35","post_date_gmt": "2023-07-12 06:31:35","post_content": "","post_title": "Test","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "test","to_ping": "","pinged": "","post_modified": "2023-07-12 06:31:35","post_modified_gmt": "2023-07-12 06:31:35","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example.com\/test\/","menu_order": 0,"post_type": "post","post_mime_type": "","comment_count": "0","filter": "raw"}}', true ); return $context; } elseif ( empty( $imports ) ) { $context = json_decode( '{"response_type":"sample","pluggable_data":{"id": "1","parent_import_id": "0","name": "demowpinstawpxyz.WordPress.2023_07_12.xml","friendly_name": "","type": "upload","feed_type": "","path": "\/wpallimport\/uploads\/ee8816eebf7a373454cdd1189c831241\/demowpinstawpxyz.WordPress.2023_07_12.xml","xpath": "\/rss","registered_on": "2023-07-12 05:10:29","root_element": "rss","processing": "0","executing": "0","triggered": "0","queue_chunk_number": "0","first_import": "2023-07-12 05:09:41","count": "1","imported": "0","created": "0","updated": "0","skipped": "1","deleted": "0","changed_missing": "0","canceled": "0","canceled_on": "0000-00-00 00:00:00","failed": "0","failed_on": "0000-00-00 00:00:00","settings_update_on": "0000-00-00 00:00:00","last_activity": "2023-07-12 05:10:24","iteration": "1"}}', true ); return $context; } $context['response_type'] = 'live'; if ( ! empty( $posts ) ) { $context['pluggable_data'] = WordPress::get_post_context( $posts[0] ); } else { $context['pluggable_data'] = $imports; } return $context; } /** * Get Wp Simple Pay Forms. * * @param array $data data. * * @return array */ public function search_wp_simple_pay_forms( $data ) { $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $forms = get_posts( [ 'post_type' => 'simple-pay', 'posts_per_page' => $limit, 'offset' => $offset, 'fields' => 'ids', ] ); $forms_count = wp_count_posts( 'simple-pay' )->publish; $options = []; if ( ! empty( $forms ) ) { foreach ( $forms as $form_id ) { if ( function_exists( 'simpay_get_form' ) ) { $form = simpay_get_form( $form_id ); $options[] = [ 'label' => null !== get_the_title( $form_id ) ? $form->company_name : get_the_title( $form_id ), 'value' => $form_id, ]; } } } return [ 'options' => $options, 'hasMore' => $forms_count > $limit && $forms_count > $offset, ]; } /** * Get Post list as per post type for metabox. * * @param array $data data. * * @return array */ public function search_mb_posts_list( $data ) { $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $posts = get_posts( [ 'post_type' => $data['dynamic'], 'posts_per_page' => $limit, 'offset' => $offset, 'fields' => 'ids', ] ); $all_posts = get_posts( [ 'post_type' => $data['dynamic'], 'posts_per_page' => -1, 'fields' => 'ids', ] ); $posts_count = count( $all_posts ); $options = []; if ( ! empty( $posts ) ) { foreach ( $posts as $post ) { $title = html_entity_decode( get_the_title( $post ), ENT_QUOTES, 'UTF-8' ); $options[] = [ 'label' => $title, 'value' => $post, ]; } } return [ 'options' => $options, 'hasMore' => $posts_count > $limit && $posts_count > $offset, ]; } /** * Get Metabox Custom box in Post list. * * @param array $data data. * * @return array */ public function search_mb_field_list( $data ) { if ( ! function_exists( 'rwmb_get_object_fields' ) ) { return []; } $options = []; $metabox_fields = (array) rwmb_get_object_fields( $data['dynamic'] ); foreach ( $metabox_fields as $metabox_field ) { if ( ! empty( $metabox_field['id'] ) && ! empty( $metabox_field['name'] ) ) { $options[] = [ 'label' => $metabox_field['name'], 'value' => $metabox_field['id'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Metabox Custom box user list. * * @param array $data data. * * @return array */ public function search_mb_user_field_list( $data ) { if ( ! function_exists( 'rwmb_get_object_fields' ) ) { return []; } $options = []; $metabox_fields = (array) rwmb_get_object_fields( null, 'user' ); foreach ( $metabox_fields as $metabox_field ) { if ( ! empty( $metabox_field['id'] ) && ! empty( $metabox_field['name'] ) ) { $options[] = [ 'label' => $metabox_field['name'], 'value' => $metabox_field['id'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Last Updated Field Data for MetaBox. * * @param array $data data. * @return array */ public function search_meta_box_field_data( $data ) { global $wpdb; $context = []; $field = (int) ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); $post_type = $data['filter']['wp_post_type']['value']; $post = $data['filter']['wp_post']['value']; if ( -1 === $field ) { if ( function_exists( 'rwmb_get_object_fields' ) ) { $metaboxes = rwmb_get_object_fields( $post_type ); if ( ! empty( $metaboxes ) ) { $random_key = array_rand( $metaboxes ); $field = $random_key; } else { $result = ''; } } } else { $field = $data['filter']['field_id']['value']; } if ( function_exists( 'rwmb_meta' ) ) { $result = rwmb_meta( $field, '', $post ); } $response = []; if ( ! empty( $result ) ) { $response['pluggable_data'] = array_merge( [ $field => $result ], WordPress::get_post_context( $post ) ); $response['response_type'] = 'live'; } else { $response = json_decode( '{"response_type":"sample","pluggable_data":{"custom_description": "custom message", "ID": 1, "post_author": "1", "post_date": "2023-05-31 13:26:24", "post_date_gmt": "2023-05-31 13:26:24", "post_content": "", "post_title": "Test", "post_excerpt": "", "post_status": "publish", "comment_status": "open", "ping_status": "open", "post_password": "", "post_name": "test", "to_ping": "", "pinged": "", "post_modified": "2023-08-17 09:15:56", "post_modified_gmt": "2023-08-17 09:15:56", "post_content_filtered": "", "post_parent": 0, "guid": "https:\/\/example.com\/?p=1", "menu_order": 0, "post_type": "post", "post_mime_type": "", "comment_count": "2", "filter": "raw"}}', true ); } return $response; } /** * Search Last Updated User Field Data MetaBox. * * @param array $data data. * @return array */ public function search_user_meta_box_field_data( $data ) { global $wpdb; $context = []; $field = (int) ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); if ( -1 === $field ) { if ( function_exists( 'rwmb_get_object_fields' ) ) { $metabox_fields = (array) rwmb_get_object_fields( null, 'user' ); if ( ! empty( $metabox_fields ) ) { $random_key = array_rand( $metabox_fields ); $field = $random_key; } else { $result = ''; } } } else { $field = $data['filter']['field_id']['value']; } $users = get_users( [ 'fields' => 'ID', 'meta_key' => $field, ] ); if ( ! empty( $users ) ) { $user_random_key = array_rand( $users ); $user_id = $user_random_key; if ( function_exists( 'rwmb_get_value' ) ) { $result = rwmb_get_value( $field, [ 'object_type' => 'user' ], $users[ $user_id ] ); } $response = []; if ( ! empty( $result ) ) { $context = [ 'field_id' => $field, $field => $result, 'user' => WordPress::get_user_context( $users[ $user_id ] ), ]; $response['pluggable_data'] = $context; $response['response_type'] = 'live'; } else { $response = json_decode( '{ "response_type": "sample", "pluggable_data": { "field_id": "gender", "user": { "wp_user_id": 114, "user_login": "test", "display_name": "test", "user_firstname": "test", "user_lastname": "test", "user_email": "test@test.com", "user_role": [ "subscriber" ] } } }', true ); } } else { $response = json_decode( '{ "response_type": "sample", "pluggable_data": { "field_id": "gender", "user": { "wp_user_id": 114, "user_login": "test", "display_name": "test", "user_firstname": "test", "user_lastname": "test", "user_email": "test@test.com", "user_role": [ "subscriber" ] } } }', true ); } return $response; } /** * Search forms of Pie Forms. * * @param array $data data. * @return array */ public function search_wp_polls_list( $data ) { global $wpdb; $options = []; if ( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'pollsq' ) ) ) { $results = $wpdb->get_results( 'SELECT pollq_id, pollq_question FROM ' . $wpdb->prefix . 'pollsq WHERE pollq_active = 1' ); if ( $results ) { foreach ( $results as $result ) { $options[] = [ 'label' => $result->pollq_question, 'value' => $result->pollq_id, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search answers of WP-Polls questions. * * @param array $data data. * @return array */ public function search_wp_polls_answers( $data ) { global $wpdb; $options = []; $poll_id = $data['dynamic']; if ( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'pollsa' ) ) ) { if ( '-1' !== $poll_id ) { $results = $wpdb->get_results( $wpdb->prepare( 'SELECT polla_aid, polla_answers FROM ' . $wpdb->prefix . 'pollsa WHERE polla_qid = %d', $poll_id ) ); } else { $results = $wpdb->get_results( 'SELECT polla_aid, polla_answers FROM ' . $wpdb->prefix . 'pollsa' ); } if ( $results ) { foreach ( $results as $result ) { $options[] = [ 'label' => $result->polla_answers, 'value' => $result->polla_aid, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get last data for trigger. * * @param array $data data. * @return array */ public function search_wp_polls_triggers_last_data( $data ) { global $wpdb; $context = []; $context['response_type'] = 'sample'; $poll = [ 'poll_id' => 1, 'question' => 'Which skills are you interested to learn?', 'answers' => 'Web Development, Graphic Designing, Content Writing, Digital Marketing', 'start_date' => '2023-08-29 17:19:13', 'end_date' => 'Not set', 'selected_answers' => 'Content Writing, Web Development', 'selected_answer_id' => 2, ]; $poll_data = $wpdb->get_row( "SELECT pollip_qid AS poll_id, pollip_aid AS answer_id FROM {$wpdb->prefix}pollsip ORDER BY pollip_id DESC LIMIT 1" ); if ( ! empty( $poll_data ) ) { $poll = WpPolls::get_poll_context( (string) $poll_data->answer_id, (int) $poll_data->poll_id ); $poll['selected_answer_id'] = (int) $poll_data->answer_id; $context['response_type'] = 'live'; } $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; if ( 'poll_submitted' === $term ) { unset( $poll['selected_answer_id'] ); } $context['pluggable_data'] = $poll; return $context; } /** * Get ACF Custom fields list. * * @param array $data data. * * @return array */ public function search_acf_post_field_list( $data ) { $post_id = $data['dynamic']['wp_post']; $selected_post_type = $data['dynamic']['wp_post_type']; if ( -1 === $post_id ) { $args = [ 'numberposts' => 1, 'fields' => 'ids', 'orderby' => 'rand', 'post_type' => $selected_post_type, ]; $posts = get_posts( $args ); $post_id = $posts[0]; } $args = [ 'post_id' => $post_id, ]; if ( ! is_numeric( $post_id ) ) { $args = [ 'post_type' => $post_id, ]; } $options = []; if ( function_exists( 'acf_get_field_groups' ) ) { $field_groups_collection = acf_get_field_groups( $args ); foreach ( $field_groups_collection as $field_group ) { if ( function_exists( 'acf_get_fields' ) ) { $field_groups[] = acf_get_fields( $field_group['key'] ); } } if ( ! empty( $field_groups ) && is_array( $field_groups ) ) { foreach ( $field_groups as $field_groups ) { foreach ( $field_groups as $field_group ) { $options[] = [ 'value' => $field_group['name'], 'label' => ! empty( $field_group['label'] ) ? $field_group['label'] : $field_group['name'], ]; } } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get ACF Custom fields list. * * @param array $data data. * * @return array */ public function search_acf_user_field_list( $data ) { if ( ! function_exists( 'acf_get_fields' ) ) { return []; } if ( ! function_exists( 'acf_get_field_groups' ) ) { return []; } $groups_user_form = []; $options = []; if ( function_exists( 'acf_get_field_groups' ) ) { $field_groups = acf_get_field_groups(); foreach ( $field_groups as $group ) { if ( ! empty( $group['location'] ) ) { foreach ( $group['location'] as $locations ) { foreach ( $locations as $location ) { if ( 'user_form' === $location['param'] || 'user_role' === $location['param'] || 'current_user' === $location['param'] || 'current_user_role' === $location['param'] ) { $groups_user_form[] = $group; } } } } } if ( empty( $groups_user_form ) ) { return []; } $key_values = array_map( function ( $item ) { return $item['key']; }, $groups_user_form ); $unique_keys = array_unique( $key_values ); $unique_array = array_intersect_key( $groups_user_form, $unique_keys ); foreach ( $unique_array as $group ) { if ( function_exists( 'acf_get_fields' ) ) { $group_fields = acf_get_fields( $group['key'] ); } if ( ! empty( $group_fields ) ) { foreach ( $group_fields as $field ) { $options[] = [ 'value' => $field['name'], 'label' => $field['label'], ]; } } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get ACF Custom fields list. * * @param array $data data. * * @return array */ public function search_acf_options_field_list( $data ) { if ( ! function_exists( 'acf_get_fields' ) ) { return []; } if ( ! function_exists( 'acf_get_field_groups' ) ) { return []; } $groups_options_form = []; $options = []; if ( function_exists( 'acf_get_field_groups' ) ) { $field_groups = acf_get_field_groups(); foreach ( $field_groups as $group ) { if ( ! empty( $group['location'] ) ) { foreach ( $group['location'] as $locations ) { foreach ( $locations as $location ) { if ( 'options_page' === $location['param'] ) { $groups_options_form[] = $group; } } } } } if ( empty( $groups_options_form ) ) { return []; } $key_values = array_map( function ( $item ) { return $item['key']; }, $groups_options_form ); $unique_keys = array_unique( $key_values ); $unique_array = array_intersect_key( $groups_options_form, $unique_keys ); foreach ( $unique_array as $group ) { if ( function_exists( 'acf_get_fields' ) ) { $group_fields = acf_get_fields( $group['key'] ); } if ( ! empty( $group_fields ) ) { foreach ( $group_fields as $field ) { $options[] = [ 'value' => $field['name'], 'label' => $field['label'], ]; } } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Last Updated Field Data for ACF. * * @param array $data data. * @return array */ public function search_acf_post_field_data( $data ) { $context = []; $field = ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); $post_type = $data['filter']['wp_post_type']['value']; $post = $data['filter']['wp_post']['value']; if ( -1 === $post ) { $args = [ 'numberposts' => 1, 'fields' => 'ids', 'orderby' => 'rand', 'post_type' => $post_type, ]; $posts = get_posts( $args ); $post = $posts[0]; } if ( -1 === $field ) { $args = [ 'post_id' => $post, ]; if ( function_exists( 'acf_get_field_groups' ) ) { $field_groups_collection = acf_get_field_groups( $args ); } if ( ! empty( $field_groups_collection ) ) { foreach ( $field_groups_collection as $field_group ) { if ( function_exists( 'acf_get_fields' ) ) { $field_groups[] = acf_get_fields( $field_group['key'] ); } } } $fields = []; if ( ! empty( $field_groups ) && is_array( $field_groups ) ) { foreach ( $field_groups as $field_groups ) { $fields[] = $field_groups; } } if ( ! empty( $fields ) ) { $random_key = array_rand( $fields[0] ); $field_key = $fields[0][ $random_key ]; $field = $field_key['name']; } else { $result = ''; } } else { $field = $data['filter']['field_id']['value']; } if ( function_exists( ( 'get_field' ) ) ) { $result = get_field( $field, $post ); } $response = []; if ( ! empty( $result ) ) { $post_fields = []; if ( function_exists( 'get_fields' ) ) { $post_fields = get_fields( $post ); } $response['pluggable_data'] = array_merge( [ $field => $result ], [ 'field_id' => $field ], [ 'post_fields' => $post_fields ], [ 'post' => WordPress::get_post_context( $post ) ], [ 'wp_post' => $post ], [ 'wp_post_type' => get_post_type( $post ) ] ); $response['response_type'] = 'live'; } else { $response = json_decode( '{"response_type":"sample","pluggable_data":{"custom_description": "custom message", "ID": 1, "post_author": "1", "post_date": "2023-05-31 13:26:24", "post_date_gmt": "2023-05-31 13:26:24", "post_content": "", "post_title": "Test", "post_excerpt": "", "post_status": "publish", "comment_status": "open", "ping_status": "open", "post_password": "", "post_name": "test", "to_ping": "", "pinged": "", "post_modified": "2023-08-17 09:15:56", "post_modified_gmt": "2023-08-17 09:15:56", "post_content_filtered": "", "post_parent": 0, "guid": "https:\/\/example.com\/?p=1", "menu_order": 0, "post_type": "post", "post_mime_type": "", "comment_count": "2", "filter": "raw"}}', true ); } return $response; } /** * Search Last Updated User Field Data ACF. * * @param array $data data. * @return array */ public function search_acf_user_field_data( $data ) { global $wpdb; $context = []; $field = (int) ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); if ( -1 === $field ) { $groups_user_form = []; if ( function_exists( 'acf_get_field_groups' ) ) { $field_groups = acf_get_field_groups(); } if ( ! empty( $field_groups ) ) { foreach ( $field_groups as $group ) { if ( ! empty( $group['location'] ) ) { foreach ( $group['location'] as $locations ) { foreach ( $locations as $location ) { if ( 'user_form' === $location['param'] || 'user_role' === $location['param'] || 'current_user' === $location['param'] || 'current_user_role' === $location['param'] ) { $groups_user_form[] = $group; } } } } } $field_groups = $groups_user_form; } if ( empty( $field_groups ) ) { $result = ''; } $fields = []; if ( ! empty( $field_groups ) ) { foreach ( $field_groups as $group ) { if ( function_exists( 'acf_get_fields' ) ) { $group_fields = acf_get_fields( $group['key'] ); } if ( ! empty( $group_fields ) ) { foreach ( $group_fields as $field ) { $fields[] = $group_fields; } } } } if ( ! empty( $fields ) ) { $random_key = array_rand( $fields ); $field = $random_key; } else { $result = ''; } } else { $field = $data['filter']['field_id']['value']; } $users = get_users( [ 'fields' => 'ID', 'meta_key' => $field, ] ); if ( ! empty( $users ) ) { $user_random_key = array_rand( $users ); $user_id = $user_random_key; if ( function_exists( 'get_field' ) ) { $result = get_field( $field, 'user_' . $users[ $user_id ] ); } $response = []; if ( ! empty( $result ) ) { $context = [ 'field_id' => $field, $field => $result, 'user' => WordPress::get_user_context( $users[ $user_id ] ), ]; $response['pluggable_data'] = $context; $response['response_type'] = 'live'; } else { $response = json_decode( '{ "response_type": "sample", "pluggable_data": { "field_id": "gender", "user": { "wp_user_id": 114, "user_login": "test", "display_name": "test", "user_firstname": "test", "user_lastname": "test", "user_email": "test@test.com", "user_role": [ "subscriber" ] } } }', true ); } } else { $response = json_decode( '{ "response_type": "sample", "pluggable_data": { "field_id": "gender", "user": { "wp_user_id": 114, "user_login": "test", "display_name": "test", "user_firstname": "test", "user_lastname": "test", "user_email": "test@test.com", "user_role": [ "subscriber" ] } } }', true ); } return $response; } /** * Search Last Updated Options Field Data ACF. * * @param array $data data. * @return array */ public function search_acf_options_field_data( $data ) { global $wpdb; $context = []; $field = (int) ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); if ( -1 === $field ) { $groups_options_form = []; if ( function_exists( 'acf_get_field_groups' ) ) { $field_groups = acf_get_field_groups(); } if ( ! empty( $field_groups ) ) { foreach ( $field_groups as $group ) { if ( ! empty( $group['location'] ) ) { foreach ( $group['location'] as $locations ) { foreach ( $locations as $location ) { if ( 'options_page' === $location['param'] ) { $groups_options_form[] = $group; } } } } } } if ( empty( $groups_options_form ) ) { $result = ''; } $key_values = array_map( function ( $item ) { return $item['key']; }, $groups_options_form ); $unique_keys = array_unique( $key_values ); $unique_array = array_intersect_key( $groups_options_form, $unique_keys ); $fields = []; if ( ! empty( $unique_array ) ) { foreach ( $unique_array as $group ) { if ( function_exists( 'acf_get_fields' ) ) { $group_fields = acf_get_fields( $group['key'] ); } if ( ! empty( $group_fields ) ) { foreach ( $group_fields as $field ) { $fields[] = $group_fields; } } } } if ( ! empty( $fields ) ) { $random_key = array_rand( $fields ); $field = $random_key; } else { $result = ''; } } else { $field = $data['filter']['field_id']['value']; } if ( function_exists( 'get_field' ) ) { $option_value = get_field( $field, 'option' ); } if ( ! empty( $option_value ) ) { if ( function_exists( 'acf_get_field' ) ) { $options_fields = acf_get_field( $field ); if ( function_exists( 'acf_maybe_get' ) ) { $options_page = acf_maybe_get( $options_fields, 'parent' ); } } $context = [ 'field_id' => $field, $field => $option_value, ]; $response['pluggable_data'] = $context; $response['response_type'] = 'live'; } else { $response = json_decode( '{ "response_type": "sample", "pluggable_data": { "field_id": "optionpage", "optionpage": "newoption" } }', true ); } return $response; } /** * Get WP Fusion Tags list. * * @param array $data data. * * @return array */ public function search_wp_fusion_tag_list( $data ) { if ( ! function_exists( 'wp_fusion' ) ) { return []; } $options = []; $tags = wp_fusion()->settings->get( 'available_tags' ); if ( $tags ) { foreach ( $tags as $t_id => $tag ) { if ( is_array( $tag ) && isset( $tag['label'] ) ) { $options[] = [ 'value' => $t_id, 'label' => $tag['label'], ]; } else { $options[] = [ 'value' => $t_id, 'label' => $tag, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get list of events for Modern Events Calendar. * * @param array $data data. * @return array */ public function search_mec_events_list( $data ) { $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $args = [ 'post_type' => 'mec-events', 'post_status' => [ 'publish', 'private' ], 'posts_per_page' => -1, ]; $loop = new WP_Query( $args ); $events_count = count( $loop->posts ); $args = [ 'post_type' => 'mec-events', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => [ 'publish', 'private' ], ]; $loop = new WP_Query( $args ); $events = $loop->posts; $options = []; if ( ! empty( $events ) ) { foreach ( $events as $event ) { if ( isset( $event->ID ) ) { $options[] = [ 'label' => get_the_title( $event ), 'value' => $event->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $events_count > $limit && $events_count > $offset, ]; } /** * Search tickets of MEC events. * * @param array $data data. * @return array */ public function search_mec_event_tickets( $data ) { $options = []; $event_id = $data['dynamic']; $event_tickets = get_post_meta( $event_id, 'mec_tickets', true ); if ( ! empty( $event_tickets ) && is_array( $event_tickets ) ) { foreach ( $event_tickets as $ticket_id => $event_ticket ) { if ( isset( $event_ticket['name'] ) ) { $options[] = [ 'label' => $event_ticket['name'], 'value' => $ticket_id, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get last data for trigger. * * @param array $data data. * @return array */ public function search_mec_triggers_last_data( $data ) { global $wpdb; $context = []; $context['response_type'] = 'sample'; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; if ( 'new_event' === $term ) { $post_id = $wpdb->get_var( "SELECT post_id FROM {$wpdb->prefix}mec_events ORDER BY id DESC LIMIT 1" ); $live_data = [ 'post_id' => $post_id, 'event' => get_post_meta( $post_id ), 'post' => get_post( $post_id ), ]; if ( ! empty( $post_id ) ) { $context['pluggable_data'] = $live_data; $context['response_type'] = 'live'; } else { $context['pluggable_data'] = [ 'post_id' => 272, 'event' => [ 'mec_color' => [ 'e14d43' ], '_thumbnail_id' => [ 229 ], 'mec_location_id' => [ 49 ], 'mec_dont_show_map' => [ 0 ], 'mec_organizer_id' => [ 53 ], 'mec_start_date' => [ '2025-04-01' ], 'mec_start_time_hour' => [ 8 ], 'mec_start_time_minutes' => [ 0 ], 'mec_start_time_ampm' => [ 'AM' ], 'mec_start_day_seconds' => [ 32400 ], 'mec_start_datetime' => [ '2025-04-01 08:00 AM' ], 'mec_end_date' => [ '2025-04-01' ], 'mec_date' => [ 'a:3:{s:5:"start";a:4:{s:4:"date";s:10:"2025-03-29";s:4:"hour";s:1:"8";s:7:"minutes";s:1:"0";s:4:"ampm";s:2:"AM";}s:3:"end";a:4:{s:4:"date";s:10:"2025-03-29";s:4:"hour";s:1:"6";s:7:"minutes";s:1:"0";s:4:"ampm";s:2:"PM";}s:6:"allday";s:1:"1";}' ], 'mec_end_time_hour' => [ 6 ], 'mec_end_time_minutes' => [ 0 ], 'mec_end_time_ampm' => [ 'PM' ], 'mec_end_day_seconds' => [ 68400 ], 'mec_end_datetime' => [ '2025-04-01 06:00 PM' ], 'mec_allday' => [ 1 ], 'mec_fees' => [ 'a:0:{}' ], 'mec_op' => [ 'a:0:{}' ], 'mec_repeat' => [ 'a:0:{}' ], 'mec_booking' => [ 'a:0:{}' ], 'mec_comment' => [ '' ], 'mec_in_days' => [ '' ], 'mec_tickets' => [ 'a:0:{}' ], 'mec_reg_fields' => [ 'a:0:{}' ], 'mec_hourly_schedules' => [ 'a:0:{}' ], 'mec_ticket_variations' => [ 'a:0:{}' ], 'mec_hide_time' => [ 0 ], 'mec_hide_end_time' => [ 0 ], 'mec_repeat_status' => [ 0 ], 'mec_fees_global_inheritance' => [ 1 ], 'mec_ticket_variations_global_inheritance' => [ 1 ], 'mec_reg_fields_global_inheritance' => [ 1 ], 'mec_event_date_submit' => [ '20250331042811' ], 'mec_new_event_notif_sent' => [ 1 ], ], 'post' => [ 'ID' => 272, 'post_author' => 1, 'post_date' => '2025-03-31 04:28:09', 'post_date_gmt' => '2025-03-31 04:28:09', 'post_content' => '

Sample Event

', 'post_title' => 'Sample Event', 'post_status' => 'publish', 'comment_status' => 'open', 'ping_status' => 'closed', 'post_name' => 'sample-event', 'guid' => 'http://example.local/events/sample-event/', 'post_type' => 'mec-events', 'comment_count' => 0, ], ]; $context['response_type'] = 'sample'; } return $context; } $where = ''; if ( 'cancelled' === $term ) { $where = 'WHERE verified = -1'; } elseif ( 'confirmed' === $term ) { $where = 'WHERE confirmed = 1'; } elseif ( 'pending' === $term ) { $where = 'WHERE confirmed = 0'; } $event_id = (int) ( isset( $data['filter']['event_id']['value'] ) ? $data['filter']['event_id']['value'] : '-1' ); if ( -1 !== $event_id ) { if ( ! empty( $where ) ) { $where .= ' AND event_id = ' . $event_id; } else { $where = 'WHERE event_id = ' . $event_id; } } $event_data = $wpdb->get_row( "SELECT booking_id FROM {$wpdb->prefix}mec_bookings $where ORDER BY id DESC LIMIT 1" ); // @phpcs:ignore if ( ! empty( $event_data ) ) { $event = ModernEventsCalendar::get_event_context( (int) $event_data->booking_id ); $context['response_type'] = 'live'; } else { $event = [ 'event_id' => 1, 'title' => 'Sample Event', 'description' => 'Description of the sample event.', 'categories' => 'New, Sample', 'start_date' => 'September 13, 2023', 'start_time' => '8:00 AM', 'end_date' => 'September 13, 2023', 'end_time' => '11:00 AM', 'location' => 'City Hall', 'organizer' => 'John Doe', 'cost' => '5000', 'featured_image_id' => 1, 'featured_image_url' => 'https://example.com/wp-content/uploads/2022/12/Screenshot_20221127_021332.png', 'tickets' => [ [ 'id' => 1, 'name' => 'Silver', 'description' => 'Standard seat with reasonable price.', 'price' => '300', 'price_label' => 'USD', 'limit' => '20', ], [ 'id' => 2, 'name' => 'Premium', 'description' => 'VIP seat with high price.', 'price' => '500', 'price_label' => 'USD', 'limit' => '10', ], ], 'attendees' => [ [ 'id' => 1, 'email' => 'johndoe@test.com', 'name' => 'John Doe', ], [ 'id' => 2, 'email' => 'adamsmith@test.com', 'name' => 'Adam Smith', ], ], 'booking' => [ 'title' => 'johndoe@test.com - John Doe', 'transaction_id' => 'RSH59404', 'amount_payable' => '800', 'price' => '800', 'time' => '2023-09-07 06:40:32', 'payment_gateway' => 'Manual Pay', 'confirmation_status' => 'Pending', 'verification_status' => 'Verified', 'attendees_count' => 2, ], ]; } $context['pluggable_data'] = $event; return $context; } /** * Get form list Contact Form 7. * * @param array $data data. * * @return array */ public function search_contact_form7_list( $data ) { $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $posts = get_posts( [ 'post_type' => 'wpcf7_contact_form', 'posts_per_page' => $limit, 'offset' => $offset, ] ); $all_posts = get_posts( [ 'post_type' => 'wpcf7_contact_form', 'posts_per_page' => -1, ] ); $posts_count = count( $all_posts ); $options = []; if ( ! empty( $posts ) ) { foreach ( $posts as $post ) { $options[] = [ 'label' => get_the_title( $post->ID ), 'value' => $post->ID, ]; } } return [ 'options' => $options, 'hasMore' => $posts_count > $limit && $posts_count > $offset, ]; } /** * Get Thrive Leads form list * * @param array $data data. * * @return array */ public function search_thrive_leads_forms_list( $data ) { $options = []; $lg_ids = get_posts( [ 'post_type' => '_tcb_form_settings', 'fields' => 'id=>parent', 'posts_per_page' => -1, 'post_status' => 'any', ] ); if ( function_exists( 'tve_leads_get_form_variations' ) ) { foreach ( $lg_ids as $lg_id => $lg_parent ) { $variations = tve_leads_get_form_variations( $lg_parent ); foreach ( $variations as $variation ) { $options[] = [ 'label' => $variation['post_title'], 'value' => $lg_parent, ]; } } } return [ 'options' => array_unique( $options ), 'hasMore' => false, ]; } /** * Get Store Engine Products list * * @param array $data data. * * @return array */ public function search_store_engine_products( $data ) { $options = []; if ( ! class_exists( 'StoreEngine' ) ) { return $options; } $products = get_posts( [ 'post_type' => 'storeengine_product', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', ] ); foreach ( $products as $product ) { $current_price = get_post_meta( $product->ID, '_storeengine_product_price', true ); $price_display = ''; if ( ! empty( $current_price ) && is_numeric( $current_price ) ) { $price_display = ' - $' . number_format( floatval( $current_price ), 2 ); } $id_display = ' (ID: ' . $product->ID . ')'; $options[] = [ 'label' => $product->post_title . $price_display . $id_display, 'value' => $product->ID, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get all countries list from StoreEngine * * @param array $data data. * * @return array */ public function search_store_engine_countries( $data ) { $options = []; if ( ! class_exists( 'StoreEngine\Classes\Countries' ) ) { return [ 'options' => $options, 'hasMore' => false, ]; } $countries_obj = \StoreEngine\Classes\Countries::get_instance(); $countries = $countries_obj->get_countries(); foreach ( $countries as $code => $name ) { $options[] = [ 'label' => $name . ' (' . $code . ')', 'value' => $code, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Store Engine Last Data * * @param array $data data. * * @return array */ public function search_se_triggers_last_data( $data ) { $context = []; global $wpdb; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; if ( 'se_product_purchased' === $term ) { $product = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT 1", 'storeengine_product', 'publish' ), ARRAY_A ); if ( ! empty( $product ) ) { $product_meta = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d", $product['ID'] ), ARRAY_A ); $custom_metas = []; foreach ( $product_meta as $meta ) { if ( strpos( $meta['meta_key'], '_storeengine_' ) === 0 ) { $clean_key = ltrim( $meta['meta_key'], '_' ); $custom_metas[ $clean_key ] = maybe_unserialize( $meta['meta_value'] ); } } $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'storeengine_orders' ) ); $order = null; if ( $table_exists ) { $order = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}storeengine_orders ORDER BY id DESC LIMIT %d", 1 ), ARRAY_A ); } $customer_id = isset( $order['customer_id'] ) ? $order['customer_id'] : null; $user = null; if ( $customer_id ) { $user = get_userdata( $customer_id ); } else { $customers = get_users( [ 'role__in' => [ 'storeengine_customer', 'customer' ], 'number' => 1, 'orderby' => 'ID', 'order' => 'DESC', ] ); if ( ! empty( $customers ) ) { $user = $customers[0]; } else { $user = get_userdata( $product['post_author'] ); } } $product_data = [ 'id' => (int) $product['ID'], 'guid' => $product['guid'], 'post' => (int) $product['ID'], 'filter' => 'raw', 'pinged' => $product['pinged'], 'to_ping' => $product['to_ping'], 'order_id' => '', 'permalink' => get_permalink( $product['ID'] ), 'post_date' => $product['post_date'], 'post_name' => $product['post_name'], 'post_type' => $product['post_type'], 'user_role' => $user ? $user->roles : [], 'membership_details' => [ 'expiration_specific_date' => '', 'expiration_fixed_date_duration' => 0, 'is_enable_expiration' => 0, 'content_protects_rules' => [], 'membership_plan' => [ 'id' => null, 'name' => '', 'slug' => '', 'status' => '', ], ], 'menu_order' => (int) $product['menu_order'], 'post_title' => $product['post_title'], 'user_email' => $user ? $user->user_email : '', 'user_login' => $user ? $user->user_login : '', 'wp_user_id' => $user ? $user->ID : 0, 'ping_status' => $product['ping_status'], 'post_author' => (int) $product['post_author'], 'post_parent' => (int) $product['post_parent'], 'post_status' => $product['post_status'], 'custom_metas' => $custom_metas, 'display_name' => $user ? $user->display_name : '', 'post_content' => $product['post_content'], 'post_excerpt' => $product['post_excerpt'], 'comment_count' => (int) $product['comment_count'], 'post_date_gmt' => $product['post_date_gmt'], 'post_modified' => $product['post_modified'], 'post_password' => $product['post_password'], 'user_lastname' => $user ? get_user_meta( $user->ID, 'last_name', true ) : '', 'comment_status' => $product['comment_status'], 'post_mime_type' => $product['post_mime_type'], 'transaction_id' => '', 'user_firstname' => $user ? get_user_meta( $user->ID, 'first_name', true ) : '', 'user_registered' => $user ? $user->user_registered : '', 'post_modified_gmt' => $product['post_modified_gmt'], 'post_content_filtered' => $product['post_content_filtered'], ]; $integration = $wpdb->get_row( $wpdb->prepare( "SELECT integration_id, price_id FROM {$wpdb->prefix}storeengine_integrations WHERE product_id = %d AND provider = %s LIMIT 1", $product['ID'], 'storeengine/membership-addon' ) ); $membership_plan_id = isset( $integration->integration_id ) ? $integration->integration_id : null; if ( $membership_plan_id ) { $access_group = get_post( $membership_plan_id ); if ( 'storeengine_groups' === $access_group && $access_group->post_type ) { $product_data['membership_details']['membership_plan'] = [ 'id' => (int) $membership_plan_id, 'name' => $access_group->post_title, 'slug' => $access_group->post_name, 'status' => $access_group->post_status, ]; $expiration_data = get_post_meta( $membership_plan_id, '_storeengine_membership_expiration', true ); if ( $expiration_data && is_array( $expiration_data ) ) { $product_data['membership_details']['expiration_specific_date'] = isset( $expiration_data['specific_date'] ) ? $expiration_data['specific_date'] : ''; $product_data['membership_details']['expiration_fixed_date_duration'] = isset( $expiration_data['fixed_date_duration'] ) ? (int) $expiration_data['fixed_date_duration'] : 0; $product_data['membership_details']['is_enable_expiration'] = isset( $expiration_data['is_enable'] ) ? (int) $expiration_data['is_enable'] : 0;} $content_protects = get_post_meta( $membership_plan_id, '_storeengine_membership_content_protect_types', true ); if ( $content_protects && is_array( $content_protects ) ) { $product_data['membership_details']['content_protects_rules'] = $content_protects; } } } if ( $order ) { $product_data['order_id'] = (int) $order['id']; $product_data['transaction_id'] = isset( $order['transaction_id'] ) ? $order['transaction_id'] : ''; } $context['pluggable_data'] = $product_data; $context['response_type'] = 'live'; } else { $sample_data = [ 'id' => 53, 'guid' => 'http://suretriggers-wp.local/product/product-2/', 'post' => 53, 'filter' => 'raw', 'pinged' => '', 'to_ping' => '', 'order_id' => 43, 'permalink' => 'http://suretriggers-wp.local/product/product-2/', 'post_date' => '2025-07-24 07:01:01', 'post_name' => 'product-2', 'post_type' => 'storeengine_product', 'user_role' => [ 'storeengine_customer' ], 'membership_details' => [ 'expiration_specific_date' => '', 'expiration_fixed_date_duration' => 0, 'is_enable_expiration' => 0, 'content_protects_rules' => [], 'membership_plan' => [ 'id' => null, 'name' => '', 'slug' => '', 'status' => '', ], ], 'menu_order' => 0, 'post_title' => 'Product 2', 'user_email' => 'mucool@gmail.com', 'user_login' => 'mucool', 'wp_user_id' => 12, 'ping_status' => 'open', 'post_author' => 1, 'post_parent' => 0, 'post_status' => 'publish', 'custom_metas' => [ 'storeengine_product_hide' => '', 'storeengine_product_type' => 'simple', 'storeengine_product_shipping_type' => 'digital', 'storeengine_product_physical_weight' => '', 'storeengine_product_physical_weight_unit' => 'g', 'storeengine_product_digital_auto_complete' => 1, 'storeengine_product_integrated_plan_id' => 99, 'storeengine_product_gallery_ids' => [], 'storeengine_product_downloadable_files' => [ [ 'id' => '9bd1194a-0406-46f3-aff3-dc539cdc791f', 'name' => '', 'file' => 'http://suretriggers-wp.local/wp-content/uploads/2025/07/bd0f98d1bede01622fe7f03a4f8fdc2155abafb4.jpg', 'enabled' => 1, ], ], 'storeengine_upsell_ids' => [], 'storeengine_crosssell_ids' => [], ], 'display_name' => 'mucool titirmare', 'post_content' => '

sdfdsfsd

', 'post_excerpt' => '', 'comment_count' => 0, 'post_date_gmt' => '2025-07-24 07:01:01', 'post_modified' => '2025-07-24 08:14:01', 'post_password' => '', 'user_lastname' => 'titirmare', 'comment_status' => 'open', 'post_mime_type' => '', 'transaction_id' => '', 'user_firstname' => 'mucool', 'user_registered' => '2025-07-24 08:16:48', 'post_modified_gmt' => '2025-07-24 08:14:01', 'post_content_filtered' => '', ]; $context['pluggable_data'] = $sample_data; $context['response_type'] = 'sample'; } } return $context; } /** * Get list for Woocommerce Subscriptions * * @param array $data data. * * @return array */ public function search_wc_subscription_variation_products( $data ) { $options = []; global $wpdb; if ( ! function_exists( 'wc_get_product' ) ) { return []; } $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT posts.ID, posts.post_title FROM $wpdb->posts as posts LEFT JOIN $wpdb->term_relationships as rel ON (posts.ID = rel.object_id) WHERE rel.term_taxonomy_id IN (SELECT term_id FROM $wpdb->terms WHERE slug IN ('subscription','variable-subscription')) AND posts.post_type = %s AND posts.post_status = %s UNION ALL SELECT ID, post_title FROM $wpdb->posts WHERE post_type = %s AND post_status = %s ORDER BY post_title", 'product', 'publish', 'shop_subscription', 'publish' ) ); $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $subscriptions_products = []; $subscription_products_count = 10; if ( function_exists( 'wc_get_products' ) ) { $product_query = wc_get_products( [ 'type' => [ 'subscription', 'variable-subscription' ], 'posts_per_page' => $limit, 'offset' => $offset, 'paginate' => true, ] ); if ( is_object( $product_query ) ) { $subscriptions_products = $product_query->products; $subscription_products_count = $product_query->total; } } if ( $subscriptions ) { foreach ( $subscriptions as $product ) { $options[] = [ 'label' => $product->post_title . ' (#' . $product->ID . ')', 'value' => (int) $product->ID, ]; $product_s = wc_get_product( $product->ID ); /** * * Ignore line * * @phpstan-ignore-next-line */ if ( 'variable-subscription' == $product_s->product_type ) { $args = [ 'post_type' => 'product_variation', 'post_parent' => $product->ID, 'posts_per_page' => -1, 'orderby' => 'ID', 'order' => 'ASC', 'post_status' => 'publish', ]; $variations = get_posts( $args ); foreach ( $variations as $var ) { $options[] = [ 'label' => $var->post_title . ' (#' . $var->ID . ')', 'value' => $var->ID, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } elseif ( ! empty( $subscriptions_products ) ) { foreach ( $subscriptions_products as $product ) { $title = $product->get_name(); $options[] = [ 'label' => $title . ' (#' . $product->get_id() . ')', 'value' => $product->get_id(), ]; $product_s = wc_get_product( $product->get_id() ); /** * * Ignore line * * @phpstan-ignore-next-line */ if ( 'variable-subscription' == $product_s->product_type ) { $args = [ 'post_type' => 'product_variation', 'post_parent' => $product->get_id(), 'posts_per_page' => -1, 'orderby' => 'ID', 'order' => 'ASC', 'post_status' => 'publish', ]; $variations = get_posts( $args ); foreach ( $variations as $var ) { $options[] = [ 'label' => $var->post_title . ' (#' . $var->ID . ')', 'value' => $var->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $subscription_products_count > $limit && $subscription_products_count > $offset, ]; } else { return [ 'options' => $options, 'hasMore' => false, ]; } } /** * Get WS Forms form list * * @param array $data data. * * @return array */ public function search_ws_forms_list( $data ) { $options = []; global $wpdb; $forms = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wsf_form", 'ARRAY_A' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared foreach ( $forms as $form ) { $options[] = [ 'label' => $form['label'], 'value' => $form['id'], ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Learndash Achievement list * * @param array $data data. * * @return array */ public function search_ld_achievements_list( $data ) { $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $posts = get_posts( [ 'post_type' => 'ld-achievement', 'posts_per_page' => $limit, 'offset' => $offset, 'post_status' => [ 'publish' ], ] ); $posts_count = wp_count_posts( 'ld-achievement' )->publish; $options = []; if ( ! empty( $posts ) ) { foreach ( $posts as $post ) { $options[] = [ 'label' => get_the_title( $post->ID ), 'value' => $post->ID, ]; } } return [ 'options' => $options, 'hasMore' => $posts_count > $limit && $posts_count > $offset, ]; } /** * Get Advanced Ads list * * @param array $data data. * * @return array */ public function search_ads_list( $data ) { $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $posts = get_posts( [ 'post_type' => 'advanced_ads', 'posts_per_page' => $limit, 'offset' => $offset, 'post_status' => [ 'publish', 'draft' ], ] ); $posts_count = wp_count_posts( 'advanced_ads' )->publish; $options = []; if ( ! empty( $posts ) ) { foreach ( $posts as $post ) { $options[] = [ 'label' => get_the_title( $post->ID ), 'value' => $post->ID, ]; } } return [ 'options' => $options, 'hasMore' => $posts_count > $limit && $posts_count > $offset, ]; } /** * Advanced Ads pluggable data. * * @param array $data data. * @return array */ public function search_ad_last_data( $data ) { $context = []; $args = [ 'post_type' => 'advanced_ads', 'posts_per_page' => 1, 'orderby' => 'modified', 'order' => 'DESC', ]; if ( isset( $data['filter']['ad_status']['value'] ) ) { $post_status = $data['filter']['ad_status']['value']; $args['post_status'] = $post_status; } if ( isset( $data['filter']['ad_new_status']['value'] ) ) { $post_status = $data['filter']['ad_new_status']['value']; $args['post_status'] = $post_status; } if ( isset( $data['filter']['ad_id']['value'] ) ) { $post_id = $data['filter']['ad_id']['value']; if ( -1 != $post_id ) { if ( $post_id > 0 ) { $args['p'] = $post_id; } } } $posts = get_posts( $args ); if ( ! empty( $posts ) ) { $context['pluggable_data'] = $posts[0]; $context['pluggable_data'] = WordPress::get_post_context( $posts[0]->ID ); if ( isset( $data['filter']['ad_new_status']['value'] ) ) { $context['pluggable_data']['ad_new_status'] = $posts[0]->post_status; } if ( isset( $data['filter']['ad_old_status']['value'] ) ) { $context['pluggable_data']['ad_old_status'] = $data['filter']['ad_old_status']['value']; } $context['pluggable_data']['ad_id'] = $posts[0]->ID; if ( isset( $data['filter']['ad_status']['value'] ) ) { $context['pluggable_data']['ad_status'] = $posts[0]->post_status; } $context['response_type'] = 'live'; } else { $context['pluggable_data'] = [ 'ID' => 1, 'post' => 1, 'post_author' => 1, 'post_date' => '2022-11-18 12:18:14', 'post_date_gmt' => '2022-11-18 12:18:14', 'post_content' => 'Ad Post Content', 'post_title' => 'Ad Post', 'post_excerpt' => '', 'post_status' => 'draft', 'comment_status' => 'open', 'ping_status' => 'open', 'post_password' => '', 'post_name' => 'ad-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/ad-post/', 'menu_order' => 0, 'post_type' => 'advanced_ads', 'post_mime_type' => '', 'comment_count' => 0, 'filter' => 'raw', ]; if ( isset( $data['filter']['ad_new_status']['value'] ) ) { $context['pluggable_data']['ad_new_status'] = $data['filter']['ad_new_status']['value']; } if ( isset( $data['filter']['ad_old_status']['value'] ) ) { $context['pluggable_data']['ad_old_status'] = $data['filter']['ad_old_status']['value']; } $context['pluggable_data']['ad_id'] = 1; if ( isset( $data['filter']['ad_status']['value'] ) ) { $context['pluggable_data']['ad_status'] = $data['filter']['ad_status']['value']; } $context['response_type'] = 'sample'; } return $context; } /** * Get Newsletter lists * * @param array $data data. * * @return array */ public function search_newsletter_lists( $data ) { $options = []; if ( class_exists( '\Newsletter' ) ) { $lists = \Newsletter::instance()->get_lists(); if ( ! empty( $lists ) ) { foreach ( $lists as $list ) { $options[] = [ 'label' => $list->name, 'value' => 'list_' . $list->id, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Newsletter pluggable data. * * @param array $data data. * @return array */ public function search_newsletter_last_data( $data ) { $context = []; global $wpdb; $list = $data['filter']['list_id']['value']; if ( -1 == $list ) { $log = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . "newsletter WHERE status='C' ORDER BY id DESC LIMIT 1" ) ); //phpcs:ignore } else { // Validate column name against allowlist to prevent SQL injection. $allowed_lists = []; for ( $i = 1; $i <= 40; $i++ ) { $allowed_lists[] = 'list_' . $i; } $num = $list; if ( ! in_array( $num, $allowed_lists, true ) ) { return $context; } $location = 1; $sql = 'SELECT * FROM ' . $wpdb->prefix . "newsletter WHERE $num = %d AND status = 'C' ORDER BY id DESC LIMIT 1"; $log = $wpdb->get_results( $wpdb->prepare( $sql, $location ), ARRAY_A );// @phpcs:ignore } if ( ! empty( $log ) ) { $lists_arr = get_option( 'newsletter_lists' ); if ( -1 == $list ) { foreach ( $log[0] as $key => $val ) { if ( defined( 'NEWSLETTER_LIST_MAX' ) ) { for ( $i = 1; $i <= NEWSLETTER_LIST_MAX; $i++ ) { $list_key = "list_$i"; if ( $key == $list_key ) { if ( 1 == $val ) { $context['pluggable_data']['list_id'] = $key; if ( is_array( $lists_arr ) ) { if ( isset( $lists_arr[ $key ] ) ) { $list_name = $lists_arr[ $key ]; $context['pluggable_data']['list_name'] = $list_name; } } continue; } } } } if ( 'email' == $key ) { $context['pluggable_data']['email'] = $val; } } } else { $context['pluggable_data']['list_id'] = $list; $context['pluggable_data']['email'] = $log[0]['email']; if ( is_array( $lists_arr ) ) { if ( isset( $lists_arr[ $list ] ) ) { $list_name = $lists_arr[ $list ]; $context['pluggable_data']['list_name'] = $list_name; } } } $context['response_type'] = 'live'; } else { $context = json_decode( '{"response_type":"sample","pluggable_data":{"list_id": "list_1","email": "johnd@mailinator.com","list_name": "Contact List"}}', true ); } return $context; } /** * Get wpForo Forum list * * @param array $data data. * * @return array */ public function search_wp_forum_list( $data ) { if ( ! function_exists( 'WPF' ) ) { return []; } $forums = WPF()->forum->get_forums( [ 'type' => 'forum' ] ); $options = []; if ( ! empty( $forums ) ) { foreach ( $forums as $forum ) { $options[] = [ 'label' => $forum['title'], 'value' => $forum['forumid'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get wpForo Topic list * * @param array $data data. * * @return array */ public function search_wp_topic_list( $data ) { if ( ! function_exists( 'WPF' ) ) { return []; } $forum_id = $data['dynamic']; $topics = WPF()->topic->get_topics( [ 'forumid' => $forum_id ] ); $options = []; if ( ! empty( $topics ) ) { foreach ( $topics as $topic ) { $options[] = [ 'label' => $topic['title'], 'value' => $topic['topicid'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get wpForo Groups list * * @param array $data data. * * @return array */ public function search_wp_user_groups_list( $data ) { if ( ! function_exists( 'WPF' ) ) { return []; } $usergroups = WPF()->usergroup->get_usergroups(); $options = []; if ( ! empty( $usergroups ) ) { foreach ( $usergroups as $group ) { $options[] = [ 'label' => $group['name'], 'value' => intval( $group['groupid'] ), ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get wpForo Reputation list * * @param array $data data. * * @return array */ public function search_wp_foro_reputation_list( $data ) { if ( ! function_exists( 'WPF' ) ) { return []; } $levels = WPF()->member->levels(); $options = []; if ( ! empty( $levels ) ) { foreach ( $levels as $level ) { $options[] = [ 'label' => esc_attr__( 'Level', 'suretriggers' ) . ' ' . $level . ' - ' . WPF()->member->rating( $level, 'title' ), 'value' => strval( $level ), ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * WPForo new topic pluggable data. * * @param array $data data. * @return array */ public function search_pluggables_wpforo_topic_last_data( $data ) { $context = []; global $wpdb; $forum_id = $data['filter']['forum_id']['value']; if ( -1 == $forum_id ) { $results = $wpdb->get_results( 'SELECT * from ' . $wpdb->prefix . 'wpforo_topics WHERE closed = 0 ORDER BY topicid DESC LIMIT 1', ARRAY_A ); } else { $forum = $forum_id; $sql = 'SELECT * FROM ' . $wpdb->prefix . 'wpforo_topics WHERE forumid = %d AND closed = 0 ORDER BY topicid DESC LIMIT 1'; $results = $wpdb->get_results( $wpdb->prepare( $sql, $forum ), ARRAY_A );// @phpcs:ignore } if ( ! empty( $results ) ) { $context['pluggable_data']['forum_id'] = $results[0]['forumid']; $context['pluggable_data']['topic_id'] = $results[0]['topicid']; if ( function_exists( 'WPF' ) ) { $context['pluggable_data']['forum'] = WPF()->forum->get_forum( $results[0]['forumid'] ); $context['pluggable_data']['topic'] = WPF()->topic->get_topic( $results[0]['topicid'] ); } $context['pluggable_data']['user'] = WordPress::get_user_context( $results[0]['userid'] ); $context['response_type'] = 'live'; } else { $context = json_decode( '{"response_type":"sample","pluggable_data":{"forum_id": "2","topic_id": "1","forum": {"forumid": "2","title": "Main Forum","slug": "main-forum","description": "This is a simple parent forum","parentid": "1","icon": "fas fa-comments","cover": 0,"cover_height": "150","last_topicid": "1","last_postid": "2","last_userid": "4","last_post_date": "2023-09-19 11:40:19","topics": "1","posts": "2","permissions": "a:5:{i:1;s:4:\"full\";i:2;s:9:\"moderator\";i:3;s:8:\"standard\";i:4;s:9:\"read_only\";i:5;s:8:\"standard\";}","meta_key": "","meta_desc": "","status": "1","is_cat": "0","layout": "4","order": "0","color": "#888888","url": "https:\/\/example.com\/community\/main-forum\/","cover_url": ""},"topic": {"topicid": "1","forumid": "2","first_postid": "1","userid": "4","title": "New Forum topic title","slug": "new-forum-topic-title","created": "2023-09-19 11:39:01","modified": "2023-09-19 11:40:19","last_post": "2","posts": "2","votes": "0","answers": "0","views": "1","meta_key": "","meta_desc": "","type": "0","solved": "0","closed": "0","has_attach": "0","private": "0","status": "0","name": "","email": "","prefix": "","tags": "","url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/","full_url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/","short_url": "https:\/\/example.com\/community\/topicid\/1\/"},"user": {"wp_user_id": 4,"user_login": "john@d.com","display_name": "john@d.com","user_firstname": "john","user_lastname": "d","user_email": "john@d.com","user_role": ["customer"]}}}', true );// @phpcs:ignore } return $context; } /** * WpForo Topic Reply pluggable data. * * @param array $data data. * @return array */ public function search_pluggables_wpforo_topic_reply_last_data( $data ) { $context = []; global $wpdb; $forum_id = $data['filter']['forum_id']['value']; $topic_id = $data['filter']['topic_id']['value']; if ( -1 == $forum_id && -1 != $topic_id ) { $sql = 'SELECT * from ' . $wpdb->prefix . 'wpforo_posts WHERE topicid = %d ORDER BY postid DESC LIMIT 1'; $results = $wpdb->get_results( $wpdb->prepare( $sql, $topic_id ), ARRAY_A );// @phpcs:ignore } elseif ( -1 != $forum_id && -1 == $topic_id ) { $sql = 'SELECT * from ' . $wpdb->prefix . 'wpforo_posts WHERE forumid = %d ORDER BY postid DESC LIMIT 1'; $results = $wpdb->get_results( $wpdb->prepare( $sql, $forum_id ), ARRAY_A );// @phpcs:ignore } elseif ( -1 == $forum_id && -1 == $topic_id ) { $sql = 'SELECT * from ' . $wpdb->prefix . 'wpforo_posts ORDER BY postid DESC LIMIT 1'; $results = $wpdb->get_results( $wpdb->prepare( $sql ), ARRAY_A );// @phpcs:ignore } else { $sql = 'SELECT * FROM ' . $wpdb->prefix . 'wpforo_posts WHERE forumid = %d AND topicid = %d ORDER BY postid DESC LIMIT 1'; $results = $wpdb->get_results( $wpdb->prepare( $sql, $forum_id, $topic_id ), ARRAY_A );// @phpcs:ignore } if ( ! empty( $results ) ) { $context['pluggable_data']['forum_id'] = $results[0]['forumid']; $context['pluggable_data']['topic_id'] = $results[0]['topicid']; if ( function_exists( 'WPF' ) ) { $context['pluggable_data']['forum'] = WPF()->forum->get_forum( $results[0]['forumid'] ); $context['pluggable_data']['topic'] = WPF()->topic->get_topic( $results[0]['topicid'] ); $context['pluggable_data']['reply'] = WPF()->post->get_post( $results[0]['postid'] ); } $context['pluggable_data']['user'] = WordPress::get_user_context( $results[0]['userid'] ); $context['response_type'] = 'live'; } else { $context = json_decode( '{"response_type":"sample","pluggable_data":{"forum_id": "2","topic_id": "1","forum": {"forumid": "2","title": "Main Forum","slug": "main-forum","description": "This is a simple parent forum","parentid": "1","icon": "fas fa-comments","cover": 0,"cover_height": "150","last_topicid": "1","last_postid": "2","last_userid": "4","last_post_date": "2023-09-19 11:40:19","topics": "1","posts": "2","permissions": "a:5:{i:1;s:4:\"full\";i:2;s:9:\"moderator\";i:3;s:8:\"standard\";i:4;s:9:\"read_only\";i:5;s:8:\"standard\";}","meta_key": "","meta_desc": "","status": "1","is_cat": "0","layout": "4","order": "0","color": "#888888","url": "https:\/\/example.com\/community\/main-forum\/","cover_url": ""},"topic": {"topicid": "1","forumid": "2","first_postid": "1","userid": "4","title": "New Forum topic title","slug": "new-forum-topic-title","created": "2023-09-19 11:39:01","modified": "2023-09-19 11:40:19","last_post": "2","posts": "2","votes": "0","answers": "0","views": "1","meta_key": "","meta_desc": "","type": "0","solved": "0","closed": "0","has_attach": "0","private": "0","status": "0","name": "","email": "","prefix": "","tags": "","url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/","full_url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/","short_url": "https:\/\/example.com\/community\/topicid\/1\/"},"reply_url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/#post-2","reply": {"postid": "2","parentid": "0","forumid": "2","topicid": "1","userid": 4,"title": "RE: New Forum topic title","body": "

new reply<\/p>","created": "2023-09-19 11:40:19","modified": "2023-09-19 11:40:19","likes": "0","votes": "0","is_answer": "0","is_first_post": "0","status": "0","name": "","email": "","private": "0","root": "-1","url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/#post-2","full_url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/#post-2","short_url": "https:\/\/example.com\/community\/postid\/2\/"},"user": {"wp_user_id": 4,"user_login": "john@d.com","display_name": "john@d.com","user_firstname": "john","user_lastname": "d","user_email": "john@d.com","user_role": ["customer"]}}}', true );// @phpcs:ignore } return $context; } /** * Get RafflePress Giveaways list * * @param array $data data. * * @return array */ public function search_rp_giveaways_list( $data ) { global $wpdb; $options = []; $giveaways = $wpdb->get_results( "SELECT id,name FROM {$wpdb->prefix}rafflepress_giveaways WHERE deleted_at is null ORDER BY name ASC", ARRAY_A ); foreach ( $giveaways as $giveaway ) { $options[] = [ 'label' => $giveaway['name'], 'value' => $giveaway['id'], ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get RafflePress Giveaway Actions list * * @param array $data data. * * @return array */ public function search_rp_giveaway_actions_list( $data ) { global $wpdb; $options = []; $giveaway = $wpdb->get_row( $wpdb->prepare( "SELECT settings FROM {$wpdb->prefix}rafflepress_giveaways WHERE id=%d", $data['dynamic'] ), ARRAY_A ); if ( is_array( $giveaway ) && isset( $giveaway['settings'] ) ) { $settings = json_decode( $giveaway['settings'], true ); if ( is_array( $settings ) && isset( $settings['entry_options'] ) ) { foreach ( $settings['entry_options'] as $action ) { $options[] = [ 'label' => $action['name'], 'value' => $action['id'], ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get last data for trigger. * * @param array $data data. * @return array */ public function search_raffle_press_triggers_last_data( $data ) { global $wpdb; $context = []; $context['response_type'] = 'sample'; $pluggable_data = [ 'giveaway_id' => 1, 'giveaway_title' => 'Sample Giveaway (ID#1)', 'giveaway_start_date' => 'September 20, 2023', 'giveaway_end_date' => 'October 6, 2023', 'giveaway_entries' => 9, 'giveaway_user_count' => 3, 'giveaway_status' => 'Active', 'contestant_name' => 'John Doe', 'contestant_email' => 'john_doe@gmail.com', 'contestant_email_verified' => 'Yes', 'action_id' => '0jnex', 'action_name' => 'Visit us on Instagram', ]; $giveaway_id = isset( $data['filter']['giveaway_id'] ) ? absint( $data['filter']['giveaway_id']['value'] ) : 0; $action_id = isset( $data['filter']['action_id'] ) ? sanitize_text_field( (string) $data['filter']['action_id']['value'] ) : ''; $query = "SELECT contestant_id, giveaway_id, action_id, meta FROM {$wpdb->prefix}rafflepress_entries"; if ( $giveaway_id && -1 !== $giveaway_id ) { $query .= $wpdb->prepare( ' WHERE giveaway_id = %d', $giveaway_id ); if ( '' !== $action_id ) { $query .= $wpdb->prepare( ' AND action_id = %s', $action_id ); } } $query .= ' ORDER BY created_at DESC LIMIT 1'; $giveaway_data = $wpdb->get_row( $query, ARRAY_A ); // @phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared if ( ! empty( $giveaway_data ) ) { $pluggable_data = array_merge( RafflePress::get_giveaway_context( $giveaway_data['giveaway_id'] ), RafflePress::get_contestant_context( $giveaway_data['contestant_id'] ) ); $pluggable_data['performed_action_id'] = isset( $giveaway_data['action_id'] ) ? $giveaway_data['action_id'] : 0; $giveaway_meta = isset( $giveaway_data['meta'] ) ? json_decode( $giveaway_data['meta'], true ) : []; $pluggable_data['performed_action_name'] = is_array( $giveaway_meta ) && isset( $giveaway_meta['action'] ) ? $giveaway_meta['action'] : ''; $context['response_type'] = 'live'; } $context['pluggable_data'] = $pluggable_data; return $context; } /** * Get last data for trigger * * @param array $data data. * @return array */ public function search_woo_commerce_shipstation_triggers_last_data( $data ) { $context = []; $context['response_type'] = 'sample'; $context['pluggable_data'] = []; $order_sample_data = json_decode( '{"product_id": 47,"id": 49,"parent_id": 0,"status": "completed","currency": "USD","version": "8.1.1","prices_include_tax": false,"date_created": {"date": "2023-09-23 10:28:00.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-09-23 10:29:55.000000","timezone_type": 1,"timezone": "+00:00"},"discount_total": "0","discount_tax": "0", "shipping_total": "0","shipping_tax": "0","cart_tax": "0","total": "1.00","total_tax": "0","customer_id": 1,"order_key": "wc_order_64IaGkeQKRXdm","billing": {"first_name": "john","last_name": "d","company": "","address_1": "123 Main Street","address_2": "","city": "London","state": "Greater London","postcode": "SW1A 1AA","country": "GB","email": "johnd@d.com","phone": "9878988766"},"shipping": {"first_name": "","last_name": "","company": "","address_1": "","address_2": "","city": "","state": "","postcode": "","country": "","phone": ""},"payment_method": "cod","payment_method_title": "Cash on delivery","transaction_id": "","customer_ip_address": "182.184.87.226","customer_user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/116.0.0.0 Safari\/537.36","created_via": "checkout","customer_note": "", "date_completed": { "date": "2023-09-23 10:29:55.000000", "timezone_type": 1, "timezone": "+00:00" }, "date_paid": { "date": "2023-09-23 10:29:55.000000", "timezone_type": 1, "timezone": "+00:00" }, "cart_hash": "ac073abcdc9a52025211d0fad52cfa46", "order_stock_reduced": true, "download_permissions_granted": true, "new_order_email_sent": true, "recorded_sales": true, "recorded_coupon_usage_counts": true, "number": "49", "meta_data": [{ "id": 1206, "key":"is_vat_exempt", "value": "no"},{"id": 1207,"key": "weglot_language","value": "en"},{"id": 1208,"key": "_shipstation_exported","value": "yes"},{"id": 1209,"key": "_shipstation_shipped_item_count","value": "1"}],"line_items": {"id": "25","order_id": "49","name": "New Product","product_id": "47","variation_id": "0","quantity": "1","tax_class": "","subtotal": "1","subtotal_tax": "0","total": "1","total_tax": "0","taxes": "","meta_data": []},"tax_lines": [],"shipping_lines": [],"fee_lines": [],"coupon_lines": [],"coupons": [],"products": [{"id": 25,"order_id": 49,"name": "New Product","product_id": 47,"variation_id": 0,"quantity": 1,"tax_class": "","subtotal": "1","subtotal_tax": "0","total": "1","total_tax": "0","taxes": {"total": [],"subtotal": []},"meta_data": []}],"quantity": "1","wp_user_id": 1,"user_login": "johnd","display_name": "johnd","user_firstname": "john","user_lastname": "d","user_email": "johnd@d.com","user_role": ["administrator"],"shipping_tracking_number": "","shipping_carrier": "","ship_date": "",}', true ); //phpcs:ignore $product_id = (int) ( isset( $data['filter']['product_id']['value'] ) ? $data['filter']['product_id']['value'] : -1 ); $condition = $data['filter']['condition_compare']['value']; $price = $data['filter']['price']['value']; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; if ( 'order_shipped' === $term ) { $orders = wc_get_orders( [ 'numberposts' => 1, 'orderby' => 'date', 'order' => 'DESC', 'status' => 'completed', 'meta_query' => [ [ 'key' => '_shipstation_shipped_item_count', 'compare' => 'EXISTS', ], ], ] ); if ( is_array( $orders ) && count( $orders ) > 0 ) { $order_id = $orders[0]->get_id(); $order = wc_get_order( $order_id ); $product_ids = []; if ( $order && $order instanceof \WC_Order ) { $user_id = $order->get_customer_id(); $items = $order->get_items(); foreach ( $items as $item ) { if ( method_exists( $item, 'get_product_id' ) ) { $product_ids[] = $item->get_product_id(); } } foreach ( $product_ids as $product_id ) { $context['product_id'] = $product_id; } $order_context = WooCommerce::get_order_context( $order_id ); $context = array_merge( isset( $order_context ) ? $order_context : [], isset( $user_id ) ? WordPress::get_user_context( $user_id ) : [] ); $context['shipping_tracking_number'] = $order->get_meta( '_tracking_number', true ); $context['shipping_carrier'] = $order->get_meta( '_tracking_provider', true ); /** * * Ignore line * * @phpstan-ignore-next-line */ $timestamp = strtotime( $order->get_meta( '_date_shipped', true ) ); /** * * Ignore line * * @phpstan-ignore-next-line */ $date = date_i18n( get_option( 'date_format' ), $timestamp ); $context['ship_date'] = $date; $context['response_type'] = 'live'; } } $context['pluggable_data'] = $context; } elseif ( 'specific_product_order_shipped' === $term ) { if ( -1 != $product_id ) { $product_ids = [ $product_id ]; $orders = wc_get_orders( [ 'numberposts' => 1, 'orderby' => 'date', 'order' => 'DESC', 'status' => 'completed', 'meta_query' => [ [ 'key' => '_shipstation_shipped_item_count', 'compare' => 'EXISTS', ], [ 'key' => '_product_id', 'value' => $product_ids, 'compare' => 'IN', ], ], ] ); } else { $orders = wc_get_orders( [ 'numberposts' => 1, 'orderby' => 'date', 'order' => 'DESC', 'status' => 'completed', 'meta_query' => [ [ 'key' => '_shipstation_shipped_item_count', 'compare' => 'EXISTS', ], ], ] ); } if ( is_array( $orders ) && count( $orders ) > 0 ) { $order_id = $orders[0]->get_id(); $order = wc_get_order( $order_id ); $productids = []; if ( $order instanceof \WC_Order ) { $user_id = $order->get_customer_id(); $items = $order->get_items(); foreach ( $items as $item ) { if ( method_exists( $item, 'get_product_id' ) ) { $productids[] = $item->get_product_id(); } } $order_context = WooCommerce::get_order_context( $order_id ); $context = array_merge( isset( $order_context ) ? $order_context : [], WordPress::get_user_context( $user_id ) ); foreach ( $productids as $product_id ) { $context['product_id'] = $product_id; } $context['shipping_tracking_number'] = $order->get_meta( '_tracking_number', true ); $context['shipping_carrier'] = $order->get_meta( '_tracking_provider', true ); /** * * Ignore line * * @phpstan-ignore-next-line */ $timestamp = strtotime( $order->get_meta( '_date_shipped', true ) ); /** * * Ignore line * * @phpstan-ignore-next-line */ $date = date_i18n( get_option( 'date_format' ), $timestamp ); $context['ship_date'] = $date; $context['response_type'] = 'live'; } } $context['pluggable_data'] = $context; } elseif ( 'specific_amount_order_shipped' === $term ) { $orders = wc_get_orders( [ 'numberposts' => 1, 'orderby' => 'date', 'order' => 'DESC', 'status' => 'completed', 'meta_query' => [ [ 'key' => '_shipstation_shipped_item_count', 'compare' => 'EXISTS', ], [ 'key' => '_order_total', 'value' => $price, 'compare' => $condition, ], ], ] ); if ( is_array( $orders ) && count( $orders ) > 0 ) { $order_id = $orders[0]->get_id(); $order = wc_get_order( $order_id ); $product_ids = []; if ( $order instanceof \WC_Order ) { $user_id = $order->get_customer_id(); $items = $order->get_items(); foreach ( $items as $item ) { if ( method_exists( $item, 'get_product_id' ) ) { $product_ids[] = $item->get_product_id(); } } $order_context = WooCommerce::get_order_context( $order_id ); $context = array_merge( isset( $order_context ) ? $order_context : [], isset( $user_id ) ? WordPress::get_user_context( $user_id ) : [] ); foreach ( $product_ids as $product_id ) { $context['product_id'] = $product_id; } $context['shipping_tracking_number'] = $order->get_meta( '_tracking_number', true ); $context['shipping_carrier'] = $order->get_meta( '_tracking_provider', true ); /** * * Ignore line * * @phpstan-ignore-next-line */ $timestamp = strtotime( $order->get_meta( '_date_shipped', true ) ); /** * * Ignore line * * @phpstan-ignore-next-line */ $date = date_i18n( get_option( 'date_format' ), $timestamp ); $context['ship_date'] = $date; $context['response_type'] = 'live'; } } $context['pluggable_data'] = $context; } return $context; } /** * Get GroundHogg Tag list * * @param array $data data. * * @return array */ public function search_groundhogg_tag_list( $data ) { if ( ! function_exists( 'Groundhogg\get_db' ) ) { return []; } $tags = \Groundhogg\get_db( 'tags' )->query( [] ); $options = []; if ( ! empty( $tags ) ) { foreach ( $tags as $tag ) { $options[] = [ 'label' => $tag->tag_name, 'value' => $tag->tag_id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get WP courseware courses list * * @param array $data data. * * @return array */ public function search_wpcw_courses( $data ) { $options = []; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $args = [ 'post_type' => 'wpcw_course', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', ]; $courses = get_posts( $args ); $course_count = wp_count_posts( 'wpcw_course' )->publish; if ( ! empty( $courses ) ) { if ( is_array( $courses ) ) { foreach ( $courses as $course ) { $options[] = [ 'label' => $course->post_title, 'value' => $course->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $course_count > $limit && $course_count > $offset, ]; } /** * Get WP courseware courses list * * @param array $data data. * * @return array */ public function search_wpcw_modules( $data ) { $options = []; if ( function_exists( 'wpcw_get_modules' ) ) { $modules = wpcw_get_modules(); } if ( ! empty( $modules ) ) { if ( is_array( $modules ) ) { foreach ( $modules as $module ) { $options[] = [ 'label' => $module->module_title, 'value' => $module->module_id, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get WP courseware unit list * * @param array $data data. * * @return array */ public function search_wpcw_units( $data ) { $options = []; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $args = [ 'post_type' => 'course_unit', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', ]; $units = get_posts( $args ); $unit_count = wp_count_posts( 'course_unit' )->publish; if ( ! empty( $units ) ) { if ( is_array( $units ) ) { foreach ( $units as $unit ) { $options[] = [ 'label' => $unit->post_title, 'value' => $unit->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $unit_count > $limit && $unit_count > $offset, ]; } /** * Search WP Courseware data. * * @param array $data data. * @return array|void */ public function search_wpcw_last_data( $data ) { global $wpdb; $post_type = $data['post_type']; $trigger = $data['search_term']; $context = []; if ( 'wpcw_course_completed' === $trigger ) { $post_id = $data['filter']['course_post_id']['value']; if ( -1 === $post_id ) { $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wpcw_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.course_progress=100 order by postmeta.user_id DESC LIMIT 1" ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpcw_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.course_id = %s AND postmeta.course_progress=100 order by postmeta.user_id DESC LIMIT 1", $post_id ) ); } } elseif ( 'wpcw_module_completed' === $trigger ) { $post_id = $data['filter']['module_id']['value']; if ( -1 === $post_id ) { $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wpcw_user_courses as postmeta JOIN {$wpdb->prefix}wpcw_modules as posts ON posts.parent_course_id=postmeta.course_id WHERE postmeta.course_progress>=0 order by postmeta.course_enrolment_date DESC LIMIT 1" ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpcw_user_courses as postmeta JOIN {$wpdb->prefix}wpcw_modules as posts ON posts.parent_course_id=postmeta.course_id WHERE postmeta.course_progress>=0 AND posts.module_id=%s order by postmeta.course_enrolment_date DESC LIMIT 1", $post_id ) ); } } elseif ( 'wpcw_unit_completed' === $trigger ) { $post_id = $data['filter']['unit_id']['value']; if ( -1 === $post_id ) { $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wpcw_user_progress WHERE unit_completed_status='complete' order by unit_id DESC LIMIT 1" ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpcw_user_progress WHERE unit_id=%d AND unit_completed_status='complete' order by unit_id DESC LIMIT 1", $post_id ) ); } } elseif ( 'wpcw_enroll_course' === $trigger ) { $post_id = $data['filter']['course_post_id']['value']; if ( -1 === $post_id ) { $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wpcw_user_courses as postmeta JOIN {$wpdb->prefix}wpcw_courses as posts ON posts.course_id=postmeta.course_id order by course_enrolment_date DESC LIMIT 1" ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpcw_user_courses as postmeta JOIN {$wpdb->prefix}wpcw_courses as posts ON posts.course_id=postmeta.course_id WHERE posts.course_post_id=%d order by course_enrolment_date DESC LIMIT 1", $post_id ) ); } } if ( ! empty( $result ) ) { switch ( $trigger ) { case 'wpcw_course_completed': $result_course_id = $result[0]->course_id; $result_user_id = $result[0]->user_id; if ( function_exists( 'wpcw_get_course' ) ) { $course = wpcw_get_course( $result_course_id ); if ( is_object( $course ) ) { $course = get_object_vars( $course ); } $context = array_merge( WordPress::get_user_context( $result_user_id ), $course ); } break; case 'wpcw_module_completed': $result_module_id = $result[0]->module_id; $result_user_id = $result[0]->user_id; if ( function_exists( 'wpcw_get_module' ) ) { $module = wpcw_get_module( $result_module_id ); if ( is_object( $module ) ) { $module = get_object_vars( $module ); } $context = array_merge( WordPress::get_user_context( $result_user_id ), $module ); } break; case 'wpcw_unit_completed': $result_unit_id = $result[0]->unit_id; $result_user_id = $result[0]->user_id; if ( function_exists( 'wpcw_get_unit' ) ) { $unit = wpcw_get_unit( $result_unit_id ); if ( is_object( $unit ) ) { $unit = get_object_vars( $unit ); $unit['name'] = get_the_title( $result_unit_id ); } $context = array_merge( WordPress::get_user_context( $result_user_id ), $unit ); } break; case 'wpcw_enroll_course': $result_course_id = $result[0]->course_id; $result_user_id = $result[0]->user_id; if ( function_exists( 'WPCW_courses_getCourseDetails' ) ) { $course_detail = WPCW_courses_getCourseDetails( $result_course_id ); if ( is_object( $course_detail ) ) { $course_detail = get_object_vars( $course_detail ); } $context = array_merge( WordPress::get_user_context( $result_user_id ), $course_detail ); } break; default: return; } $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } return $context; } /** * Get WooCommerce Order Note list. * * @param array $data data. * * @return array */ public function search_note_type_list( $data ) { $options = []; $options[] = [ 'label' => 'Customer', 'value' => 'customer', ]; $options[] = [ 'label' => 'Private', 'value' => 'internal', ]; return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get last data for trigger * * @param array $data data. * @return array */ public function search_woo_commerce_customers_triggers_last_data( $data ) { $context = []; $context['response_type'] = 'sample'; $context['pluggable_data'] = []; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; global $wpdb; if ( 'customer_created' === $term ) { $customer_query = get_users( [ 'fields' => 'ID', 'role' => 'customer', 'orderby' => 'ID', 'order' => 'DESC', 'number' => 1, ] ); $results = $customer_query; if ( ! empty( $results ) ) { $customer = new WC_Customer( $results[0] ); $last_order = $customer->get_last_order(); $customer_data = [ 'id' => $customer->get_id(), 'email' => $customer->get_email(), 'first_name' => $customer->get_first_name(), 'last_name' => $customer->get_last_name(), 'username' => $customer->get_username(), 'last_order_id' => is_object( $last_order ) ? $last_order->get_id() : null, 'orders_count' => $customer->get_order_count(), 'total_spent' => wc_format_decimal( $customer->get_total_spent(), 2 ), 'avatar_url' => $customer->get_avatar_url(), 'billing_address' => [ 'first_name' => $customer->get_billing_first_name(), 'last_name' => $customer->get_billing_last_name(), 'company' => $customer->get_billing_company(), 'address_1' => $customer->get_billing_address_1(), 'address_2' => $customer->get_billing_address_2(), 'city' => $customer->get_billing_city(), 'state' => $customer->get_billing_state(), 'postcode' => $customer->get_billing_postcode(), 'country' => $customer->get_billing_country(), 'email' => $customer->get_billing_email(), 'phone' => $customer->get_billing_phone(), ], 'shipping_address' => [ 'first_name' => $customer->get_shipping_first_name(), 'last_name' => $customer->get_shipping_last_name(), 'company' => $customer->get_shipping_company(), 'address_1' => $customer->get_shipping_address_1(), 'address_2' => $customer->get_shipping_address_2(), 'city' => $customer->get_shipping_city(), 'state' => $customer->get_shipping_state(), 'postcode' => $customer->get_shipping_postcode(), 'country' => $customer->get_shipping_country(), ], ]; if ( is_object( $last_order ) && method_exists( $last_order, 'get_date_created' ) ) { $created_date = $last_order->get_date_created(); if ( is_object( $created_date ) && method_exists( $created_date, 'getTimestamp' ) ) { $last_order_date = $created_date->getTimestamp(); $customer_data['created_at'] = $last_order_date; $customer_data['last_order_date'] = $last_order_date; } } $order_sample_data = $customer_data; $context['response_type'] = 'live'; $context['pluggable_data'] = $order_sample_data; } else { $order_sample_data = json_decode( '{"id": 158,"email": "johnd@d.com","first_name": "john","last_name": "d","username": "johnd","last_order_id": 6604,"orders_count": 3,"total_spent": "45.00","avatar_url": "https:\/\/secure.gravatar.com\/avatar\/0f9c8dc78cff3ea4d447b2297c8f6803?s=96&d=mm&r=g","billing_address": {"first_name": "john","last_name": "d","company": "","address_1": "","address_2": "","city": "London","state": "TN","postcode": "PV1 QW2","country": "UK","email": "johnd@d.com","phone": "9878988766"},"shipping_address": {"first_name": "","last_name": "","company": "","address_1": "","address_2": "","city": "","state": "","postcode": "","country": ""},"created_at": 1697631243,"last_order_date": 1697631243}', true ); $context['pluggable_data'] = $order_sample_data; } } elseif ( 'total_spend_reach' === $term ) { $total_spend_selected = isset( $data['filter']['total_spend']['value'] ) ? $data['filter']['total_spend']['value'] : ''; $customers = $wpdb->get_col( "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = '_customer_user' AND meta_value > 0" ); $target_customer = null; foreach ( $customers as $customer ) { $total_spend = (int) wc_get_customer_total_spent( $customer ); if ( $total_spend == $total_spend_selected ) { $target_customer = $customer; break; // Exit the loop once a matching customer is found. } } if ( $target_customer ) { $new_customer = new WC_Customer( $target_customer ); $new_customer_data = [ 'id' => $new_customer->get_id(), 'email' => $new_customer->get_email(), 'first_name' => $new_customer->get_first_name(), 'last_name' => $new_customer->get_last_name(), 'username' => $new_customer->get_username(), 'order_count' => $new_customer->get_order_count(), 'total_spend' => wc_format_decimal( $new_customer->get_total_spent(), 2 ), ]; $context['response_type'] = 'live'; $context['pluggable_data'] = $new_customer_data; } else { $sample_customer_data = [ 'id' => '101', 'created_at' => '1680675247', 'email' => 'john@d.com', 'first_name' => 'John', 'last_name' => 'D', 'username' => 'johnd', 'order_count' => '3', 'total_spend' => '22.00', ]; $context['pluggable_data'] = $sample_customer_data; } } elseif ( 'order_count_reach' === $term ) { $total_order_selected = isset( $data['filter']['order_count']['value'] ) ? $data['filter']['order_count']['value'] : ''; $customers = $wpdb->get_col( "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = '_customer_user' AND meta_value > 0" ); $target_customer = null; foreach ( $customers as $customer ) { $args = [ 'customer_id' => $customer, 'limit' => -1, 'status' => [ 'wc-completed' ], ]; $orders = wc_get_orders( $args ); if ( ! empty( $orders ) ) { $total_order = (int) wc_get_customer_order_count( $customer ); if ( $total_order == $total_order_selected ) { $target_customer = $customer; break; // Exit the loop once a matching customer is found. } } } if ( $target_customer ) { $new_customer = new WC_Customer( $target_customer ); $new_customer_data = [ 'id' => $new_customer->get_id(), 'email' => $new_customer->get_email(), 'first_name' => $new_customer->get_first_name(), 'last_name' => $new_customer->get_last_name(), 'username' => $new_customer->get_username(), 'order_count' => $new_customer->get_order_count(), ]; $context['response_type'] = 'live'; $context['pluggable_data'] = $new_customer_data; } else { $sample_customer_data = [ 'id' => '101', 'created_at' => '1680675247', 'email' => 'john@d.com', 'first_name' => 'John', 'last_name' => 'D', 'username' => 'johnd', 'orders_count' => '3', ]; $context['pluggable_data'] = $sample_customer_data; } } return $context; } /** * Get Affiliate list * * @param array $data data. * * @return array */ public function search_affiliate_list( $data ) { $options = []; $args = [ 'meta_query' => [ [ 'key' => 'wafp_is_affiliate', 'value' => '1', 'compare' => '=', ], ], ]; $affiliates = get_users( $args ); foreach ( $affiliates as $user ) { $options[] = [ 'label' => $user->display_name, 'value' => $user->ID, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Affiliate Source list * * @param array $data data. * * @return array */ public function search_affiliate_transaction_source_list( $data ) { $options = []; $sources = [ 'General', 'MemberPress', 'WooCommerce', 'Easy Digital Downloads', 'WPForms', 'Formidable', 'PayPal', ]; foreach ( $sources as $source ) { $options[] = [ 'label' => $source, 'value' => str_replace( ' ', '_', strtolower( $source ) ), ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Easy Affiliate data. * * @param array $data data. * @return array|void */ public function search_easy_affiliate_last_data( $data ) { global $wpdb; $trigger = $data['search_term']; $context = []; if ( 'sale_recorded' === $trigger ) { $affiliate_id = $data['filter']['affiliate_id']['value']; if ( -1 === $affiliate_id ) { $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wafp_transactions as postmeta JOIN {$wpdb->prefix}wafp_events as posts ON posts.evt_id=postmeta.id WHERE postmeta.status='complete' order by postmeta.id DESC LIMIT 1" ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wafp_transactions as postmeta JOIN {$wpdb->prefix}wafp_events as posts ON posts.evt_id=postmeta.id WHERE postmeta.status='complete' AND affiliate_id=%d order by postmeta.id DESC LIMIT 1", $affiliate_id ) ); } } elseif ( 'sale_added' === $trigger ) { $orderby = 'signup_date'; $order = 'DESC'; $paged = 1; $search = ''; $perpage = 1; /** * * Ignore line * * @phpstan-ignore-next-line */ $result = \EasyAffiliate\Models\User::affiliate_list_table( $orderby, $order, $paged, $search, $perpage ); if ( empty( $result['results'] ) ) { $result = []; } } elseif ( 'payout_made' === $trigger ) { $affiliate_id = $data['filter']['affiliate_id']['value']; if ( -1 === $affiliate_id ) { $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wafp_payments as postmeta JOIN {$wpdb->prefix}wafp_events as posts ON posts.evt_id=postmeta.id WHERE postmeta.amount>0 order by postmeta.id DESC LIMIT 1" ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wafp_payments as postmeta JOIN {$wpdb->prefix}wafp_events as posts ON posts.evt_id=postmeta.id WHERE postmeta.amount>0 AND affiliate_id=%d order by postmeta.id DESC LIMIT 1", $affiliate_id ) ); } } if ( ! empty( $result ) ) { switch ( $trigger ) { case 'sale_recorded': $result_affiliate_id = $result[0]->affiliate_id; /** * * Ignore line * * @phpstan-ignore-next-line */ $affiliate = \EasyAffiliate\Lib\ModelFactory::fetch( $result[0]->evt_id_type, $result[0]->evt_id ); $affiliate = get_object_vars( $affiliate->rec ); $context = array_merge( WordPress::get_user_context( $result_affiliate_id ), $affiliate ); break; case 'sale_added': /** * * Ignore line * * @phpstan-ignore-next-line */ $data = new \EasyAffiliate\Models\User( $result['results'][0]->ID ); /** * * Ignore line * * @phpstan-ignore-next-line */ $context = get_object_vars( $data->rec ); break; case 'payout_made': $result_affiliate_id = $result[0]->affiliate_id; /** * * Ignore line * * @phpstan-ignore-next-line */ $affiliate = \EasyAffiliate\Lib\ModelFactory::fetch( $result[0]->evt_id_type, $result[0]->evt_id ); $affiliate = get_object_vars( $affiliate->rec ); $context = array_merge( WordPress::get_user_context( $result_affiliate_id ), $affiliate ); break; default: return; } $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } elseif ( empty( $result ) ) { switch ( $trigger ) { case 'sale_added': $context = json_decode( '{"ID": 1,"first_name": "John","last_name": "D","user_login": "johnd","user_nicename": "johnd","user_email": "johnd@d.com","user_url": "","user_registered": "2023-10-13 13:39:16","user_activation_key": "","user_status": "0","display_name": "johnd","paypal_email": "johnd@d.com","address_one": "1street","address_two": "", "city": "london","state": "","zip": "","country": "UK","tax_id_us": "","tax_id_int": "","is_affiliate": "1","is_blocked": "","blocked_message": "","referrer": "0","notes": "","unsubscribed": ""}', true ); break; case 'sale_recorded': $context = json_decode( '{"wp_user_id": 73,"user_login": "johnd@yopmail.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["subscriber"],"id": "5","affiliate_id": "73","click_id": "0","item_id": "","item_name": "test","coupon": "","sale_amount": "10.00","refund_amount": "20.00","subscr_id": "","subscr_paynum": "0","ip_addr": "","cust_email": "","cust_name": "","trans_num": "test5","type": "commission","source": "general","order_id": "0","status": "complete","rebill": "0","created_at": "2023-10-11 09:18:41"}', true ); break; case 'payout_made': $context = json_decode( '{"wp_user_id": 73,"user_login": "johnd@yopmail.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["subscriber"],"id": "5","affiliate_id": "73","click_id": "0","item_id": "","item_name": "test","coupon": "","sale_amount": "10.00","refund_amount": "20.00","subscr_id": "","subscr_paynum": "0","ip_addr": "","cust_email": "","cust_name": "","trans_num": "test5","type": "commission","source": "general","order_id": "0","status": "complete","rebill": "0","created_at": "2023-10-11 09:18:41"}', true ); break; default: return; } $context['pluggable_data'] = $context; $context['response_type'] = 'sample'; } return $context; } /** * Get WooCommerce Subscriptions Coupon list * * @param array $data data. * * @return array */ public function search_woo_subscription_coupon_list( $data ) { $options = []; $coupon_codes = []; $query = new \WP_Query( [ 'post_type' => 'shop_coupon', 'posts_per_page' => -1, 'no_found_rows' => true, 'meta_query' => [ [ 'key' => '_is_aw_coupon', 'compare' => 'NOT EXISTS', ], ], ] ); foreach ( $query->posts as $coupon ) { /** * * Ignore line * * @phpstan-ignore-next-line */ $code = wc_format_coupon_code( $coupon->post_title ); $coupon_codes[ $code ] = $code; } foreach ( $coupon_codes as $code ) { $coupon = new \WC_Coupon( $code ); if ( ! in_array( $coupon->get_discount_type(), [ 'recurring_fee', 'recurring_percent' ], true ) ) { unset( $coupon_codes[ $code ] ); } } if ( ! empty( $coupon_codes ) ) { if ( is_array( $coupon_codes ) ) { foreach ( $coupon_codes as $coupon_code ) { $options[] = [ 'label' => $coupon_code, 'value' => $coupon_code, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get BuddyBoss field. * * @param array $data data. * * @return array|void */ public function search_bb_field_list( $data ) { global $wpdb; $options = []; $xprofile_fields = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_xprofile_fields WHERE parent_id = 0 ORDER BY field_order ASC" ); if ( ! empty( $xprofile_fields ) ) { foreach ( $xprofile_fields as $xprofile_field ) { $options[] = [ 'label' => $xprofile_field->name, 'value' => $xprofile_field->id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Woocommerce Bookings Product List. * * @param array $data data. * * @return array|void */ public function search_wb_bookable_product_list( $data ) { $options = []; if ( ! class_exists( 'WC_Bookings_Admin' ) ) { return; } $products = WC_Bookings_Admin::get_booking_products(); if ( ! empty( $products ) ) { if ( is_array( $products ) ) { foreach ( $products as $product ) { $options[] = [ 'label' => $product->get_name(), 'value' => $product->get_id(), ]; $resources = $product->get_resources(); if ( ! empty( $resources ) ) { foreach ( $resources as $resource ) { $options[] = [ 'label' => $resource->get_name(), 'value' => $resource->get_id(), ]; } } } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get last data for WooCommerce Booking trigger * * @param array $data data. * @return array */ public function search_woo_commerce_booking_last_data( $data ) { $context = []; $context['response_type'] = 'sample'; $context['pluggable_data'] = []; $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; global $wpdb; if ( 'booking_created' === $term ) { $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type='wc_booking' AND post_status='confirmed' order by ID DESC LIMIT 1" ); if ( ! empty( $results ) ) { if ( class_exists( 'WC_Booking' ) ) { $booking = new WC_Booking( $results[0]->ID ); $person_counts = $booking->get_person_counts(); $bookable_product_id = $booking->get_product_id(); if ( method_exists( $booking, 'get_data' ) ) { $booking = $booking->get_data(); $booking['start'] = gmdate( 'Y-m-d H:i:s', $booking['start'] ); $booking['end'] = gmdate( 'Y-m-d H:i:s', $booking['end'] ); if ( ! empty( $person_counts ) ) { $total_count = 0; foreach ( $person_counts as $key => $value ) { $total_count += $value; } $booking['total_person_counts'] = $total_count; } $booking['bookable_product'] = $bookable_product_id; $context['response_type'] = 'live'; $context['pluggable_data'] = array_merge( $booking, WordPress::get_user_context( $booking['customer_id'] ) ); } } } else { $booking_sample_data = json_decode( '{"id": 6546,"all_day": false,"cost": "45.02","customer_id": 1,"date_created": 1696915500,"date_modified": 1696915863,"end": "2023-10-14 12:00:00","google_calendar_event_id": "0","order_id": 0,"order_item_id": 0,"parent_id": 0,"person_counts": {"6525": 1,"6526": 1},"product_id": 6527,"resource_id": 0,"start": "2023-10-14 10:00:00","status": "confirmed","local_timezone": "","meta_data": [{"id": 12163,"key": "_booking_all_day","value": "0"},{"id": 12164,"key": "_booking_cost","value": "45.02"},{"id": 12165,"key": "_booking_customer_id","value": "1"},{"id": 12166,"key": "_booking_order_item_id","value": "0"},{"id": 12167,"key": "_booking_parent_id","value": "0"},{"id": 12168,"key": "_booking_persons","value": {"6525": 1,"6526": 1}},{"id": 12169,"key": "_booking_product_id","value": "6527"},{"id": 12170,"key": "_booking_resource_id","value": "0"},{"id": 12171,"key": "_booking_start","value": "20231014100000"},{"id": 12172,"key": "_booking_end","value": "20231014120000"},{"id": 12173,"key": "_wc_bookings_gcalendar_event_id","value": "0"},{"id": 12175,"key": "_edit_lock","value": "1696915725:1"},{"id": 12176,"key": "_edit_last","value": "1"}],"total_person_counts": 2,"bookable_product": 6527,"wp_user_id": 1,"user_login": "johnd@yopmail.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["customer"]}', true ); $context['pluggable_data'] = $booking_sample_data; } } elseif ( 'booking_status_changed' === $term ) { $to_status = isset( $data['filter']['to_status']['value'] ) ? $data['filter']['to_status']['value'] : -1; if ( -1 == $to_status ) { $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type='wc_booking' order by ID DESC LIMIT 1" ); } else { $results = $wpdb->get_results( $wpdb->prepare( " SELECT * FROM {$wpdb->prefix}posts WHERE `post_status` = %s AND `post_type` LIKE %s ", $to_status, 'wc_booking' ) ); } if ( ! empty( $results ) ) { if ( class_exists( 'WC_Booking' ) ) { $booking = new WC_Booking( $results[0]->ID ); $person_counts = $booking->get_person_counts(); $bookable_product_id = $booking->get_product_id(); if ( method_exists( $booking, 'get_data' ) ) { $booking = $booking->get_data(); $booking['start'] = gmdate( 'Y-m-d H:i:s', $booking['start'] ); $booking['end'] = gmdate( 'Y-m-d H:i:s', $booking['end'] ); if ( ! empty( $person_counts ) ) { $total_count = 0; foreach ( $person_counts as $key => $value ) { $total_count += $value; } $booking['total_person_counts'] = $total_count; } $booking['bookable_product'] = $bookable_product_id; $booking['from_status'] = $data['filter']['from_status']['value']; $booking['to_status'] = $booking['status']; $context['response_type'] = 'live'; $context['pluggable_data'] = array_merge( $booking, WordPress::get_user_context( $booking['customer_id'] ) ); } } } else { $booking_sample_data = json_decode( '{"id": 6546,"all_day": false,"cost": "45.02","customer_id": 1,"date_created": 1696915500,"date_modified": 1696915863,"end": "2023-10-14 12:00:00","google_calendar_event_id": "0","order_id": 0,"order_item_id": 0,"parent_id": 0,"person_counts": {"6525": 1,"6526": 1},"product_id": 6527,"resource_id": 0,"start": "2023-10-14 10:00:00","status": "confirmed","to_status": "confirmed","from_status": "cancelled","local_timezone": "","meta_data": [{"id": 12163,"key": "_booking_all_day","value": "0"},{"id": 12164,"key": "_booking_cost","value": "45.02"},{"id": 12165,"key": "_booking_customer_id","value": "1"},{"id": 12166,"key": "_booking_order_item_id","value": "0"},{"id": 12167,"key": "_booking_parent_id","value": "0"},{"id": 12168,"key": "_booking_persons","value": {"6525": 1,"6526": 1}},{"id": 12169,"key": "_booking_product_id","value": "6527"},{"id": 12170,"key": "_booking_resource_id","value": "0"},{"id": 12171,"key": "_booking_start","value": "20231014100000"},{"id": 12172,"key": "_booking_end","value": "20231014120000"},{"id": 12173,"key": "_wc_bookings_gcalendar_event_id","value": "0"},{"id": 12175,"key": "_edit_lock","value": "1696915725:1"},{"id": 12176,"key": "_edit_last","value": "1"}],"total_person_counts": 2,"bookable_product": 6527,"wp_user_id": 1,"user_login": "johnd@yopmail.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["customer"]}', true ); $context['pluggable_data'] = $booking_sample_data; } } return $context; } /** * Get WooCommerce Booking status list. * * @param array $data data. * * @return array */ public function search_woo_booking_status_list( $data ) { $options = [ [ 'label' => 'Pending Confirmation', 'value' => 'pending-confirmation', ], [ 'label' => 'Unpaid', 'value' => 'unpaid', ], [ 'label' => 'Confirmed', 'value' => 'confirmed', ], [ 'label' => 'Paid', 'value' => 'paid', ], [ 'label' => 'Complete', 'value' => 'complete', ], [ 'label' => 'In Cart', 'value' => 'in-cart', ], [ 'label' => 'Cancelled', 'value' => 'cancelled', ], ]; return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Woocommerce Memberships Status List. * * @param array $data data. * * @return array|void */ public function search_wc_membership_status_list( $data ) { $options = []; if ( ! function_exists( 'wc_memberships_get_user_membership_statuses' ) ) { return; } $statuses = wc_memberships_get_user_membership_statuses(); if ( ! empty( $statuses ) ) { if ( is_array( $statuses ) ) { foreach ( $statuses as $status => $value ) { $status = 0 === strpos( $status, 'wcm-' ) ? substr( $status, 4 ) : $status; $options[] = [ 'label' => $value['label'], 'value' => $status, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search Woocommerce Subscription data. * * @param array $data data. * @return array|void */ public function search_user_subscription_last_data( $data ) { $context = []; if ( ! class_exists( 'WC_Subscription' ) || ! function_exists( 'wcs_get_subscription' ) || ! function_exists( 'wcs_get_subscriptions_for_product' ) || ! function_exists( 'wcs_order_contains_renewal' ) || ! function_exists( 'wcs_get_subscriptions_for_order' ) ) { return; } if ( 'trial_end' == $data['search_term'] ) { $subscription_id = $data['filter']['subscription']['value']; $query_args = [ 'post_type' => 'shop_subscription', 'orderby' => 'ID', 'order' => 'DESC', 'post_status' => 'wc-active', 'posts_per_page' => 1, 'meta_query' => [ [ 'key' => '_schedule_trial_end', 'value' => gmdate( 'Y-m-d H:i:s' ), 'compare' => '<=', ], ], 'post__in' => [ $subscription_id ], ]; $query_result = new WP_Query( $query_args ); $subscription_orders = $query_result->get_posts(); if ( ! empty( $subscription_orders ) ) { /** * * Ignore line * * @phpstan-ignore-next-line */ $subscription = wcs_get_subscription( $subscription_orders[0]->ID ); $user_id = $subscription->get_user_id(); $items = $subscription->get_items(); $product_ids = []; foreach ( $items as $item ) { $product_ids[] = $item->get_product_id(); } $subscription_status = $subscription->get_status(); $subscription_start_date = $subscription->get_date_created(); $context['subscription_data'] = [ 'status' => $subscription_status, 'start_date' => $subscription_start_date, 'trial_end_date' => $subscription->get_date( 'schedule_trial_end' ), 'next_payment_date' => $subscription->get_date( 'next_payment' ), 'end_date' => $subscription->get_date( 'schedule_end' ), ]; $context['user'] = WordPress::get_user_context( $user_id ); foreach ( $product_ids as $val ) { $context['subscription'] = $val; $context['subscription_name'] = get_the_title( $val ); } $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $context = json_decode( '{"subscription_data": {"status": "active","start_date": {"date": "2023-05-18 12:36:53.000000","timezone_type": 1,"timezone": "+00:00"},"trial_end_date": "2023-10-20 03:31:04","next_payment_date": 0,"end_date": "2024-05-28 12:36:53"},"user": {"wp_user_id": 1,"user_login": "john@d.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "john@d.com","user_role": ["customer","subscriber"]},"subscription": 5861,"subscription_name": "Demo Subscription"}', true ); $context['pluggable_data'] = $context; $context['response_type'] = 'sample'; } } elseif ( 'renewal_payment_failed' == $data['search_term'] ) { $subscription_item = $data['filter']['subscription_item']['value']; $subscription_ids = wcs_get_subscriptions_for_product( $subscription_item ); $ids = []; $related = []; foreach ( $subscription_ids as $subscription ) { $ids[] = $subscription; $subscriptions = new WC_Subscription( $subscription ); $related[] = $subscriptions->get_related_orders(); } $failed_payment_orders = []; foreach ( $related as $value ) { foreach ( $value as $val ) { if ( wcs_order_contains_renewal( $val ) ) { $order = wc_get_order( $val ); if ( $order ) { /** * * Ignore line * * @phpstan-ignore-next-line */ $payment_status = $order->get_status(); if ( 'failed' === $payment_status || 'wc-on-hold' === $payment_status ) { $failed_payment_orders[] = $val; } } } } } if ( ! empty( $failed_payment_orders ) ) { $failed = array_rand( $failed_payment_orders ); $related_subscriptions = wcs_get_subscriptions_for_order( $failed_payment_orders[ $failed ] ); if ( ! empty( $related_subscriptions ) ) { $sub_id = get_post_meta( $failed_payment_orders[ $failed ], '_subscription_renewal', true ); $subscription = wcs_get_subscription( $sub_id ); $items = $subscription->get_items(); $product_ids = []; foreach ( $items as $item ) { $product_ids[] = $item->get_product_id(); } $context['user'] = WordPress::get_user_context( $subscription->get_user_id() ); foreach ( [ 'renewal' ] as $order_type ) { foreach ( $subscription->get_related_orders( 'ids', $order_type ) as $order_id ) { $context['subscription_related_order'][] = $order_id; } } foreach ( $product_ids as $val ) { $context['subscription_item'] = $val; $context['subscription_name'] = get_the_title( $val ); } $context['data'] = $subscription->get_data(); $context['pluggable_data'] = $context; $context['response_type'] = 'live'; } else { $context['pluggable_data'] = json_decode( '{"user": {"wp_user_id": 36,"user_login": "john@d.com","display_name": "test","user_firstname": "Test","user_lastname": "test","user_email": "john@d.com","user_role": ["wpamelia-customer","customer"]},"subscription_related_order": [6643],"subscription_item": 5962,"subscription_name": "Demo2 Subscription","data": {"id": 6642,"parent_id": 6641,"status": "on-hold","currency": "USD","version": "7.6.1","prices_include_tax": false,"date_created": {"date": "2023-10-20 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-20 08:45:02.000000","timezone_type": 1,"timezone": "+00:00"},"discount_total": "0","discount_tax": "0","shipping_total": "0","shipping_tax": "0","cart_tax": "0","total": "1.00","total_tax": "0","customer_id": 36,"order_key": "wc_order_6Pdirh5WDDiVA","billing": {"first_name": "bella","last_name": "test","company": "","address_1": "test","address_2": "","city": "test","state": "TN","postcode": "600144","country": "IN","email": "john@d.com","phone": "98675757"},"shipping": {"first_name": "bella","last_name": "test","company": "","address_1": "test","address_2": "","city": "Chennai","state": "TN","postcode": "600100","country": "IN","phone": ""},"payment_method": "","payment_method_title": "","transaction_id": "","customer_ip_address": "127.0.0.1","customer_user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/118.0.0.0 Safari\/537.36","created_via": "checkout","customer_note": "","date_completed": null,"date_paid": null,"cart_hash": "","order_stock_reduced": false,"download_permissions_granted": true,"new_order_email_sent": false,"recorded_sales": false,"recorded_coupon_usage_counts": false,"billing_period": "day","billing_interval": "1","suspension_count": 1,"requires_manual_renewal": true,"cancelled_email_sent": "","trial_period": "day","schedule_trial_end": {"date": "2023-10-21 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_next_payment": {"date": "2023-10-21 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_end": {"date": "2023-10-22 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_start": {"date": "2023-10-22 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"switch_data": [],"number": "6642","meta_data": [{"id": 13719,"key": "is_vat_exempt","value": "no"}],"line_items": {"142": []},"tax_lines": [],"shipping_lines": [],"fee_lines": [],"coupon_lines": []}}', true ); $context['response_type'] = 'sample'; } } else { $context['pluggable_data'] = json_decode( '{"user": {"wp_user_id": 36,"user_login": "john@d.com","display_name": "test","user_firstname": "Test","user_lastname": "test","user_email": "john@d.com","user_role": ["wpamelia-customer","customer"]},"subscription_related_order": [6643],"subscription_item": 5962,"subscription_name": "Demo2 Subscription","data": {"id": 6642,"parent_id": 6641,"status": "on-hold","currency": "USD","version": "7.6.1","prices_include_tax": false,"date_created": {"date": "2023-10-20 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-20 08:45:02.000000","timezone_type": 1,"timezone": "+00:00"},"discount_total": "0","discount_tax": "0","shipping_total": "0","shipping_tax": "0","cart_tax": "0","total": "1.00","total_tax": "0","customer_id": 36,"order_key": "wc_order_6Pdirh5WDDiVA","billing": {"first_name": "bella","last_name": "test","company": "","address_1": "test","address_2": "","city": "test","state": "TN","postcode": "600144","country": "IN","email": "john@d.com","phone": "98675757"},"shipping": {"first_name": "bella","last_name": "test","company": "","address_1": "test","address_2": "","city": "Chennai","state": "TN","postcode": "600100","country": "IN","phone": ""},"payment_method": "","payment_method_title": "","transaction_id": "","customer_ip_address": "127.0.0.1","customer_user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/118.0.0.0 Safari\/537.36","created_via": "checkout","customer_note": "","date_completed": null,"date_paid": null,"cart_hash": "","order_stock_reduced": false,"download_permissions_granted": true,"new_order_email_sent": false,"recorded_sales": false,"recorded_coupon_usage_counts": false,"billing_period": "day","billing_interval": "1","suspension_count": 1,"requires_manual_renewal": true,"cancelled_email_sent": "","trial_period": "day","schedule_trial_end": {"date": "2023-10-21 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_next_payment": {"date": "2023-10-21 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_end": {"date": "2023-10-22 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_start": {"date": "2023-10-22 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"switch_data": [],"number": "6642","meta_data": [{"id": 13719,"key": "is_vat_exempt","value": "no"}],"line_items": {"142": []},"tax_lines": [],"shipping_lines": [],"fee_lines": [],"coupon_lines": []}}', true ); $context['response_type'] = 'sample'; } } return $context; } /** * Get Masteriyo LMS Courses. * * @param array $data data. * * @return array */ public function search_masteriyo_lms_courses( $data ) { $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $args = [ 'post_type' => 'mto-course', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', ]; $courses = get_posts( $args ); $course_count = wp_count_posts( 'mto-course' )->publish; $options = []; if ( ! empty( $courses ) ) { if ( is_array( $courses ) ) { foreach ( $courses as $course ) { $options[] = [ 'label' => $course->post_title, 'value' => $course->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $course_count > $limit && $course_count > $offset, ]; } /** * Get Masteriyo LMS Lessons. * * @param array $data data. * * @return array */ public function search_masteriyo_lms_lessons( $data ) { $course_id = $data['dynamic']; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $options = []; $args = [ 'post_type' => 'mto-lesson', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', 'meta_query' => [ [ 'key' => '_course_id', 'value' => $course_id, 'compare' => '=', ], ], ]; $lessons = get_posts( $args ); $lesson_count = wp_count_posts( 'mto-lesson' )->publish; if ( ! empty( $lessons ) ) { if ( is_array( $lessons ) ) { foreach ( $lessons as $lesson ) { $options[] = [ 'label' => $lesson->post_title, 'value' => $lesson->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $lesson_count > $limit && $lesson_count > $offset, ]; } /** * Get Masteriyo LMS Quiz. * * @param array $data data. * * @return array */ public function search_masteriyo_lms_quizs( $data ) { $course_id = $data['dynamic']; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $options = []; $args = [ 'post_type' => 'mto-quiz', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', 'meta_query' => [ [ 'key' => '_course_id', 'value' => $course_id, 'compare' => '=', ], ], ]; $quizs = get_posts( $args ); $quiz_count = wp_count_posts( 'mto-quiz' )->publish; if ( ! empty( $quizs ) ) { if ( is_array( $quizs ) ) { foreach ( $quizs as $quiz ) { $options[] = [ 'label' => $quiz->post_title, 'value' => $quiz->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $quiz_count > $limit && $quiz_count > $offset, ]; } /** * Search Masteriyo LMS data. * * @param array $data data. * @return array|void|mixed */ public function search_masteriyo_lms_last_data( $data ) { global $wpdb; $post_type = $data['post_type']; $trigger = $data['search_term']; $context = []; $post_id = -1; if ( 'course_completed' === $trigger ) { $post_id = $data['filter']['course_id']['value']; } elseif ( 'lesson_completed' === $trigger ) { $post_id = $data['filter']['lesson_id']['value']; } elseif ( 'quiz_completed' === $trigger || 'quiz_failed' === $trigger ) { $post_id = $data['filter']['quiz_id']['value']; } if ( 'course_completed' === $trigger || 'lesson_completed' === $trigger ) { if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_user_activities as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.item_id WHERE postmeta.activity_status='completed' AND posts.post_type=%s order by postmeta.id DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_user_activities as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.item_id WHERE postmeta.item_id = %s AND postmeta.activity_status='completed' AND posts.post_type=%s order by postmeta.id DESC LIMIT 1", $post_id, $post_type ) ); } } if ( 'quiz_completed' === $trigger || 'quiz_failed' === $trigger ) { if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_user_activities as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.item_id WHERE postmeta.activity_status='completed' AND postmeta.activity_type='quiz' AND posts.post_type=%s order by postmeta.user_item_id DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_user_activities as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.item_id WHERE postmeta.item_id=%s AND postmeta.activity_type='quiz' OR postmeta.activity_status='completed' AND posts.post_type=%s order by postmeta.id DESC LIMIT 1", $post_id, $post_type ) ); } if ( ! empty( $result ) ) { $resultt = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_quiz_attempts WHERE quiz_id=%d AND user_id=%d order by id DESC LIMIT 1", $result[0]->item_id, $result[0]->user_id ) ); if ( function_exists( 'masteriyo_get_quiz' ) ) { $quiz = masteriyo_get_quiz( $resultt[0]->quiz_id ); if ( is_object( $quiz ) && method_exists( $quiz, 'get_pass_mark' ) ) { if ( 'quiz_completed' === $trigger && $resultt[0]->earned_marks < $quiz->get_pass_mark() ) { $result = []; } elseif ( 'quiz_failed' === $trigger && $resultt[0]->earned_marks > $quiz->get_pass_mark() ) { $result = []; } } } } } if ( ! empty( $result ) ) { $result_item_id = $result[0]->item_id; $result_user_id = $result[0]->user_id; $quiz_attempt = ''; if ( 'quiz_completed' === $trigger || 'quiz_failed' === $trigger ) { $resultt = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_quiz_attempts WHERE quiz_id=%d AND user_id=%d order by id DESC LIMIT 1", $result[0]->item_id, $result[0]->user_id ) ); $quiz_attempt = $resultt[0]->id; } switch ( $trigger ) { case 'course_completed': if ( function_exists( 'masteriyo_get_course' ) ) { $course = masteriyo_get_course( $result_item_id ); $context_data = array_merge( WordPress::get_user_context( $result_user_id ), $course->get_data() ); $context_data['course_id'] = $result_item_id; } break; case 'lesson_completed': if ( function_exists( 'masteriyo_get_lesson' ) ) { $lesson = masteriyo_get_lesson( $result_item_id ); $context_data = array_merge( WordPress::get_user_context( $result_user_id ), $lesson->get_data() ); $context_data['lesson_id'] = $result_item_id; } break; case 'quiz_completed': case 'quiz_failed': if ( function_exists( 'masteriyo_get_quiz' ) ) { $quiz = masteriyo_get_quiz( $result_item_id ); $context_data = WordPress::get_user_context( $result_user_id ); if ( function_exists( 'masteriyo_get_quiz_attempt' ) ) { $attempt = masteriyo_get_quiz_attempt( $quiz_attempt ); $context_data['quiz_id'] = $result_item_id; $context_data['course_id'] = $quiz->get_course_id(); $context_data['quiz'] = $quiz->get_data(); $context_data['attempt'] = $attempt->get_data(); } } break; default: return; } if ( ! empty( $context_data ) ) { $context['pluggable_data'] = $context_data; $context['response_type'] = 'live'; } } elseif ( empty( $result ) ) { switch ( $trigger ) { case 'course_completed': $sample_data = '{"pluggable_data":{"wp_user_id": 1,"user_login": "admin","display_name": "admin","user_firstname": "test","user_lastname": "test","user_email": "john@d.com","user_role": ["customer"],"id": 6636,"name": "Modes Master Class","slug": "modes-master-class-2","date_created": {"date": "2023-10-20 06:09:15.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-21 15:22:29.000000","timezone_type": 1,"timezone": "+00:00"},"status": "publish","menu_order": 0,"featured": false,"catalog_visibility": "visible","description": "Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words.","short_description": "","post_password": "","author_id": 1,"parent_id": 0,"reviews_allowed": true,"date_on_sale_from": null,"date_on_sale_to": null,"price": "0","regular_price": "0","sale_price": "","price_type": "free","category_ids": [106,107],"tag_ids": [],"difficulty_id": 0,"featured_image": 6616,"rating_counts": [],"average_rating": "0","review_count": 0,"enrollment_limit": 0,"duration": 360,"access_mode": "open","billing_cycle": "","show_curriculum": true,"purchase_note": "","highlights": "

  • Suscipit tortor eget felis.<\/li>
  • Curabitur arcu erat idimper.<\/li>
  • Lorem ipsum dolor sit amet.<\/li>","is_ai_created": false,"is_creating": false,"meta_data": []},"response_type":"sample"} '; break; case 'lesson_completed': $sample_data = '{"pluggable_data":{"wp_user_id": 1,"user_login": "admin","display_name": "admin","user_firstname": "test","user_lastname": "test","user_email": "john@d.com","user_role": ["customer"],"id": 6636,"name": "Lesson 1","slug": "lesson-1","date_created": {"date": "2023-10-20 06:09:15.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-21 15:22:29.000000","timezone_type": 1,"timezone": "+00:00"},"status": "publish","menu_order": 0,"featured": false,"catalog_visibility": "visible","description": "new lesson","short_description": "","post_password": "","author_id": 1,"parent_id": 0,"course_id": 6594,"reviews_allowed": true,"featured_image": 6616,"rating_counts": [],"average_rating": "0","review_count": 0,"meta_data": [],"lesson_id": "6596"},"response_type":"sample"} '; break; case 'quiz_completed': case 'quiz_failed': $sample_data = '{"pluggable_data":{"wp_user_id": 18,"user_login": "john@yopmail.com","display_name": "johns john","user_firstname": "johns","user_lastname": "john","user_email": "john@d.com","user_role": ["customer"],"quiz_id": "6654","course_id": 6634,"quiz": {"id": 6654,"name": "New Quiz","slug": "new-quiz","date_created": {"date": "2023-10-23 16:36:14.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-23 17:10:42.000000","timezone_type": 1,"timezone": "+00:00"},"parent_id": 6630,"course_id": 6634,"author_id": 0,"menu_order": 4,"status": "publish","description": "","short_description": "","pass_mark": 2,"full_mark": 100,"duration": 0,"attempts_allowed": 0,"questions_display_per_page": 0,"meta_data": []},"attempt": {"id": 17,"course_id": 6634,"quiz_id": 6654,"user_id": "18","total_questions": 2,"total_answered_questions": 2,"total_marks": "100.00","total_attempts": 1,"total_correct_answers": 1,"total_incorrect_answers": 1,"earned_marks": "1.00","answers": {"6655": {"answered": "False","correct": false},"6656": {"answered": "False","correct": true}},"attempt_status": "attempt_ended","attempt_started_at": {"date": "2023-10-24 09:34:16.000000","timezone_type": 1,"timezone": "+00:00"},"attempt_ended_at": {"date": "2023-10-24 09:34:29.000000","timezone_type": 1,"timezone": "+00:00"},"meta_data": []}},"response_type":"sample"}'; break; default: return; } $context = json_decode( $sample_data, true ); } return $context; } /** * Search learndash user added in group. * * @param array $data data. * @return array|void */ public function search_pluggables_user_added_in_group( $data ) { $context = []; if ( ! function_exists( 'learndash_get_groups_user_ids' ) ) { return; } $term = $data['search_term']; $group_id = $data['filter']['sfwd_group_id']['value']; if ( 'user_added_group' == $term ) { if ( -1 === $group_id ) { $args = [ 'numberposts' => 1, 'orderby' => 'rand', 'post_type' => 'groups', ]; $posts = get_posts( $args ); $random_value = $posts[0]->ID; $group_users = learndash_get_groups_user_ids( $random_value ); $group_id = $random_value; } else { $group_users = learndash_get_groups_user_ids( $group_id ); } $users = get_users( [ 'meta_key' => 'learndash_group_' . $group_id . '_enrolled_at', 'orderby' => 'meta_value', 'order' => 'DESC', 'number' => 1, 'include' => $group_users, ] ); } elseif ( 'user_removed_group' == $term ) { if ( -1 === $group_id ) { $args = [ 'numberposts' => 1, 'orderby' => 'rand', 'post_type' => 'groups', ]; $posts = get_posts( $args ); $random_value = $posts[0]->ID; $group_id = $random_value; } $args = [ 'meta_query' => [ 'relation' => 'AND', [ 'key' => 'group_' . $group_id . '_access_from', 'compare' => 'NOT EXISTS', ], [ 'key' => 'learndash_group_' . $group_id . '_enrolled_at', 'compare' => 'EXISTS', ], ], 'orderby' => 'meta_value', 'order' => 'DESC', 'number' => 1, ]; $users = get_users( $args ); } elseif ( 'leader_added_group' == $term || 'leader_removed_group' == $term ) { if ( -1 === $group_id ) { $args = [ 'numberposts' => 1, 'fields' => 'ids', 'orderby' => 'rand', 'post_type' => 'groups', ]; $posts = get_posts( $args ); $random_key = array_rand( $posts ); $random_value = $posts[ $random_key ]; $group_id = $random_value; } $user_query_args = [ 'orderby' => 'learndash_group_leaders_' . intval( $group_id ), 'order' => 'DESC', 'meta_query' => [ [ 'key' => 'learndash_group_leaders_' . intval( $group_id ), 'value' => intval( $group_id ), 'compare' => '=', 'type' => 'NUMERIC', ], ], ]; $users = get_users( $user_query_args ); } if ( ! empty( $users ) ) { $context = WordPress::get_user_context( $users[0]->ID ); $context['sfwd_group_id'] = $group_id; $context['group_title'] = get_the_title( $group_id ); $context['group_url'] = get_permalink( $group_id ); $context['group_featured_image_id'] = get_post_meta( $group_id, '_thumbnail_id', true ); $context['group_featured_image_url'] = get_the_post_thumbnail_url( $group_id ); if ( function_exists( 'learndash_group_enrolled_courses' ) ) { $group_courses_id = learndash_group_enrolled_courses( $group_id ); if ( ! empty( $group_courses_id ) ) { foreach ( $group_courses_id as $key => $course_id ) { $context['group_courses'][ $key ] = LearnDash::get_course_pluggable_data( $course_id ); } } } $context['response_type'] = 'live'; } else { $context = WordPress::get_sample_user_context(); $context['group_title'] = 'Test Group'; $context['sfwd_group_id'] = 112; $context['group_url'] = 'https://example.com/test-group'; $context['group_featured_image_id'] = 113; $context['group_featured_image_url'] = 'https://example.com/test-group-img'; $context['group_courses'] = [ [ 'ID' => 7915, 'title' => 'Example Course', 'URL' => 'https://example.com/courses/example-course/', 'status' => 'publish', 'featured_image_id' => '', 'featured_image_url' => false, ], ]; $context['response_type'] = 'sample'; } $context['pluggable_data'] = $context; return $context; } /** * Search learndash user enrolled in course. * * @param array $data data. * @return array|void */ public function search_pluggables_user_enrolled_course( $data ) { global $wpdb; $context = []; if ( ! function_exists( 'ld_course_access_expires_on' ) || ! function_exists( 'learndash_group_enrolled_courses' ) || ! function_exists( 'learndash_get_lesson_list' ) ) { return; } $term = $data['search_term']; $course_id = isset( $data['filter']['sfwd_course_id'] ) ? $data['filter']['sfwd_course_id']['value'] : ''; $group_id = isset( $data['filter']['sfwd_group_id'] ) ? $data['filter']['sfwd_group_id']['value'] : ''; if ( 'course_enrolled' == $term ) { if ( -1 === $course_id ) { $courses = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='access' AND activity.activity_status= %d order by activity_id DESC LIMIT 1", 0 ) ); } else { $courses = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='access' AND activity.activity_status= %d AND activity.post_id= %d AND activity.course_id= %d order by activity_id DESC LIMIT 1", 0, $course_id, $course_id ) ); } } elseif ( 'course_unenrolled' == $term ) { if ( -1 === $course_id ) { $courses = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='access' AND activity.activity_status= %d order by activity_id DESC LIMIT 1", 0 ) ); $course_id = $courses[0]->course_id; } $args = [ 'meta_query' => [ 'relation' => 'AND', [ 'key' => 'course_' . $course_id . '_access_from', 'compare' => 'NOT EXISTS', ], [ 'key' => 'learndash_course_' . $course_id . '_enrolled_at', 'compare' => 'EXISTS', ], ], ]; $users = get_users( $args ); } elseif ( 'course_access_expired' == $term ) { if ( -1 === $course_id ) { $course_args = [ 'post_type' => 'sfwd-courses', 'posts_per_page' => 1, 'orderby' => 'rand', 'order' => 'ASC', 'post_status' => 'publish', ]; $courses_posts = get_posts( $course_args ); $course_id = $courses_posts[0]->ID; } $args = [ 'meta_query' => [ [ 'key' => 'learndash_course_expired_' . $course_id, 'compare' => 'EXISTS', ], ], ]; $users = get_users( $args ); } elseif ( 'group_course_completed' == $term ) { if ( -1 === $group_id ) { $courses = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='group_progress' AND activity.activity_status= %d order by activity_id DESC LIMIT 1", 1 ) ); } else { $courses = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='group_progress' AND activity.activity_status= %d AND activity.post_id= %d order by activity_id DESC LIMIT 1", 1, $group_id ) ); } $activity_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity_meta WHERE activity_id = %d", $courses[0]->activity_id ) ); } elseif ( 'course_group_added' == $term ) { if ( -1 === $group_id ) { $args = [ 'numberposts' => 1, 'fields' => 'ids', 'orderby' => 'rand', 'post_type' => 'groups', ]; $posts = get_posts( $args ); $random_key = array_rand( $posts ); $random_value = $posts[ $random_key ]; $group_id = $random_value; } $courses = learndash_group_enrolled_courses( $group_id ); } elseif ( 'assignment_submitted' == $term ) { $course_id = isset( $data['filter']['sfwd-courses'] ) ? $data['filter']['sfwd-courses']['value'] : ''; $lesson_id = $data['filter']['sfwd_lesson_topic_id']['value']; if ( -1 === $course_id && -1 === $lesson_id ) { $args = [ 'post_type' => 'sfwd-assignment', 'posts_per_page' => 1, 'order' => 'DESC', 'post_status' => 'publish', ]; } else { if ( -1 === $course_id ) { $courses = get_posts( [ 'posts_per_page' => - 1, 'post_type' => 'sfwd-courses', 'post_status' => 'publish', 'fields' => 'ids', ] ); $course_key = array_rand( $courses ); $course_id = $courses[ $course_key ]; } if ( -1 === $lesson_id ) { $args = [ 'post_type' => 'sfwd-assignment', 'posts_per_page' => 1, 'order' => 'DESC', 'post_status' => 'publish', 'meta_query' => [ [ 'key' => 'course_id', 'value' => $course_id, 'compare' => '=', ], ], ]; } else { $args = [ 'post_type' => 'sfwd-assignment', 'posts_per_page' => 1, 'order' => 'DESC', 'post_status' => 'publish', 'meta_query' => [ 'relation' => 'AND', [ 'key' => 'lesson_id', 'value' => $lesson_id, 'compare' => '=', ], [ 'key' => 'course_id', 'value' => $course_id, 'compare' => '=', ], ], ]; } } $assignments = get_posts( $args ); } elseif ( 'assignment_graded' == $term ) { $course_id = isset( $data['filter']['sfwd-courses'] ) ? $data['filter']['sfwd-courses']['value'] : ''; $lesson_id = $data['filter']['sfwd_lesson_topic_id']['value']; if ( -1 === $course_id && -1 === $lesson_id ) { $args = [ 'post_type' => 'sfwd-assignment', 'posts_per_page' => 1, 'order' => 'DESC', 'post_status' => 'publish', 'meta_query' => [ [ 'key' => 'approval_status', 'compare' => 'EXISTS', ], ], ]; } else { if ( -1 === $course_id ) { $courses = get_posts( [ 'posts_per_page' => - 1, 'post_type' => 'sfwd-courses', 'post_status' => 'publish', 'fields' => 'ids', ] ); $course_key = array_rand( $courses ); $course_id = $courses[ $course_key ]; } if ( -1 === $lesson_id ) { $lessons = learndash_get_lesson_list( $course_id, [ 'num' => 0 ] ); if ( ! empty( $lessons ) ) { $random_key = array_rand( $lessons ); $random_value = $lessons[ $random_key ]; $lesson_id = $random_value->ID; } } $args = [ 'post_type' => 'sfwd-assignment', 'posts_per_page' => 1, 'order' => 'DESC', 'post_status' => 'publish', 'meta_query' => [ 'relation' => 'AND', [ 'key' => 'lesson_id', 'value' => $lesson_id, 'compare' => '=', ], [ 'key' => 'course_id', 'value' => $course_id, 'compare' => '=', ], [ 'key' => 'approval_status', 'compare' => 'EXISTS', ], ], ]; } $assignments = get_posts( $args ); } if ( 'assignment_submitted' == $term || 'assignment_graded' == $term ) { if ( ! empty( $assignments ) ) { $context_data = WordPress::get_user_context( (int) $assignments[0]->post_author ); $context_data['assignment_id'] = $assignments[0]->ID; $context_data['assignment_title'] = $assignments[0]->post_title; $context_data['assignment_url'] = get_post_meta( $assignments[0]->ID, 'file_link', true ); $context_data['lesson_id'] = get_post_meta( $assignments[0]->ID, 'lesson_id', true ); $context_data['course_id'] = get_post_meta( $assignments[0]->ID, 'course_id', true ); $context_data['points'] = get_post_meta( $assignments[0]->ID, 'points', true ); $context['response_type'] = 'live'; } else { $context_data = WordPress::get_sample_user_context(); $context_data['assignment_title'] = 'Test Assignment'; $context_data['assignment_id'] = 112; $context_data['assignment_url'] = 'https://example.com/test_assignment.pdf'; $context_data['lesson_id'] = 2; $context_data['course_id'] = 1; $context_data['points'] = '12'; $context['response_type'] = 'sample'; } } elseif ( 'course_unenrolled' == $term || 'course_access_expired' == $term ) { if ( ! empty( $users ) ) { $context_data = WordPress::get_user_context( $users[0]->ID ); $context_data['sfwd_course_id'] = $course_id; $context_data['course_title'] = get_the_title( $course_id ); $context_data['course_url'] = get_permalink( $course_id ); $context_data['course_featured_image_id'] = get_post_meta( $course_id, '_thumbnail_id', true ); $context_data['course_featured_image_url'] = get_the_post_thumbnail_url( $course_id ); $timestamp = ld_course_access_expires_on( $course_id, $users[0]->ID ); $timestamp = is_numeric( $timestamp ) ? (int) $timestamp : null; $date_format = get_option( 'date_format' ); if ( is_string( $date_format ) ) { $context_data['course_access_expiry_date'] = wp_date( $date_format, $timestamp ); } $context['response_type'] = 'live'; } else { $context_data = WordPress::get_sample_user_context(); $context_data['course_name'] = 'Test Course'; $context_data['sfwd_course_id'] = 112; $context_data['course_url'] = 'https://example.com/test-course'; $context_data['course_featured_image_id'] = 113; $context_data['course_featured_image_url'] = 'https://example.com/test-course-img'; $context_data['course_access_expiry_date'] = '2023-10-20'; $context['response_type'] = 'sample'; } } elseif ( 'course_group_added' == $term ) { if ( ! empty( $courses ) ) { $context_data['course_id'] = $courses[0]; $context_data['course_title'] = get_the_title( $courses[0] ); $context_data['course_url'] = get_permalink( $courses[0] ); $context_data['course_featured_image_id'] = get_post_meta( $courses[0], '_thumbnail_id', true ); $context_data['course_featured_image_url'] = get_the_post_thumbnail_url( $courses[0] ); $context_data['sfwd_group_id'] = $group_id; $context_data['group_name'] = get_the_title( $group_id ); if ( function_exists( 'learndash_group_enrolled_courses' ) ) { $group_courses_id = learndash_group_enrolled_courses( $group_id ); if ( ! empty( $group_courses_id ) ) { foreach ( $group_courses_id as $key => $course_id ) { $context_data['group_courses'][ $key ] = LearnDash::get_course_pluggable_data( $course_id ); } } } $context['response_type'] = 'live'; } else { $context_data = WordPress::get_sample_user_context(); $context_data['course_name'] = 'Test Course'; $context_data['sfwd_course_id'] = 112; $context_data['course_url'] = 'https://example.com/test-course'; $context_data['course_featured_image_id'] = 113; $context_data['course_featured_image_url'] = 'https://example.com/test-course-img'; $context_data['course_access_expiry_date'] = '2023-10-20'; $context_data['sfwd_group_id'] = 12; $context_data['group_name'] = 'Test Group'; $context_data['group_courses'] = [ [ 'ID' => 7915, 'title' => 'Example Course', 'URL' => 'https://example.com/courses/example-course/', 'status' => 'publish', 'featured_image_id' => '', 'featured_image_url' => false, ], ]; $context['response_type'] = 'sample'; } } elseif ( 'group_course_completed' == $term ) { if ( ! empty( $courses ) && ! empty( $activity_meta ) ) { $context_data = WordPress::get_user_context( $courses[0]->user_id ); $context_data['sfwd_group_id'] = $courses[0]->post_id; $context_data['group_title'] = get_the_title( $courses[0]->post_id ); $context_data['group_url'] = get_permalink( $courses[0]->post_id ); $context_data['group_featured_image_id'] = get_post_meta( $courses[0]->post_id, '_thumbnail_id', true ); $context_data['group_featured_image_url'] = get_the_post_thumbnail_url( $courses[0]->post_id ); if ( function_exists( 'learndash_group_enrolled_courses' ) ) { $group_courses_id = learndash_group_enrolled_courses( $courses[0]->post_id ); if ( ! empty( $group_courses_id ) ) { foreach ( $group_courses_id as $key => $course_id ) { $context_data['group_courses'][ $key ] = LearnDash::get_course_pluggable_data( $course_id ); } } } $course_ids = null; foreach ( $activity_meta as $item ) { if ( 'course_ids' === $item->activity_meta_key ) { $course_ids = unserialize( $item->activity_meta_value ); break; } } if ( ! empty( $course_ids ) && is_array( $course_ids ) ) { foreach ( $course_ids as $key => $course_id ) { if ( is_numeric( $course_id ) ) { $course_id = (int) $course_id; $args = [ 'include' => [ $courses[0]->user_id ], 'meta_query' => [ [ 'key' => 'course_completed_' . $course_id, 'compare' => 'EXISTS', ], ], ]; $users = get_users( $args ); if ( ! empty( $users ) ) { $context_data[ 'completed ' . $key ]['course_id'] = $course_id; $context_data[ 'completed ' . $key ]['course_title'] = get_the_title( $course_id ); $context_data[ 'completed ' . $key ]['course_url'] = get_permalink( $course_id ); $context_data[ 'completed ' . $key ]['course_featured_image_id'] = get_post_meta( $course_id, '_thumbnail_id', true ); $context_data[ 'completed ' . $key ]['course_featured_image_url'] = get_the_post_thumbnail_url( $course_id ); $timestamp = ld_course_access_expires_on( $course_id, $courses[0]->user_id ); $timestamp = is_numeric( $timestamp ) ? (int) $timestamp : null; $date_format = get_option( 'date_format' ); if ( is_string( $date_format ) ) { $context_data[ 'completed ' . $key ]['course_access_expiry_date'] = wp_date( $date_format, $timestamp ); } } } } } $context['response_type'] = 'live'; } else { $context_data = WordPress::get_sample_user_context(); $context_data['sfwd_group_id'] = 112; $context_data['group_title'] = 'Test Group'; $context_data['group_url'] = 113; $context_data['group_featured_image_id'] = 11; $context_data['group_featured_image_url'] = 'https://example.com/test-group-img'; $context_data['completed 0'] = [ 'course_id' => 10, 'course_title' => 'Test Course', 'course_url' => 'https://example.com/test-course', 'course_featured_image_id' => 14, 'course_featured_image_url' => 'https://example.com/test-course-img', ]; $context_data['group_courses'] = [ [ 'ID' => 7915, 'title' => 'Example Course', 'URL' => 'https://example.com/courses/example-course/', 'status' => 'publish', 'featured_image_id' => '', 'featured_image_url' => false, ], ]; $context['response_type'] = 'sample'; } } else { if ( ! empty( $courses ) ) { $context_data = WordPress::get_user_context( $courses[0]->user_id ); $context_data['course_id'] = $courses[0]->course_id; $context_data['course_title'] = get_the_title( $courses[0]->course_id ); $context_data['course_url'] = get_permalink( $courses[0]->course_id ); $context_data['course_featured_image_id'] = get_post_meta( $courses[0]->course_id, '_thumbnail_id', true ); $context_data['course_featured_image_url'] = get_the_post_thumbnail_url( $courses[0]->course_id ); $timestamp = ld_course_access_expires_on( $courses[0]->course_id, $courses[0]->user_id ); $timestamp = is_numeric( $timestamp ) ? (int) $timestamp : null; $date_format = get_option( 'date_format' ); if ( is_string( $date_format ) ) { $context_data['course_access_expiry_date'] = wp_date( $date_format, $timestamp ); } if ( $courses[0]->post_id ) { $context_data['sfwd_group_id'] = $courses[0]->post_id; $context_data['group_title'] = get_the_title( $courses[0]->post_id ); $context_data['group_url'] = get_permalink( $courses[0]->post_id ); $context_data['group_featured_image_id'] = get_post_meta( $courses[0]->post_id, '_thumbnail_id', true ); $context_data['group_featured_image_url'] = get_the_post_thumbnail_url( $courses[0]->post_id ); } $context['response_type'] = 'live'; } else { $context_data = WordPress::get_sample_user_context(); $context_data['course_name'] = 'Test Course'; $context_data['sfwd_course_id'] = 112; $context_data['course_url'] = 'https://example.com/test-course'; $context_data['course_featured_image_id'] = 113; $context_data['course_featured_image_url'] = 'https://example.com/test-course-img'; $context_data['course_access_expiry_date'] = '2023-10-20'; $context['response_type'] = 'sample'; } } $context['pluggable_data'] = $context_data; return $context; } /** * Search LearnDash Lesson Topic List. * * @param array $data Search Params. * * @since 1.0.0 * * @return array */ public function search_ld_lessons_topics_list( $data ) { $options = []; $course_id = $data['dynamic']['sfwd-courses']; if ( ! function_exists( 'learndash_get_lesson_list' ) || ! function_exists( 'learndash_get_topic_list' ) ) { return []; } $lessons = learndash_get_lesson_list( $course_id, [ 'num' => 0 ] ); foreach ( $lessons as $lesson ) { $options[] = [ 'label' => $lesson->post_title, 'value' => $lesson->ID, ]; $topics = learndash_get_topic_list( $lesson->ID, $course_id ); foreach ( $topics as $topic ) { $options[] = [ 'label' => $topic->post_title, 'value' => $topic->ID, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search LearnDash Quiz List. * * @param array $data Search Params. * * @since 1.0.0 * * @return array */ public function search_ld_quiz_list( $data ) { $options = []; $course_id = $data['dynamic']['sfwd-courses']; $lesson_id = $data['dynamic']['sfwd_lessons_topics']; if ( ! function_exists( 'learndash_get_course_quiz_list' ) || ! function_exists( 'learndash_get_lesson_quiz_list' ) ) { return []; } $quizzes = learndash_get_course_quiz_list( $course_id ); $quizzes = array_merge( $quizzes, learndash_get_lesson_quiz_list( $lesson_id, null, $course_id ) ); if ( ! empty( $quizzes ) ) { foreach ( $quizzes as $quiz ) { $options[] = [ 'label' => $quiz['post']->post_title, 'value' => $quiz['post']->ID, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search LearnDash Quiz Essay Question List. * * @param array $data Search Params. * * @since 1.0.0 * * @return array */ public function search_ld_quiz_essay_question_list( $data ) { $options = []; $quiz_id = $data['dynamic']; if ( ! function_exists( 'learndash_get_quiz_questions' ) ) { return []; } if ( 0 < $quiz_id ) { $quiz_question_ids = learndash_get_quiz_questions( $quiz_id ); if ( ! empty( $quiz_question_ids ) ) { foreach ( $quiz_question_ids as $question_post_id => $question_pro_id ) { $question_type = get_post_meta( $question_post_id, 'question_type', true ); if ( is_string( $question_type ) && 'essay' === $question_type ) { $title = html_entity_decode( get_the_title( $question_post_id ), ENT_QUOTES, 'UTF-8' ); $options[] = [ 'label' => $title, 'value' => $question_post_id, ]; } } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search LearnDash Lessons List. * * @param array $data Search Params. * * @since 1.0.0 * * @return array */ public function search_ld_lessons_list( $data ) { $options = []; $course_id = $data['dynamic']['sfwd-courses']; if ( ! function_exists( 'learndash_get_lesson_list' ) ) { return []; } $lessons = learndash_get_lesson_list( $course_id, [ 'num' => 0 ] ); foreach ( $lessons as $lesson ) { $options[] = [ 'label' => $lesson->post_title, 'value' => $lesson->ID, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search LearnDash Topics List. * * @param array $data Search Params. * * @since 1.0.0 * * @return array */ public function search_ld_topics_list( $data ) { $options = []; $course_id = $data['dynamic']['sfwd-courses']; $lesson_id = $data['dynamic']['sfwd-lessons']; if ( ! function_exists( 'learndash_get_topic_list' ) ) { return []; } $topics = learndash_get_topic_list( $lesson_id, $course_id ); foreach ( $topics as $topic ) { $options[] = [ 'label' => $topic->post_title, 'value' => $topic->ID, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search LearnDash Assignments List. * * @param array $data Search Params. * * @since 1.0.0 * * @return array */ public function search_ld_assignments_list( $data ) { $options = []; $course_id = $data['dynamic']['sfwd-courses']; $lesson_id = $data['dynamic']['sfwd_lesson_topic_id']; $args = [ 'post_type' => 'sfwd-assignment', 'numberposts' => - 1, ]; $meta_query = []; if ( ! empty( $course_id ) ) { $meta_query[] = [ 'key' => 'course_id', 'value' => (int) $course_id, 'compare' => '=', ]; } if ( ! empty( $lesson_id ) ) { $meta_query[] = [ 'key' => 'lesson_id', 'value' => (int) $lesson_id, 'compare' => '=', ]; } if ( ! empty( $meta_query ) ) { $args['meta_query'] = $meta_query; if ( count( $meta_query ) > 1 ) { $args['meta_query']['relation'] = 'AND'; } } $assignments = get_posts( $args ); foreach ( $assignments as $assignment ) { $options[] = [ 'label' => $assignment->post_title, 'value' => $assignment->ID, ]; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Search post by post type. * * @param array $data Search Params. * * @since 1.0.0 * * @return array */ public function search_edd_prices( $data ) { $options = []; $downlaod_id = $data['dynamic']['download_id']; $variable_prices = get_post_meta( $downlaod_id, 'edd_variable_prices', true ); if ( ! empty( $variable_prices ) && is_array( $variable_prices ) ) { foreach ( $variable_prices as $price_id => $price ) { if ( isset( $price['name'] ) ) { $options[] = [ 'label' => $price['name'] . ' (' . $price['amount'] . ')', 'value' => $price['index'], ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * GetPowerful Docs list. * * @param array $data data. * * @return array */ public function search_pfd_docs_list( $data ) { $course_id = $data['dynamic']; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $options = []; $args = [ 'post_type' => 'docs', 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', ]; $docs = get_posts( $args ); $docs_count = wp_count_posts( 'docs' )->publish; if ( ! empty( $docs ) ) { if ( is_array( $docs ) ) { foreach ( $docs as $doc ) { $options[] = [ 'label' => $doc->post_title, 'value' => $doc->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $docs_count > $limit && $docs_count > $offset, ]; } /** * Search Powerful Docs last data. * * @param array $data data. * @return array|void|mixed */ public function search_pfd_feedback_last_data( $data ) { $sample_data = '{"pluggable_data":{"wp_user_id":4587,"user_login":"alice.wright","display_name":"Alice Wright","user_firstname":"Alice","user_lastname":"Wright","user_email":"alice.wright@example.com","user_registered":"2024-11-15 09:30:00","user_role":["subscriber","editor"],"doc_id":"3245","feedback":"yes","questions":"— Can you explain the next steps for this document?","comment":"Looking forward to your feedback.","name":"Alice Wright","email":"alice.wright@example.com","doc_name":"Project Plan Q4","doc_link":"https://example.com/project-plan-q4","time":"2025-09-29 10:00:00","doc_author_email":"author@company.com"},"response_type":"sample"}'; $context = json_decode( $sample_data, true ); return $context; } /** * WooCommerce Coupon Discount type list. * * @param array $data data. * * @return array */ public function search_woo_coupon_discount_type_list( $data ) { $options = []; $discount_types = wc_get_coupon_types(); if ( ! empty( $discount_types ) ) { if ( is_array( $discount_types ) ) { foreach ( $discount_types as $key => $value ) { $options[] = [ 'label' => $value, 'value' => $key, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * WooCommerce Product list along with variation list. * * @param array $data data. * * @return array|void */ public function search_woo_product_variation_list( $data ) { $options = []; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); if ( ! function_exists( 'wc_get_products' ) ) { return; } $products = wc_get_products( [ 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'date', 'order' => 'DESC', ] ); $prod_count = wp_count_posts( 'product' )->publish; if ( ! empty( $products ) ) { if ( is_array( $products ) ) { foreach ( $products as $product ) { $options[] = [ 'label' => $product->get_name(), 'value' => $product->get_id(), ]; if ( $product->is_type( 'variable' ) ) { $variations = Utilities::get_product_variations( $product->get_id() ); foreach ( $variations['result'] as $variation ) { $options[] = [ 'label' => $variation->post_title, 'value' => $variation->ID, ]; } } } } } return [ 'options' => $options, 'hasMore' => $prod_count > $limit && $prod_count > $offset, ]; } /** * WooCommerce Product list along with variation list. * * @param array $data data. * * @return array */ public function search_woo_coupon_list( $data ) { $options = []; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $coupons = get_posts( [ 'posts_per_page' => - 1, 'orderby' => 'name', 'order' => 'asc', 'post_type' => 'shop_coupon', 'post_status' => 'publish', ] ); $coupon_count = wp_count_posts( 'shop_coupon' )->publish; if ( ! empty( $coupons ) ) { if ( is_array( $coupons ) ) { foreach ( $coupons as $coupon ) { $code = wc_format_coupon_code( $coupon->post_title ); $options[] = [ 'label' => $code, 'value' => $code, ]; } } } return [ 'options' => $options, 'hasMore' => $coupon_count > $limit && $coupon_count > $offset, ]; } /** * Prepare LatePoint Bookings List. * * @param array $data Search Params. * @return array */ public function search_lp_bookings_list( $data ) { if ( ! class_exists( 'OsBookingHelper' ) ) { return []; } $bookings = OsBookingHelper::get_bookings_for_select(); $options = []; if ( ! empty( $bookings ) ) { foreach ( $bookings as $key => $booking ) { $options[] = [ 'label' => $booking['label'], 'value' => $booking['value'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare LatePoint Services List. * * @param array $data Search Params. * @return array */ public function search_lp_services_list( $data ) { if ( ! class_exists( 'OsServiceHelper' ) ) { return []; } $services = OsServiceHelper::get_services_list(); $options = []; if ( ! empty( $services ) ) { foreach ( $services as $key => $service ) { $options[] = [ 'label' => $service['label'], 'value' => $service['value'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare LatePoint Bundles List. * * @param array $data Search Params. * @return array */ public function search_lp_bundles_list( $data ) { global $wpdb; $bundles = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}latepoint_bundles", ARRAY_A ); $options = []; if ( ! empty( $bundles ) ) { foreach ( $bundles as $bundle ) { $options[] = [ 'label' => $bundle['name'], 'value' => $bundle['id'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare LatePoint Agents List. * * @param array $data Search Params. * @return array */ public function search_lp_agents_list( $data ) { if ( ! class_exists( 'OsAgentHelper' ) ) { return []; } $agent_ids_for_service = OsAgentHelper::get_agent_ids_for_service_and_location( $data['dynamic'] ); $agents = OsAgentHelper::get_agents_list(); $options = []; if ( ! empty( $agents ) ) { foreach ( $agents as $key => $agent ) { if ( in_array( $agent['value'], $agent_ids_for_service ) ) { $options[] = [ 'label' => $agent['label'], 'value' => $agent['value'], ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare LatePoint Agents WP User List. * * @param array $data Search Params. * @return array */ public function search_lp_user_agents_list( $data ) { if ( ! class_exists( 'OsWpUserHelper' ) ) { return []; } $agents = OsWpUserHelper::get_wp_users_for_select( [ 'role' => 'latepoint_agent' ] ); $options = []; if ( ! empty( $agents ) ) { $options = $agents; } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare LatePoint Statuses List. * * @param array $data Search Params. * @return array */ public function search_lp_statuses_list( $data ) { if ( ! class_exists( 'OsBookingHelper' ) ) { return []; } $statuses = OsBookingHelper::get_statuses_list(); $options = []; if ( ! empty( $statuses ) ) { foreach ( $statuses as $key => $label ) { $options[] = [ 'label' => $label, 'value' => $key, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare LatePoint Customers List. * * @param array $data Search Params. * @return array */ public function search_lp_customers_list( $data ) { if ( ! class_exists( 'OsCustomerHelper' ) ) { return []; } $customers = OsCustomerHelper::get_customers_for_select(); $options = []; if ( ! empty( $customers ) ) { foreach ( $customers as $key => $customer ) { $options[] = [ 'label' => $customer['label'], 'value' => $customer['value'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare SureForms Forms List. * * @param array $data Search Params. * @return array */ public function search_sureforms_form_list( $data ) { $options = []; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $forms = get_posts( [ 'posts_per_page' => - 1, 'orderby' => 'name', 'order' => 'asc', 'post_type' => 'sureforms_form', 'post_status' => 'publish', ] ); $form_count = wp_count_posts( 'sureforms_form' )->publish; if ( ! empty( $forms ) ) { if ( is_array( $forms ) ) { foreach ( $forms as $form ) { $title = html_entity_decode( get_the_title( $form->ID ), ENT_QUOTES, 'UTF-8' ); $options[] = [ 'label' => $title, 'value' => $form->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $form_count > $limit && $form_count > $offset, ]; } /** * Prepare Academy Course List. * * @param array $data Search Params. * @return array */ public function search_ac_lms_courses( $data ) { $options = []; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $courses = get_posts( [ 'posts_per_page' => - 1, 'orderby' => 'name', 'order' => 'asc', 'post_type' => 'academy_courses', 'post_status' => 'publish', ] ); $course_count = wp_count_posts( 'academy_courses' )->publish; if ( ! empty( $courses ) ) { if ( is_array( $courses ) ) { foreach ( $courses as $course ) { $options[] = [ 'label' => get_the_title( $course->ID ), 'value' => $course->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $course_count > $limit && $course_count > $offset, ]; } /** * Prepare Academy Lesson List. * * @param array $data Search Params. * @return array */ public function search_ac_lms_lessons( $data ) { $options = []; if ( ! class_exists( '\Academy\Helper' ) ) { return []; } $curriculums = \Academy\Helper::get_course_curriculum( $data['dynamic'] ); if ( ! empty( $curriculums ) ) { foreach ( $curriculums as $topic ) { if ( isset( $topic['topics'] ) && is_array( $topic['topics'] ) ) { foreach ( $topic['topics'] as $lesson ) { if ( isset( $lesson['type'] ) && 'lesson' === $lesson['type'] ) { $options[] = [ 'label' => $lesson['name'], 'value' => $lesson['id'], ]; } } } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare Academy Quiz List. * * @param array $data Search Params. * @return array */ public function search_ac_lms_quiz( $data ) { $options = []; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $quizs = get_posts( [ 'posts_per_page' => - 1, 'orderby' => 'name', 'order' => 'asc', 'post_type' => 'academy_quiz', 'post_status' => 'publish', ] ); $quiz_count = wp_count_posts( 'academy_quiz' )->publish; if ( ! empty( $quizs ) ) { if ( is_array( $quizs ) ) { foreach ( $quizs as $quiz ) { $options[] = [ 'label' => get_the_title( $quiz->ID ), 'value' => $quiz->ID, ]; } } } return [ 'options' => $options, 'hasMore' => $quiz_count > $limit && $quiz_count > $offset, ]; } /** * Search Academy LMS data. * * @param array $data data. * @return array|void */ public function search_ac_lms_last_data( $data ) { global $wpdb; $post_type = $data['post_type']; $trigger = $data['search_term']; $context = []; if ( ! class_exists( '\Academy\Helper' ) ) { return []; } $course_id = -1; $lesson_id = -1; $quiz_id = -1; if ( 'ac_lms_course_completed' === $trigger ) { $course_id = $data['filter']['course']['value']; } elseif ( 'ac_lms_lesson_completed' === $trigger ) { $course_id = $data['filter']['course']['value']; $lesson_id = $data['filter']['lesson']['value']; } elseif ( 'ac_lms_quiz_completed' === $trigger || 'ac_lms_quiz_failed' === $trigger ) { $quiz_id = $data['filter']['quiz']['value']; } elseif ( 'ac_lms_enrolled_course' === $trigger ) { $course_id = $data['filter']['course']['value']; } $users = get_users( [ 'fields' => 'ID', 'meta_key' => 'is_academy_student', ] ); if ( ! empty( $users ) ) { $user_random_key = array_rand( $users ); $user_id = $users[ $user_random_key ]; } if ( 'ac_lms_course_completed' === $trigger ) { if ( -1 === $course_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}comments as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.comment_post_ID WHERE postmeta.comment_type='course_completed' AND posts.post_type=%s order by postmeta.comment_ID DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}comments as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.comment_post_ID WHERE postmeta.comment_post_ID = %s AND postmeta.comment_type='course_completed' AND posts.post_type=%s order by postmeta.comment_ID DESC LIMIT 1", $course_id, $post_type ) ); } } elseif ( 'ac_lms_lesson_completed' === $trigger ) { if ( -1 === $course_id ) { $courses = get_posts( [ 'posts_per_page' => - 1, 'post_type' => 'academy_courses', 'post_status' => 'publish', 'fields' => 'ids', ] ); $course_id = array_rand( $courses ); $option_name = 'academy_course_' . $course_id . '_completed_topics'; } else { $option_name = 'academy_course_' . $course_id . '_completed_topics'; } if ( ! empty( $users ) ) { $meta = get_user_meta( $user_id, $option_name, true ); if ( is_string( $meta ) ) { $saved_topics_lists = (array) json_decode( $meta, true ); if ( -1 === $lesson_id ) { $result = $saved_topics_lists['lesson']; } else { if ( is_array( $saved_topics_lists['lesson'] ) ) { if ( array_key_exists( $lesson_id, $saved_topics_lists['lesson'] ) ) { $result = $saved_topics_lists['lesson']; } } } } } } elseif ( 'ac_lms_quiz_completed' === $trigger ) { if ( -1 === $quiz_id ) { $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}academy_quiz_attempts WHERE attempt_status='passed' order by attempt_id DESC LIMIT 1" ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}academy_quiz_attempts WHERE quiz_id=%s AND attempt_status='passed' order by attempt_id DESC LIMIT 1", $quiz_id ) ); } } elseif ( 'ac_lms_quiz_failed' === $trigger ) { if ( -1 === $quiz_id ) { $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}academy_quiz_attempts WHERE attempt_status='failed' order by attempt_id DESC LIMIT 1" ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}academy_quiz_attempts WHERE quiz_id=%s AND attempt_status='failed' order by attempt_id DESC LIMIT 1", $quiz_id ) ); } } elseif ( 'ac_lms_enrolled_course' === $trigger ) { if ( -1 === $course_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type = %s order by ID DESC LIMIT 1", 'academy_enrolled' ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type = %s AND post_parent = %d order by ID DESC LIMIT 1", 'academy_enrolled', $course_id ) ); } } if ( ! empty( $result ) ) { switch ( $trigger ) { case 'ac_lms_course_completed': $data = WordPress::get_post_context( $result[0]->comment_post_ID ); $context_data = WordPress::get_user_context( $result[0]->user_id ); $context_data['course_data'] = $data; $context_data['course'] = $result[0]->comment_post_ID; break; case 'ac_lms_enrolled_course': $data = WordPress::get_post_context( $result[0]->post_parent ); $context_data = WordPress::get_user_context( $result[0]->post_author ); $context_data['course_data'] = $data; $context_data['enrollment_data'] = $result[0]; $context_data['course'] = $result[0]->post_parent; break; case 'ac_lms_lesson_completed': if ( -1 === $lesson_id ) { $key = array_rand( $result ); $lesson_data = \Academy\Helper::get_lesson( $key ); } else { $lesson_data = \Academy\Helper::get_lesson( $lesson_id ); } if ( is_object( $lesson_data ) ) { $lesson_data = get_object_vars( $lesson_data ); } if ( ! empty( $users ) ) { $context_data = array_merge( $lesson_data, WordPress::get_user_context( $user_id ) ); } $context_data['course_data'] = WordPress::get_post_context( $course_id ); $context_data['lesson'] = $lesson_id; $context_data['course'] = $course_id; break; case 'ac_lms_quiz_completed': case 'ac_lms_quiz_failed': $context_data = WordPress::get_user_context( $result[0]->user_id ); $context_data['quiz_data'] = WordPress::get_post_context( $result[0]->quiz_id ); $context_data['quiz_attempt_details'] = $result; $context_data['quiz'] = $result[0]->quiz_id; break; default: return; } $context['pluggable_data'] = $context_data; $context['response_type'] = 'live'; } elseif ( empty( $result ) ) { switch ( $trigger ) { case 'ac_lms_course_completed': $sample_data = '{"pluggable_data":{"wp_user_id": 73, "user_login": "abc@yopmail.com","display_name": "data data1", "user_firstname": "data","user_lastname": "data1","user_email": "abc@yopmail.com","user_role": [],"course_data": {"ID": 6949,"post_author": "1","post_date": "2023-11-29 05:37:50","post_date_gmt": "2023-11-29 05:37:50","post_content": "\n

    this is a business course.<\/p>\n","post_title": "Business Course","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "business-course","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:27","post_modified_gmt": "2023-11-29 09:50:27","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example-wpnew.local\/course\/business-course\/","menu_order": 0,"post_type": "academy_courses","post_mime_type": "","comment_count": "0","filter": "raw"},"course": 1},"response_type":"sample"}'; break; case 'ac_lms_lesson_completed': $sample_data = '{"pluggable_data":{"ID": "1","lesson_author": "1","lesson_date": "2023-11-29 07:01:03","lesson_date_gmt": "2023-11-29 07:01:03","lesson_title": "Lesson 1","lesson_name": "","lesson_content": "","lesson_excerpt": "","lesson_status": "publish","comment_status": "close","comment_count": "0","lesson_password": "","lesson_modified": "2023-11-29 07:01:03","lesson_modified_gmt": "2023-11-29 07:01:03","wp_user_id": 73,"user_login": "abc@yopmail.com","display_name": "data data1","user_firstname": "data","user_lastname": "data1","user_email": "abc@yopmail.com","user_role": [],"course_data": {"ID": 6949,"post_author": "1","post_date": "2023-11-29 05:37:50","post_date_gmt": "2023-11-29 05:37:50","post_content": "\n

    this is a business course.<\/p>\n","post_title": "Business Course","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "business-course","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:27","post_modified_gmt": "2023-11-29 09:50:27","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example-wpnew.local\/course\/business-course\/","menu_order": 0,"post_type": "academy_courses","post_mime_type": "","comment_count": "0","filter": "raw"},"lesson": 1,"course":1},"response_type":"sample"}'; break; case 'ac_lms_quiz_completed': $sample_data = '{"pluggable_data":{"wp_user_id": 73,"user_login": "abc@yopmail.com","display_name": "data data1","user_firstname": "data","user_lastname": "data1","user_email": "abc@yopmail.com","user_role": [],"quiz_data": {"ID": 6960,"post_author": "1","post_date": "2023-11-29 09:49:42","post_date_gmt": "2023-11-29 09:49:42","post_content": "","post_title": "First Quiz","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "closed","post_password": "","post_name": "first-quiz","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:11","post_modified_gmt": "2023-11-29 09:50:11","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example-wpnew.local\/?post_type=academy_quiz&p=6960","menu_order": 0,"post_type": "academy_quiz","post_mime_type": "","comment_count": "0","filter": "raw"}, "quiz_attempt_details": [{"attempt_id": "2","course_id": "6949","quiz_id": "6960","user_id": "126","total_questions": "1","total_answered_questions": "1","total_marks": "20.00","earned_marks": "20.00","attempt_info": "{\"total_correct_answers\":1}","attempt_status": "passed","attempt_ip": "127.0.0.1","attempt_started_at": "2023-11-30 06:20:10","attempt_ended_at": "2023-11-30 06:20:10","is_manually_reviewed": null,"manually_reviewed_at": null}],"quiz":1},"response_type":"sample"}'; break; case 'ac_lms_quiz_failed': $sample_data = '{"pluggable_data":{"wp_user_id": 73,"user_login": "abc@yopmail.com","display_name": "data data1","user_firstname": "data","user_lastname": "data1","user_email": "abc@yopmail.com","user_role": [],"quiz_data": {"ID": 6960,"post_author": "1","post_date": "2023-11-29 09:49:42","post_date_gmt": "2023-11-29 09:49:42","post_content": "","post_title": "First Quiz","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "closed","post_password": "","post_name": "first-quiz","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:11","post_modified_gmt": "2023-11-29 09:50:11","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example-wpnew.local\/?post_type=academy_quiz&p=6960","menu_order": 0,"post_type": "academy_quiz","post_mime_type": "","comment_count": "0","filter": "raw"}, "quiz_attempt_details": [{"attempt_id": "2","course_id": "6949","quiz_id": "6960","user_id": "126","total_questions": "1","total_answered_questions": "1","total_marks": "20.00","earned_marks": "0.00","attempt_info": "{\"total_correct_answers\":0}","attempt_status": "failed","attempt_ip": "127.0.0.1","attempt_started_at": "2023-11-30 06:20:10","attempt_ended_at": "2023-11-30 06:20:10","is_manually_reviewed": null,"manually_reviewed_at": null}],"quiz":1},"response_type":"sample"}'; break; case 'ac_lms_enrolled_course': $sample_data = '{"pluggable_data":{"course_data": {"ID": 6949,"post_author": "1","post_date": "2023-11-29 05:37:50","post_date_gmt": "2023-11-29 05:37:50","post_content": "\n

    this is a business course.<\/p>\n","post_title": "Business Course","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "business-course","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:27","post_modified_gmt": "2023-11-29 09:50:27","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example-wpnew.local\/course\/business-course\/","menu_order": 0,"post_type": "academy_courses","post_mime_type": "","comment_count": "0","filter": "raw"},"enrollment_data": {"ID": "6971","post_author": "126","post_date": "2023-11-30 05:52:54","post_date_gmt": "2023-11-30 05:52:54","post_content": "","post_title": "Course Enrolled November 30, 2023 @ 5:52 am","post_excerpt": "","post_status": "completed","comment_status": "closed","ping_status": "closed","post_password": "","post_name": "course-enrolled-november-30-2023-552-am","to_ping": "","pinged": "","post_modified": "2023-11-30 05:52:54","post_modified_gmt": "2023-11-30 05:52:54","post_content_filtered": "","post_parent": "6949","guid": "https:\/\/example-wpnew.local\/?p=6971","menu_order": "0","post_type": "academy_enrolled","post_mime_type": "","comment_count": "0"},"course":1, "wp_user_id": 2,"user_login": "test","display_name": "test test","user_firstname": "test","user_lastname": "test", "user_email": "test@yopmail.com","user_role": ["academy_student"]},"response_type":"sample"}'; break; default: return; } $context = (array) json_decode( $sample_data, true ); } return $context; } /** * Search myCred Point Type List. * * @param array $data Search Params. * @return array */ public function search_mycred_point_type_list( $data ) { $options = []; if ( ! function_exists( 'mycred_get_types' ) ) { return []; } $posts = mycred_get_types(); if ( ! empty( $posts ) ) { if ( is_array( $posts ) ) { foreach ( $posts as $key => $post ) { $options[] = [ 'label' => $post, 'value' => $key, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Prepare elementor forms. * * @param array $data Search Params. * * @return array */ public function search_new_elementor_form_fields( $data ) { $fields = []; $select_form_id = $data['dynamic']; global $wpdb; $post_metas = $wpdb->get_results( $wpdb->prepare( "SELECT pm.post_id, pm.meta_value FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts p ON p.ID = pm.post_id WHERE p.post_type IS NOT NULL AND p.post_status = %s AND pm.meta_key = %s AND pm.`meta_value` LIKE %s", 'publish', '_elementor_data', '%%form_fields%%' ) ); if ( ! empty( $post_metas ) ) { foreach ( $post_metas as $post_meta ) { /** * * Ignore line * * @phpstan-ignore-next-line */ $inner_forms = Utilities::search_elementor_forms( json_decode( $post_meta->meta_value ) ); if ( ! empty( $inner_forms ) ) { foreach ( $inner_forms as $form ) { $form_id = explode( '_', $select_form_id ); if ( is_object( $form ) ) { if ( $form->id == $form_id[1] ) { if ( ! empty( $form->settings->form_fields ) ) { foreach ( $form->settings->form_fields as $field ) { $fields[] = [ 'value' => $field->custom_id, 'text' => ! empty( $field->field_label ) ? $field->field_label : 'unknown', ]; } } } } } } } } $options = []; if ( ! empty( $fields ) ) { foreach ( $fields as $key => $value ) { $options[] = [ 'label' => $value['text'], 'value' => $value['value'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Fluent Booking Appointment Events. * * @param array $data data. * * @return array */ public function search_fluent_booking_calendars_list( $data ) { global $wpdb; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $calendars = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS id, title FROM {$wpdb->prefix}fcal_calendars WHERE status = %s ORDER BY id DESC LIMIT %d OFFSET %d", [ 'active', $limit, $offset ] ), OBJECT ); $calendars_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); $options = []; if ( ! empty( $calendars ) ) { foreach ( $calendars as $calendar ) { $options[] = [ 'label' => $calendar->title, 'value' => $calendar->id, ]; } } return [ 'options' => $options, 'hasMore' => $calendars_count > $limit && $calendars_count > $offset, ]; } /** * Get Fluent Booking Appointment Events. * * @param array $data data. * * @return array */ public function search_fluent_booking_events_list( $data ) { global $wpdb; $page = $data['page']; $limit = Utilities::get_search_page_limit(); $offset = $limit * ( $page - 1 ); $calendar_id = sanitize_text_field( $data['dynamic']['calender_id'] ); if ( '-1' === $calendar_id ) { $events = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS id, title FROM {$wpdb->prefix}fcal_calendar_events WHERE status = %s ORDER BY id DESC LIMIT %d OFFSET %d", [ 'active', $limit, $offset ] ), OBJECT ); } else { $events = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS id, title FROM {$wpdb->prefix}fcal_calendar_events WHERE status = %s AND calendar_id = %d ORDER BY id DESC LIMIT %d OFFSET %d", [ 'active', $calendar_id, $limit, $offset ] ), OBJECT ); } $events_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); $options = []; if ( ! empty( $events ) ) { foreach ( $events as $event ) { $options[] = [ 'label' => $event->title, 'value' => $event->id, ]; } } return [ 'options' => $options, 'hasMore' => $events_count > $limit && $events_count > $offset, ]; } /** * Get Fluent Booking last data. * * @param array $data data. * * @return array */ public function search_fluent_booking_last_data( $data ) { global $wpdb; $trigger = $data['search_term']; $course_data = []; $lesson_data = []; $sample_data = '{"pluggable_data":{"booking":{"id":"7","hash":"dc641fd972e27be079945e3f998def39","calendar_id":"1","event_id":"1","group_id":"7","fcrm_id":null,"parent_id":null,"host_user_id":"1","person_user_id":"1","person_contact_id":null,"person_time_zone":"Asia/Calcutta","start_time":"2024-01-29 11:00:00","end_time":"2024-01-29 11:15:00","slot_minutes":"15","first_name":"Sure","last_name":"Test","email":"dev-email@wpengine.local","message":"","internal_note":null,"phone":"","country":null,"ip_address":"","browser":null,"device":null,"other_info":null,"location_details":{"type":"in_person_guest","description":"Location description."},"cancelled_by":"1","status":"completed","source":"web","booking_type":"scheduling","event_type":"single","payment_status":null,"payment_method":null,"source_url":"https://connector.com/fluent-booking/","source_id":null,"utm_source":"","utm_medium":"","utm_campaign":"","utm_term":"","created_at":"2024-01-29 06:46:22","updated_at":"2024-01-29 06:57:42","custom_fields":null},"event":{"id":"1","hash":"38c65708b797f5d6956070896f792b34","user_id":"1","calendar_id":"1","duration":"15","title":"One to one","slug":"15min","media_id":null,"description":"","settings":{"schedule_type":"weekly_schedules","weekly_schedules":{"sun":{"enabled":false,"slots":[]},"mon":{"enabled":true,"slots":[{"start":"03:30","end":"11:30"}]},"tue":{"enabled":true,"slots":[{"start":"03:30","end":"11:30"}]},"wed":{"enabled":true,"slots":[{"start":"03:30","end":"11:30"}]},"thu":{"enabled":true,"slots":[{"start":"03:30","end":"11:30"}]},"fri":{"enabled":true,"slots":[{"start":"03:30","end":"11:30"}]},"sat":{"enabled":false,"slots":[]}},"date_overrides":[],"range_type":"range_days","range_days":60,"range_date_between":["",""],"schedule_conditions":{"value":4,"unit":"hours"},"location_fields":{"conferencing":{"label":"Conferencing","options":{"google_meet":{"title":"Google Meet (Connect Google Meet First)","disabled":true,"location_type":"conferencing"},"ms_teams":{"title":"MS Teams (Connect Outlook First)","disabled":true,"location_type":"conferencing"}}},"in_person":{"label":"In Person","options":{"in_person_guest":{"title":"In Person (Attendee Address)"},"in_person_organizer":{"title":"In Person (Organizer Address)"}}},"phone":{"label":"Phone","options":{"phone_guest":{"title":"Attendee Phone Number"},"phone_organizer":{"title":"Organizer Phone Number"}}},"online":{"label":"Online","options":{"online_meeting":{"title":"Online Meeting"}}},"other":{"label":"Other","options":{"custom":{"title":"Custom"}}}},"team_members":[],"custom_redirect":{"enabled":false,"redirect_url":"","is_query_string":"no","query_string":""},"multi_duration":{"enabled":true,"default_duration":"15","available_durations":["15","30","45"]}},"availability_type":"existing_schedule","availability_id":"1","status":"active","type":"free","color_schema":"#0099ff","location_type":"","location_heading":"","location_settings":[{"type":"in_person_guest","title":"In Person (Attendee Address)","display_on_booking":""}],"event_type":"single","is_display_spots":"0","max_book_per_slot":"1","created_at":"2024-01-28 08:35:29","updated_at":"2024-01-28 08:36:06"}},"response_type":"sample"}'; //phpcs:ignore $context = [ 'pluggable_data' => json_decode( $sample_data, true ), 'response_type' => 'sample', ]; if ( 'fluent_booking_appointment_cancelled' === $trigger ) { $status = 'cancelled'; } elseif ( 'fluent_booking_appointment_completed' === $trigger ) { $status = 'completed'; } $event_id = (int) $data['filter']['event_id']['value']; if ( 'fluent_booking_appointment_cancelled' === $trigger || 'fluent_booking_appointment_completed' === $trigger ) { if ( $event_id > 0 ) { $booking = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fcal_bookings WHERE event_id= %d AND status= %s ORDER BY id DESC LIMIT 1", $event_id, $status ) ); } else { $booking = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fcal_bookings WHERE status= %s ORDER BY id DESC LIMIT 1", $status ) ); } } elseif ( 'fluent_booking_new_appointment_booked' === $trigger ) { if ( $event_id > 0 ) { $booking = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fcal_bookings WHERE event_id= %d AND status != %s ORDER BY id DESC LIMIT 1", $event_id, 'cancelled' ) ); } else { $booking = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fcal_bookings WHERE status != %s ORDER BY id DESC LIMIT 1", 'cancelled' ) ); } } if ( ! empty( $booking ) ) { $booking_meta = $wpdb->get_row( $wpdb->prepare( "SELECT value FROM {$wpdb->prefix}fcal_booking_meta WHERE booking_id= %d AND meta_key= 'custom_fields_data'", $booking->id ) ); $booking_event = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fcal_calendar_events WHERE id= %d", $booking->event_id ) ); $booking_data = $booking; $booking_data->custom_fields = $booking_meta->value; $booking_array = [ 'booking' => $booking_data, 'event' => $booking_event, ]; $booking_array_response = self::recursive_unserialize( $booking_array ); $context['pluggable_data'] = $booking_array_response; $context['response_type'] = 'live'; } return $context; } /** * Recursive unserilize. * * @param array $data data. * * @return array|mixed */ public static function recursive_unserialize( $data ) { if ( is_array( $data ) ) { foreach ( $data as $key => $value ) { $data[ $key ] = self::recursive_unserialize( $value ); } return $data; } elseif ( is_object( $data ) && 'stdClass' === get_class( $data ) ) { foreach ( $data as $property => $value ) { $data->$property = self::recursive_unserialize( $value ); } return $data; } elseif ( is_string( $data ) && self::is_serialized( strval( $data ) ) ) { return unserialize( $data ); } else { return $data; } } /** * Check if string serialized. * * @param string $data data. * * @return bool */ public static function is_serialized( $data ) { if ( is_serialized( $data ) ) { return true; } else { return false; } } /** * Search Tutor LMS data. * * @param array $data data. * @return array|void|mixed */ public function search_tutor_lms_last_data( $data ) { global $wpdb; $post_type = $data['post_type']; $trigger = $data['search_term']; $context = []; if ( ! function_exists( 'tutor_utils' ) ) { return []; } $post_id = -1; if ( 'course_enrolled' === $trigger || 'tutor_courses_question' === $trigger ) { $post_id = $data['filter']['tutor_course']['value']; } elseif ( 'quiz_attempt_percentage' === $trigger || 'quiz_failed' === $trigger || 'quiz_passed' === $trigger ) { $post_id = $data['filter']['quiz_id']['value']; } if ( 'course_enrolled' === $trigger ) { if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_status='completed' AND post_type=%s order by ID DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_parent = %s AND post_status='completed' AND post_type=%s order by ID DESC LIMIT 1", $post_id, $post_type ) ); } } elseif ( 'tutor_courses_question' === $trigger ) { if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}comments as comment JOIN {$wpdb->prefix}posts as posts ON posts.ID=comment.comment_post_ID WHERE comment.comment_approved='approved' AND comment.comment_type='tutor_q_and_a' AND posts.post_type=%s order by comment.comment_ID DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}comments as comment JOIN {$wpdb->prefix}posts as posts ON posts.ID=comment.comment_post_ID WHERE comment.comment_post_ID = %s AND comment.comment_approved='approved' AND comment.comment_type='tutor_q_and_a' AND posts.post_type=%s order by comment.comment_ID DESC LIMIT 1", $post_id, $post_type ) ); } } elseif ( 'quiz_passed' === $trigger ) { if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_quiz_attempts as quiz JOIN {$wpdb->prefix}posts as posts ON posts.ID=quiz.quiz_id WHERE quiz.attempt_status='attempt_ended' AND quiz.earned_marks >= quiz.total_marks AND posts.post_type=%s order by quiz.attempt_id DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_quiz_attempts as quiz JOIN {$wpdb->prefix}posts as posts ON posts.ID=quiz.quiz_id WHERE quiz.quiz_id = %s AND quiz.attempt_status='attempt_ended' AND quiz.earned_marks >= quiz.total_marks AND posts.post_type=%s order by quiz.attempt_id DESC LIMIT 1", $post_id, $post_type ) ); } } elseif ( 'quiz_failed' === $trigger ) { if ( -1 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_quiz_attempts as quiz JOIN {$wpdb->prefix}posts as posts ON posts.ID=quiz.quiz_id WHERE quiz.attempt_status='attempt_ended' AND quiz.earned_marks < quiz.total_marks AND posts.post_type=%s order by quiz.attempt_id DESC LIMIT 1", $post_type ) ); } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_quiz_attempts as quiz JOIN {$wpdb->prefix}posts as posts ON posts.ID=quiz.quiz_id WHERE quiz.quiz_id = %s AND quiz.attempt_status='attempt_ended' AND quiz.earned_marks < quiz.total_marks AND posts.post_type=%s order by quiz.attempt_id DESC LIMIT 1", $post_id, $post_type ) ); } } elseif ( 'quiz_attempt_percentage' == $trigger ) { $condition_compare = 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 === $post_id ) { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_quiz_attempts as quiz JOIN {$wpdb->prefix}posts as posts ON posts.ID=quiz.quiz_id WHERE earned_marks $condition_compare %d AND quiz.attempt_status='attempt_ended' AND posts.post_type=%s order by quiz.attempt_id DESC LIMIT 1", $percentage, $post_type ) ); //phpcs:ignore } else { $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_quiz_attempts as quiz JOIN {$wpdb->prefix}posts as posts ON posts.ID=quiz.quiz_id WHERE earned_marks $condition_compare %d AND quiz.quiz_id = %s AND quiz.attempt_status='attempt_ended' AND posts.post_type=%s order by quiz.attempt_id DESC LIMIT 1", $percentage, $post_id, $post_type ) ); //phpcs:ignore } } if ( ! empty( $result ) ) { switch ( $trigger ) { case 'course_enrolled': $result_item_id = $result[0]->post_parent; $result_user_id = $result[0]->post_author; $context_data = array_merge( WordPress::get_user_context( $result_user_id ), WordPress::get_post_context( $result_item_id ) ); $context_data['tutor_course'] = $result_item_id; break; case 'tutor_courses_question': $date = $result[0]->comment_date; $data = [ 'comment_post_ID' => $result[0]->comment_post_ID, 'comment_author' => $result[0]->comment_author, 'comment_date' => $date, 'comment_date_gmt' => get_gmt_from_date( $date ), 'comment_content' => $result[0]->comment_content, 'comment_approved' => 'approved', 'comment_agent' => 'TutorLMSPlugin', 'comment_type' => 'tutor_q_and_a', 'comment_parent' => $result[0]->comment_parent, 'user_id' => $result[0]->user_id, ]; $context_data['tutor_course'] = $result[0]->comment_post_ID; $context_data['data'] = $data; break; case 'quiz_attempt_percentage': case 'quiz_failed': case 'quiz_passed': $attempt = tutor_utils()->get_attempt( $result[0]->attempt_id ); $context_data = WordPress::get_user_context( $result[0]->user_id ); $context_data['quiz_id'] = $attempt->quiz_id; $context_data['attempt_id'] = $result[0]->attempt_id; $context_data['attempt'] = $attempt; break; default: return; } if ( ! empty( $context_data ) ) { $context['pluggable_data'] = $context_data; $context['response_type'] = 'live'; } } elseif ( empty( $result ) ) { switch ( $trigger ) { case 'course_enrolled': $sample_data = '{"pluggable_data":{"wp_user_id": 1,"user_login": "admin","display_name": "admin","user_firstname": "test","user_lastname": "test","user_email": "john@d.com","user_role": ["customer"],"id": 6636,"name": "Modes Master Class","slug": "modes-master-class-2","date_created": {"date": "2023-10-20 06:09:15.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-21 15:22:29.000000","timezone_type": 1,"timezone": "+00:00"},"status": "publish","menu_order": 0,"featured": false,"catalog_visibility": "visible","description": "Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words.","short_description": "","post_password": "","author_id": 1,"parent_id": 0,"reviews_allowed": true,"date_on_sale_from": null,"date_on_sale_to": null,"price": "0","regular_price": "0","sale_price": "","price_type": "free","category_ids": [106,107],"tag_ids": [],"difficulty_id": 0,"featured_image": 6616,"rating_counts": [],"average_rating": "0","review_count": 0,"enrollment_limit": 0,"duration": 360,"access_mode": "open","billing_cycle": "","show_curriculum": true,"purchase_note": "","highlights": "

  • Suscipit tortor eget felis.<\/li>
  • Curabitur arcu erat idimper.<\/li>
  • Lorem ipsum dolor sit amet.<\/li>","is_ai_created": false,"is_creating": false,"meta_data": []},"response_type":"sample"} '; break; case 'tutor_courses_question': $sample_data = '{"pluggable_data":{"tutor_course": "74","data": {"comment_post_ID": "74","comment_author": "admin","comment_date": "2024-02-12 08:52:45","comment_date_gmt": "2024-02-12 08:52:45","comment_content": "asdsd","comment_approved": "approved","comment_agent": "TutorLMSPlugin","comment_type": "tutor_q_and_a","comment_parent": "0","user_id": "1"}},"response_type":"sample"}'; break; case 'quiz_attempt_percentage': case 'quiz_failed': case 'quiz_passed': $sample_data = '{"pluggable_data":{"wp_user_id": 1,"user_login": "john","display_name": "john","user_firstname": "john","user_lastname": "d","user_email": "johnd@gmail.com","user_role": ["administrator","tutor_instructor"],"quiz_id": "77","attempt_id": "1","attempt": {"attempt_id": "1","course_id": "74","quiz_id": "77","user_id": "1","total_questions": "1","total_answered_questions": "1","total_marks": "10.00","earned_marks": "10.00","attempt_info": "a:9:{s:10:\"time_limit\";a:3:{s:10:\"time_value\";s:1:\"0\";s:9:\"time_type\";s:7:\"minutes\";s:18:\"time_limit_seconds\";i:0;}s:13:\"feedback_mode\";s:5:\"retry\";s:16:\"attempts_allowed\";s:2:\"10\";s:13:\"passing_grade\";s:2:\"10\";s:24:\"max_questions_for_answer\";s:2:\"10\";s:20:\"question_layout_view\";s:0:\"\";s:15:\"questions_order\";s:4:\"rand\";s:29:\"short_answer_characters_limit\";s:3:\"200\";s:34:\"open_ended_answer_characters_limit\";s:3:\"500\";}","attempt_status":"attempt_ended","attempt_ip": "::1","attempt_started_at": "2024-02-12 09:05:15","attempt_ended_at": "2024-02-12 09:05:18","is_manually_reviewed": null,"manually_reviewed_at": null}},"response_type":"sample"}'; break; default: return; } $context = json_decode( $sample_data, true ); } return $context; } /** * Get Asgorus Forum list * * @param array $data data. * * @return array */ public function search_asgorus_forums_list( $data ) { if ( ! class_exists( 'AsgarosForum' ) ) { return []; } $category = $data['dynamic']; if ( is_array( $category ) ) { $category_id = $category['forum_category']; } else { $category_id = $category; } $asgaros_forum = new AsgarosForum(); $forums = $asgaros_forum->get_forums( $category_id ); $options = []; if ( ! empty( $forums ) ) { foreach ( $forums as $forum ) { $options[] = [ 'label' => $forum->name, 'value' => $forum->id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Asgorus Categories list * * @param array $data data. * * @return array */ public function search_asgorus_categories_list( $data ) { if ( ! class_exists( 'AsgarosForum' ) ) { return []; } $asgaros_forum = new AsgarosForum(); $categories = (array) $asgaros_forum->content->get_categories(); $options = []; if ( ! empty( $categories ) ) { foreach ( $categories as $category ) { $options[] = [ 'label' => $category->name, 'value' => $category->term_id, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Asgorus Topic lists * * @param array $data data. * * @return array */ public function search_asgorus_topic_list( $data ) { if ( ! class_exists( 'AsgarosForum' ) ) { return []; } global $wpdb; $forum_id = $data['dynamic']; $asgaros_forum = new AsgarosForum(); $sql = 'SELECT name,id FROM ' . $wpdb->prefix . 'forum_topics WHERE parent_id = %d AND closed = 0 ORDER BY id'; $topics = $wpdb->get_results( $wpdb->prepare( $sql, $forum_id ), ARRAY_A );// @phpcs:ignore $options = []; if ( ! empty( $topics ) ) { foreach ( $topics as $topic ) { $options[] = [ 'label' => $topic['name'], 'value' => $topic['id'], ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Asgorus Topic Last Data * * @param array $data data. * * @return array */ public function search_pluggables_asgaros_topic_last_data( $data ) { if ( ! class_exists( 'AsgarosForum' ) ) { return []; } $asgaros_forum = new AsgarosForum(); $context = []; global $wpdb; $forum_id = $data['filter']['forum_id']['value']; if ( -1 == $forum_id ) { $results = $wpdb->get_results( 'SELECT * from ' . $wpdb->prefix . 'forum_topics WHERE closed = 0 ORDER BY id DESC LIMIT 1', ARRAY_A ); } else { $forum = $forum_id; $sql = 'SELECT * FROM ' . $wpdb->prefix . 'forum_topics WHERE parent_id = %d AND closed = 0 ORDER BY id DESC LIMIT 1'; $results = $wpdb->get_results( $wpdb->prepare( $sql, $forum ), ARRAY_A );// @phpcs:ignore } if ( ! empty( $results ) ) { $sql_post = 'SELECT * FROM ' . $wpdb->prefix . 'forum_posts WHERE parent_id = %d ORDER BY id DESC LIMIT 1'; $results_post = $wpdb->get_results( $wpdb->prepare( $sql_post, $results[0]['id'] ), ARRAY_A ); // @phpcs:ignore $context['pluggable_data']['forum_id'] = $results[0]['parent_id']; $context['pluggable_data']['topic_id'] = $results[0]['id']; $context['pluggable_data']['post_id'] = $results_post[0]['id']; $context['pluggable_data']['forum'] = $asgaros_forum->content->get_forum( $results[0]['parent_id'] ); $context['pluggable_data']['topic'] = $asgaros_forum->content->get_topic( $results[0]['id'] ); $context['pluggable_data']['post'] = $asgaros_forum->content->get_post( $results_post[0]['id'] ); $context['pluggable_data']['author'] = WordPress::get_user_context( $results[0]['author_id'] ); $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"forum_id":"1","topic_id":"2","forum":{"id":"1","name":"First Forum","parent_id":"64","parent_forum":"0","description":"My first forum.","icon":"fas fa-comments","sort":"1","forum_status":"normal","slug":"first-forum"},"topic":{"id":"2","parent_id":"1","author_id":"1","views":"2","name":"other topic","sticky":"0","closed":"0","approved":"1","slug":"other-topic"},"user":{"wp_user_id":1,"user_login":"suredev","display_name":"SureDev","user_firstname":"Sure","user_lastname":"Dev","user_email":"dev-test@example.com","user_role":["administrator"]}},"response_type":"sample"}', true );// @phpcs:ignore } return $context; } /** * Get Asgorus Topic Reply Last Data * * @param array $data data. * * @return array */ public function search_pluggables_asgaros_reply_last_data( $data ) { if ( ! class_exists( 'AsgarosForum' ) ) { return []; } $asgaros_forum = new AsgarosForum(); $context = []; global $wpdb; $forum_id = $data['filter']['forum_id']['value']; $topic_id = $data['filter']['forum_id']['value']; if ( -1 == $topic_id ) { $results = $wpdb->get_results( 'SELECT * from ' . $wpdb->prefix . 'forum_posts ORDER BY id DESC LIMIT 1', ARRAY_A ); } else { $sql = 'SELECT * FROM ' . $wpdb->prefix . 'forum_posts WHERE parent_id = %d ORDER BY id DESC LIMIT 1'; $results = $wpdb->get_results( $wpdb->prepare( $sql, $topic_id ), ARRAY_A );// @phpcs:ignore } if ( ! empty( $results ) ) { $topic_id = $results[0]['parent_id']; $post_id = $results[0]['id']; $context['pluggable_data']['forum_id'] = $forum_id; $context['pluggable_data']['topic_id'] = $topic_id; $context['pluggable_data']['post_id'] = $post_id; $context['pluggable_data']['forum'] = $asgaros_forum->content->get_forum( $forum_id ); $context['pluggable_data']['topic'] = $asgaros_forum->content->get_topic( $topic_id ); $context['pluggable_data']['post'] = $asgaros_forum->content->get_post( $post_id ); $context['pluggable_data']['author'] = WordPress::get_user_context( $results[0]['author_id'] ); $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"forum_id":"1","topic_id":"2","forum":{"id":"1","name":"First Forum","parent_id":"64","parent_forum":"0","description":"My first forum.","icon":"fas fa-comments","sort":"1","forum_status":"normal","slug":"first-forum"},"topic":{"id":"2","parent_id":"1","author_id":"1","views":"2","name":"other topic","sticky":"0","closed":"0","approved":"1","slug":"other-topic"},"user":{"wp_user_id":1,"user_login":"suredev","display_name":"SureDev","user_firstname":"Sure","user_lastname":"Dev","user_email":"dev-test@example.com","user_role":["administrator"]}},"response_type":"sample"}', true );// @phpcs:ignore } return $context; } /** * Get WPLoyalty Points Awarded Last Data * * @param array $data data. * * @return array|mixed|string */ public function search_wp_loyalty_points_awarded_customer( $data ) { $context = []; global $wpdb; if ( ! class_exists( 'Wlr\App\Helpers\Base' ) ) { return []; } $sql = 'SELECT * FROM ' . $wpdb->prefix . 'wlr_earn_campaign_transaction WHERE transaction_type = %s ORDER BY id DESC LIMIT 1'; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'credit' ), ARRAY_A );// @phpcs:ignore if ( ! empty( $results ) ) { $context['pluggable_data']['user_email'] = $results[0]['user_email']; $context['pluggable_data']['points_earned'] = $results[0]['points']; $context['pluggable_data']['action_type'] = $results[0]['action_type']; $base_helper = new \Wlr\App\Helpers\Base(); $user = $base_helper->getPointUserByEmail( $results[0]['user_email'] ); $points_sql = 'SELECT * FROM ' . $wpdb->prefix . 'wlr_expire_points WHERE user_email = %s ORDER BY id DESC LIMIT 1'; $points_results = $wpdb->get_results( $wpdb->prepare( $points_sql, $results[0]['user_email'] ), ARRAY_A );// @phpcs:ignore $context['pluggable_data']['user'] = $user; if ( ! empty( $points_results ) ) { $expire_date = $points_results[0]['expire_date']; $timestamp = is_numeric( $expire_date ) ? (int) $expire_date : null; $date_format = get_option( 'date_format' ); if ( is_string( $date_format ) ) { $context['pluggable_data']['point_expiry_date'] = wp_date( $date_format, $timestamp ); } } $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"user_email": "johnd@yopmail.com","points_earned": "4","action_type": "point_for_purchase","user": {"id": "11","user_email": "johnd@yopmail.com","refer_code": "REF-Q5Z-ZFW","points": "17","used_total_points": "0","earn_total_point": "19","birth_date": "0","level_id": "0","is_banned_user": "0","is_allow_send_email": "1","birthday_date": "0000-00-00","last_login": "0","created_date": "1710304765"},"point_expiry_date": "April 27, 2024"},"response_type":"sample"}', true );// @phpcs:ignore } return $context; } /** * Get WPLoyalty Campaign Type List * * @param array $data data. * * @return array */ public function search_wp_loyalty_action_type_list( $data ) { $options = []; if ( ! class_exists( 'Wlr\App\Helpers\Woocommerce' ) ) { return []; } $woocommerce_helper = new \Wlr\App\Helpers\Woocommerce(); $action_types = $woocommerce_helper->getActionTypes(); if ( ! empty( $action_types ) ) { foreach ( $action_types as $key => $type ) { $options[] = [ 'label' => $type, 'value' => $key, ]; } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get last data for trigger. * * @param array $data data. * @return array */ public function search_slicewp_last_data( $data ) { global $wpdb; $context = []; $context['response_type'] = 'sample'; $user_data = WordPress::get_sample_user_context(); if ( ! function_exists( 'slicewp_get_affiliate' ) ) { return []; } $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; if ( in_array( $term, [ 'slicewp_new_affiliate', 'slicewp_update_affiliate' ], true ) ) { $affiliate = [ 'id' => 14, 'user_id' => 25, 'date_created' => '2024-03-14 12:35:50', 'date_modified' => '2024-03-14 12:36:20', 'payment_email' => 'testcustomer12@gmail.com', 'website' => '', 'status' => 'active', 'parent_id' => 0, ]; $context['pluggable_data'] = array_merge( $affiliate, [ 'user' => $user_data ] ); if ( ( ! empty( $data['filter'] ) && '-1' === $data['filter']['affiliate_id']['value'] ) || empty( $data['filter'] ) ) { $query = $wpdb->prepare( " SELECT * FROM {$wpdb->prefix}slicewp_affiliates WHERE status = %s ORDER BY id DESC LIMIT 1", 'active' ); $affiliate_results = $wpdb->get_row( $query ); //phpcs:ignore } else { $affiliate_id = $data['filter']['affiliate_id']['value']; $query = $wpdb->prepare( " SELECT * FROM {$wpdb->prefix}slicewp_affiliates WHERE status = %s AND id = %d ORDER BY id DESC LIMIT 1", 'active', $affiliate_id ); $affiliate_results = $wpdb->get_row( $query ); //phpcs:ignore } if ( ! empty( $affiliate_results ) ) { $context['pluggable_data'] = (array) $affiliate_results; $user_data = WordPress::get_user_context( $affiliate_results->user_id ); $context['pluggable_data']['user'] = $user_data; $context['response_type'] = 'live'; } } elseif ( in_array( $term, [ 'slicewp_new_commission', 'slicewp_update_commission' ], true ) ) { $commission = [ 'id' => 14, 'user_id' => 25, 'date_created' => '2024-03-14 12:35:50', 'date_modified' => '2024-03-14 12:36:20', 'payment_email' => 'testcustomer12@gmail.com', 'website' => '', 'status' => 'active', 'parent_id' => 0, ]; $context['pluggable_data'] = array_merge( $commission, [ 'user' => $user_data ] ); $affiliate_id = $data['filter']['affiliate_id']['value']; if ( -1 === $data['filter']['commission_id']['value'] ) { $query = $wpdb->prepare( " SELECT * FROM {$wpdb->prefix}slicewp_commissions WHERE affiliate_id=%d ORDER BY id DESC limit 1", $affiliate_id ); $commission_results = $wpdb->get_row( $query ); //phpcs:ignore } else { $commission_id = $data['filter']['commission_id']['value']; $query = $wpdb->prepare( " SELECT * FROM {$wpdb->prefix}slicewp_commissions WHERE id= %d AND affiliate_id=%d ORDER BY id DESC limit 1", $commission_id, $affiliate_id ); $commission_results = $wpdb->get_row( $query ); //phpcs:ignore } if ( ! empty( $commission_results ) ) { $context['pluggable_data'] = (array) $commission_results; $affiliate = slicewp_get_affiliate( $commission_results->affiliate_id ); $user_id = $affiliate->get( 'user_id' ); $user_data = WordPress::get_user_context( $user_id ); $context['pluggable_data']['user'] = $user_data; $context['response_type'] = 'live'; } } return $context; } /** * Get Ninja Tables Last Data * * @param array $data data. * * @return array */ public function search_ninja_tables_last_data( $data ) { $context = []; global $wpdb; $table_id = isset( $data['filter']['table_id']['value'] ) ? $data['filter']['table_id']['value'] : -1; if ( -1 == $table_id ) { $results = $wpdb->get_row( 'SELECT * FROM ' . $wpdb->prefix . 'ninja_table_items ORDER BY id DESC LIMIT 1', ARRAY_A ); } else { $sql = 'SELECT * FROM ' . $wpdb->prefix . 'ninja_table_items WHERE table_id = %d ORDER BY id DESC LIMIT 1'; $results = $wpdb->get_row( $wpdb->prepare( $sql, $table_id ), ARRAY_A );// @phpcs:ignore } if ( ! empty( $results ) ) { $results['value'] = json_decode( $results['value'], true ); $context['pluggable_data'] = $results; $context['pluggable_data']['owner'] = WordPress::get_user_context( $results['owner_id'] ); $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"id":"24","position":null,"table_id":"17484","owner_id":"29","attribute":"value","settings":null,"value":{"id":"3","name":"Table1","class":"Dev","gender":"Female"},"created_at":"2024-03-21 13:11:25","updated_at":"2024-03-21 13:11:25","owner":{"wp_user_id":29,"user_login":"testingdsd","display_name":"suretest","user_firstname":"John","user_lastname":"Dev","user_email":"johndoe@email.com","user_role":["editor"]}},"response_type":"sample"}', true ); } return $context; } /** * Get Ninja Tables Fields * * @param array $data data. * * @return array */ public function search_ninja_table_fields( $data ) { $context = []; global $wpdb; $table_id = isset( $data['dynamic'] ) ? $data['dynamic'] : -1; $fields = []; if ( $table_id > 0 ) { $fields = get_post_meta( $table_id, '_ninja_table_columns', true ); } return (array) $fields; } /** * Get Late Point Booking Fields * * @param array $data data. * * @return array|void */ public function search_late_point_booking_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_booking' ) ); $fields = []; if ( ! empty( $booking_fields ) ) { $fields = json_decode( $booking_fields->value, true ); } return (array) $fields; } /** Search Voxel fields for action. * * @param array $data data. * @return array */ public function search_voxel_custom_fields( $data ) { $post_type_fields = []; $post_type = $data['post_type']; if ( ! class_exists( '\Voxel\Post_Type' ) ) { return []; } $fields = \Voxel\Post_Type::get( $post_type )->get_fields(); foreach ( $fields as $key => $field ) { if ( 'step-general' == $key ) { continue; } $field_props = $field->get_props(); $post_type_fields[ $key ] = $field_props; } $context['fields'] = $post_type_fields; return $context; } /** * Get Voxel Post Types lists * * @param array $data data. * * @return array */ public function search_voxel_posttype_list( $data ) { $options = []; $voxel_post_types = []; if ( class_exists( '\Voxel\Post_Type' ) ) { $voxel_post_types = \Voxel\Post_Type::get_voxel_types(); } if ( ! empty( $voxel_post_types ) ) { foreach ( $voxel_post_types as $key => $voxel_post_type ) { $post_type = get_post_type_object( $key ); if ( $post_type ) { if ( in_array( $post_type->name, [ 'collection' ], true ) ) { continue; } $options[] = [ 'label' => esc_attr( $post_type->labels->singular_name ), 'value' => $post_type->name, ]; } } } return [ 'options' => $options, 'hasMore' => false, ]; } /** * Get Voxel Users Last Data * * @param array $data data. * * @return array|mixed|string */ public function search_voxel_users_triggers_last_data( $data ) { global $wpdb; $context = []; $term = $data['search_term']; if ( 'direct_message_received' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}voxel_messages WHERE receiver_type LIKE %s AND sender_type LIKE %s ORDER BY id DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'user', 'user' ), ARRAY_A );// @phpcs:ignore } elseif ( 'user_timeline_post_created' === $term ) { $sql = "SELECT vt.* FROM {$wpdb->prefix}voxel_timeline vt WHERE vt.feed = %s AND vt.moderation = %d ORDER BY vt.id DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'user_timeline', 0 ), ARRAY_A );// @phpcs:ignore } elseif ( 'user_timeline_post_approved' === $term ) { $sql = "SELECT vt.* FROM {$wpdb->prefix}voxel_timeline vt WHERE vt.feed = %s AND vt.moderation = %d ORDER BY vt.id DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, 'user_timeline', 1 ), ARRAY_A );// @phpcs:ignore } if ( 'direct_message_received' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data']['sender'] = WordPress::get_user_context( $results[0]['sender_id'] ); $context['pluggable_data']['receiver'] = WordPress::get_user_context( $results[0]['receiver_id'] ); $context['pluggable_data']['content'] = $results[0]['content']; $context['response_type'] = 'live'; } else { $context = json_decode( '{"pluggable_data":{"sender": {"wp_user_id": 1,"user_login": "admin","display_name": "Arian","user_firstname": "john","user_lastname": "d","user_email": "johnd@gmail.com","user_role": ["subscriber"]}},"receiver": {"wp_user_id": 101,"user_login": "benni","display_name": "Benni Ben","user_firstname": "Benni","user_lastname": "Ben","user_email": "benni@mailinator.com","user_role": ["subscriber"]},"content": "new message"},"response_type":"sample"}', true );// @phpcs:ignore } } elseif ( 'user_timeline_post_created' === $term || 'user_timeline_post_approved' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data'] = WordPress::get_user_context( $results[0]['user_id'] ); if ( class_exists( 'Voxel\Timeline\Status' ) ) { $status_details = \Voxel\Timeline\Status::get( $results[0]['id'] ); foreach ( (array) $status_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":{"wp_user_id":2,"user_login":"johnd","display_name":"johnd","user_firstname":"john","user_lastname":"doe","user_email":"johnd@gmail.com","user_registered":"2024-12-16 06:00:43","user_role":{"16":"administrator"},"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 } } return $context; } /** * Get Voxel Membership Last Data * * @param array $data data. * * @return array|mixed|string */ public function search_voxel_membership_triggers_last_data( $data ) { global $wpdb; $context = []; $term = $data['search_term']; if ( ! class_exists( 'Voxel\User' ) ) { // Return sample data when Voxel class is not available. if ( 'plan_canceled' === $term ) { $context['pluggable_data'] = WordPress::get_sample_user_context(); $context['pluggable_data']['details'] = [ 'plan' => 'premium-plus', 'type' => 'order', 'order_id' => 14, 'order_item_id' => 17, 'billing' => [ 'price_key' => 'premium-plus_pz3xfk7z', 'amount' => 20, 'currency' => 'USD', 'interval' => 'month', 'frequency' => 1, 'current_period' => [ 'start' => '2025-10-15 09:01:47', 'end' => '2025-11-15 09:01:47', ], 'is_active' => 0, 'is_canceled' => 1, ], ]; $context['response_type'] = 'sample'; } elseif ( 'plan_activated' === $term ) { $context['pluggable_data'] = WordPress::get_sample_user_context(); $context['pluggable_data']['details'] = [ 'plan' => 'premium-plus', 'type' => 'order', 'order_id' => 14, 'order_item_id' => 17, 'billing' => [ 'price_key' => 'premium-plus_pz3xfk7z', 'amount' => 20, 'currency' => 'USD', 'interval' => 'month', 'frequency' => 1, 'current_period' => [ 'start' => '2025-10-15 09:01:47', 'end' => '2025-11-15 09:01:47', ], 'is_active' => 1, 'is_canceled' => '', ], ]; $context['response_type'] = 'sample'; } elseif ( 'plan_updated' === $term ) { $context['pluggable_data'] = WordPress::get_sample_user_context(); $context['pluggable_data']['details'] = [ 'plan' => 'premium-plus', 'type' => 'subscription', 'price_id' => 'premium-plus_pz3xfk7z', 'status' => 'active', 'metadata' => [ 'voxel:payment_for' => 'membership', 'voxel:plan' => 'premium-plus', ], ]; $context['response_type'] = 'sample'; } elseif ( 'user_registered' === $term ) { $context['pluggable_data'] = WordPress::get_sample_user_context(); $context['response_type'] = 'sample'; } return $context; } if ( 'plan_activated' === $term ) { $meta_key = ( function_exists( '\Voxel\is_test_mode' ) && \Voxel\is_test_mode() ) ? 'voxel:test_plan' : 'voxel:plan'; $sql = "SELECT m.user_id AS id, u.user_login AS title, u.user_email AS email, m.meta_value AS details, JSON_UNQUOTE( JSON_EXTRACT( m.meta_value, '$.plan' ) ) AS plan, CAST( JSON_UNQUOTE( JSON_EXTRACT( m.meta_value, '$.amount' ) ) AS SIGNED ) AS amount, JSON_UNQUOTE( JSON_EXTRACT( m.meta_value, '$.status' ) ) AS status, CAST( JSON_UNQUOTE( JSON_EXTRACT( m.meta_value, '$.created' ) ) AS DATETIME ) AS created FROM {$wpdb->prefix}usermeta as m LEFT JOIN {$wpdb->prefix}users AS u ON m.user_id = u.ID WHERE m.meta_key = %s AND JSON_UNQUOTE( JSON_EXTRACT( m.meta_value, '$.plan' ) ) != 'default' ORDER BY m.user_id DESC LIMIT 25 OFFSET 0"; $results = $wpdb->get_results( $wpdb->prepare( $sql, $meta_key ), ARRAY_A );// @phpcs:ignore } elseif ( 'plan_canceled' === $term ) { // Simple approach: Get the most recent user with membership plan and modify data to show as cancelled. $meta_key = ( function_exists( '\Voxel\is_test_mode' ) && \Voxel\is_test_mode() ) ? 'voxel:test_plan' : 'voxel:plan'; $sql = "SELECT m.user_id AS id, u.user_login AS title, u.user_email AS email, m.meta_value AS details, JSON_UNQUOTE( JSON_EXTRACT( m.meta_value, '$.plan' ) ) AS plan FROM {$wpdb->prefix}usermeta as m LEFT JOIN {$wpdb->prefix}users AS u ON m.user_id = u.ID WHERE m.meta_key = %s AND JSON_UNQUOTE( JSON_EXTRACT( m.meta_value, '$.plan' ) ) != 'default' ORDER BY m.user_id DESC LIMIT 1"; $results = $wpdb->get_results( $wpdb->prepare( $sql, $meta_key ), ARRAY_A );// @phpcs:ignore } elseif ( 'plan_updated' === $term ) { $meta_key = ( function_exists( '\Voxel\is_test_mode' ) && \Voxel\is_test_mode() ) ? 'voxel:test_plan' : 'voxel:plan'; $sql = "SELECT m.user_id AS id, u.user_login AS title, u.user_email AS email, m.meta_value AS details, JSON_UNQUOTE( JSON_EXTRACT( m.meta_value, '$.plan' ) ) AS plan, CAST( JSON_UNQUOTE( JSON_EXTRACT( m.meta_value, '$.amount' ) ) AS SIGNED ) AS amount, JSON_UNQUOTE( JSON_EXTRACT( m.meta_value, '$.status' ) ) AS status, CAST( JSON_UNQUOTE( JSON_EXTRACT( m.meta_value, '$.created' ) ) AS DATETIME ) AS created FROM {$wpdb->prefix}usermeta as m LEFT JOIN {$wpdb->prefix}users AS u ON m.user_id = u.ID WHERE m.meta_key = %s AND JSON_UNQUOTE( JSON_EXTRACT( m.meta_value, '$.plan' ) ) != 'default' ORDER BY m.user_id DESC LIMIT 25 OFFSET 0"; $results = $wpdb->get_results( $wpdb->prepare( $sql, $meta_key ), ARRAY_A );// @phpcs:ignore } elseif ( 'user_registered' === $term ) { $sql = "SELECT DISTINCT u.ID FROM {$wpdb->prefix}users u JOIN {$wpdb->prefix}usermeta um ON u.ID = um.user_id WHERE um.meta_key = 'voxel:profile_id' ORDER BY ID DESC LIMIT 1"; $results = $wpdb->get_results( $sql, ARRAY_A );// @phpcs:ignore } if ( 'plan_canceled' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data'] = WordPress::get_user_context( $results[0]['id'] ); $membership_details = json_decode( $results[0]['details'], true ); $membership_details = is_array( $membership_details ) ? $membership_details : []; if ( ! isset( $membership_details['billing'] ) && isset( $membership_details['type'] ) ) { $membership_details = [ 'plan' => isset( $membership_details['plan'] ) ? $membership_details['plan'] : 'premium-plus', 'type' => 'order', 'order_id' => isset( $membership_details['order_id'] ) ? $membership_details['order_id'] : 14, 'order_item_id' => isset( $membership_details['order_item_id'] ) ? $membership_details['order_item_id'] : 17, 'billing' => [ 'price_key' => isset( $membership_details['price_id'] ) ? $membership_details['price_id'] : 'premium-plus_pz3xfk7z', 'amount' => isset( $membership_details['amount'] ) ? $membership_details['amount'] : 20, 'currency' => isset( $membership_details['currency'] ) ? $membership_details['currency'] : 'USD', 'interval' => isset( $membership_details['interval'] ) ? $membership_details['interval'] : 'month', 'frequency' => isset( $membership_details['interval_count'] ) ? $membership_details['interval_count'] : 1, 'current_period' => [ 'start' => gmdate( 'Y-m-d H:i:s' ), 'end' => gmdate( 'Y-m-d H:i:s', strtotime( '+1 month' ) ), ], 'is_active' => 0, 'is_canceled' => 1, ], ]; } else { if ( isset( $membership_details['billing'] ) ) { $membership_details['billing']['is_active'] = 0; $membership_details['billing']['is_canceled'] = 1; } } $context['pluggable_data']['details'] = $membership_details; $context['response_type'] = 'live'; } else { $context['pluggable_data'] = WordPress::get_sample_user_context(); $context['pluggable_data']['details'] = [ 'plan' => 'premium-plus', 'type' => 'order', 'order_id' => 14, 'order_item_id' => 17, 'billing' => [ 'price_key' => 'premium-plus_pz3xfk7z', 'amount' => 20, 'currency' => 'USD', 'interval' => 'month', 'frequency' => 1, 'current_period' => [ 'start' => '2025-10-15 09:01:47', 'end' => '2025-11-15 09:01:47', ], 'is_active' => 0, 'is_canceled' => 1, ], ]; $context['response_type'] = 'sample'; } } elseif ( 'plan_activated' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data'] = WordPress::get_user_context( $results[0]['id'] ); $membership_details = json_decode( $results[0]['details'], true ); $membership_details = is_array( $membership_details ) ? $membership_details : []; if ( ! isset( $membership_details['billing'] ) && isset( $membership_details['type'] ) ) { $membership_details = [ 'plan' => isset( $membership_details['plan'] ) ? $membership_details['plan'] : 'premium-plus', 'type' => 'order', 'order_id' => isset( $membership_details['order_id'] ) ? $membership_details['order_id'] : 14, 'order_item_id' => isset( $membership_details['order_item_id'] ) ? $membership_details['order_item_id'] : 17, 'billing' => [ 'price_key' => isset( $membership_details['price_id'] ) ? $membership_details['price_id'] : 'premium-plus_pz3xfk7z', 'amount' => isset( $membership_details['amount'] ) ? $membership_details['amount'] : 20, 'currency' => isset( $membership_details['currency'] ) ? $membership_details['currency'] : 'USD', 'interval' => isset( $membership_details['interval'] ) ? $membership_details['interval'] : 'month', 'frequency' => isset( $membership_details['interval_count'] ) ? $membership_details['interval_count'] : 1, 'current_period' => [ 'start' => gmdate( 'Y-m-d H:i:s' ), 'end' => gmdate( 'Y-m-d H:i:s', strtotime( '+1 month' ) ), ], 'is_active' => 1, 'is_canceled' => '', ], ]; } $context['pluggable_data']['details'] = $membership_details; $context['response_type'] = 'live'; } else { $context['pluggable_data'] = WordPress::get_sample_user_context(); $context['pluggable_data']['details'] = [ 'plan' => 'premium-plus', 'type' => 'order', 'order_id' => 14, 'order_item_id' => 17, 'billing' => [ 'price_key' => 'premium-plus_pz3xfk7z', 'amount' => 20, 'currency' => 'USD', 'interval' => 'month', 'frequency' => 1, 'current_period' => [ 'start' => '2025-10-15 09:01:47', 'end' => '2025-11-15 09:01:47', ], 'is_active' => 1, 'is_canceled' => '', ], ]; $context['response_type'] = 'sample'; } } elseif ( 'plan_updated' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data'] = WordPress::get_user_context( $results[0]['id'] ); $context['pluggable_data']['details'] = json_decode( $results[0]['details'], true ); $context['response_type'] = 'live'; } else { $context['pluggable_data'] = WordPress::get_sample_user_context(); $context['pluggable_data']['details'] = [ 'plan' => 'premium-plus', 'type' => 'subscription', 'price_id' => 'premium-plus_pz3xfk7z', 'status' => 'active', 'metadata' => [ 'voxel:payment_for' => 'membership', 'voxel:plan' => 'premium-plus', ], ]; $context['response_type'] = 'sample'; } } elseif ( 'user_registered' === $term ) { if ( ! empty( $results ) ) { $context['pluggable_data'] = WordPress::get_user_context( $results[0]['ID'] ); $context['response_type'] = 'live'; } else { $context['pluggable_data'] = WordPress::get_sample_user_context(); $context['response_type'] = 'sample'; } } return $context; } /** * Get Voxel Orders Last Data * * @param array $data data. * * @return array|mixed|string */ public function search_voxel_order_triggers_last_data( $data ) { global $wpdb; $context = []; $term = $data['search_term']; if ( ! class_exists( 'Voxel\Product_Types\Orders\Order' ) ) { return []; } if ( 'order_placed' === $term || 'order_canceled' === $term ) { if ( 'order_placed' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}vx_orders ORDER BY id DESC LIMIT 1"; } elseif ( 'order_canceled' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}vx_orders WHERE status = 'canceled' 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']['vendor_id'] = $results[0]['vendor_id']; $context['pluggable_data']['details'] = json_decode( $results[0]['details'], true ); $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']; $context['pluggable_data']['subtotal'] = $results[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'] ); $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": 10,"total": 10,"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": []}],"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_approved' === $term || 'order_declined' === $term ) { if ( 'order_approved' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}vx_orders WHERE status = 'completed' ORDER BY id DESC LIMIT 1"; } elseif ( 'order_declined' === $term ) { $sql = "SELECT * FROM {$wpdb->prefix}vx_orders WHERE status = 'canceled' 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']['vendor_id'] = $results[0]['vendor_id']; $context['pluggable_data']['details'] = json_decode( $results[0]['details'], true ); $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']; $context['pluggable_data']['subtotal'] = $results[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();