AuthController.php
3 years ago
AutomationController.php
3 years ago
EventController.php
3 years ago
EventHelperController.php
3 years ago
GlobalSearchController.php
3 years ago
IntegrationsController.php
3 years ago
OptionController.php
3 years ago
RestController.php
3 years ago
RoutesController.php
3 years ago
SettingsController.php
3 years ago
GlobalSearchController.php
7369 lines
| 1 | <?php |
| 2 | /** |
| 3 | * GlobalSearchController. |
| 4 | * php version 5.6 |
| 5 | * |
| 6 | * @category GlobalSearchController |
| 7 | * @package SureTriggers |
| 8 | * @author BSF <username@example.com> |
| 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 10 | * @link https://www.brainstormforce.com/ |
| 11 | * @since 1.0.0 |
| 12 | */ |
| 13 | |
| 14 | namespace SureTriggers\Controllers; |
| 15 | |
| 16 | use DOMDocument; |
| 17 | use FluentCrm\App\Models\CustomContactField; |
| 18 | use FluentCrm\App\Models\Subscriber; |
| 19 | use FluentCrm\App\Models\Tag; |
| 20 | use memberpress\courses\lib as lib; |
| 21 | use memberpress\courses\models as models; |
| 22 | use FluentCrm\Framework\Support\Arr; |
| 23 | use GFCommon; |
| 24 | use GFFormsModel; |
| 25 | use Give_Payment; |
| 26 | use MeprBaseRealGateway; |
| 27 | use MeprOptions; |
| 28 | use PrestoPlayer\Models\Video; |
| 29 | use RGFormsModel; |
| 30 | use SureTriggers\Integrations\AffiliateWP\AffiliateWP; |
| 31 | use SureTriggers\Integrations\EDD\EDD; |
| 32 | use SureTriggers\Integrations\FunnelKitAutomations\FunnelKitAutomations; |
| 33 | use SureTriggers\Integrations\JetpackCRM\JetpackCRM; |
| 34 | use SureTriggers\Integrations\LearnDash\LearnDash; |
| 35 | use SureTriggers\Integrations\LifterLMS\LifterLMS; |
| 36 | use SureTriggers\Integrations\MemberPress\MemberPress; |
| 37 | use SureTriggers\Integrations\MemberPressCourse\MemberPressCourse; |
| 38 | use SureTriggers\Integrations\PeepSo\PeepSo; |
| 39 | use SureTriggers\Integrations\RestrictContent\RestrictContent; |
| 40 | use SureTriggers\Integrations\TheEventCalendar\TheEventCalendar; |
| 41 | use SureTriggers\Integrations\WishlistMember\WishlistMember; |
| 42 | use SureTriggers\Integrations\WooCommerce\WooCommerce; |
| 43 | use SureTriggers\Integrations\WordPress\WordPress; |
| 44 | use SureTriggers\Models\Utilities; |
| 45 | use SureTriggers\Traits\SingletonLoader; |
| 46 | use Tribe__Tickets__Tickets_Handler; |
| 47 | use WC_Subscription; |
| 48 | use WC_Subscriptions_Product; |
| 49 | use WP_Query; |
| 50 | use WP_Comment_Query; |
| 51 | use WP_REST_Request; |
| 52 | use WP_REST_Response; |
| 53 | use WPForms_Form_Handler; |
| 54 | use CP_V2_Popups; |
| 55 | use Project_Huddle; |
| 56 | use FrmForm; |
| 57 | use Forminator_API; |
| 58 | use SureTriggers\Integrations\LearnPress\LearnPress; |
| 59 | |
| 60 | /** |
| 61 | * GlobalSearchController- Add ajax related functions here. |
| 62 | * |
| 63 | * @category GlobalSearchController |
| 64 | * @package SureTriggers |
| 65 | * @author BSF <username@example.com> |
| 66 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 67 | * @link https://www.brainstormforce.com/ |
| 68 | * @since 1.0.0 |
| 69 | * |
| 70 | * @psalm-suppress UndefinedTrait |
| 71 | */ |
| 72 | class GlobalSearchController { |
| 73 | |
| 74 | use SingletonLoader; |
| 75 | |
| 76 | /** |
| 77 | * Search post by post type. |
| 78 | * |
| 79 | * @param array $data Search Params. |
| 80 | * |
| 81 | * @since 1.0.0 |
| 82 | * |
| 83 | * @return array |
| 84 | */ |
| 85 | public function search_post( $data ) { |
| 86 | $result = []; |
| 87 | $posts = Utilities::find_posts_by_title( $data ); |
| 88 | |
| 89 | foreach ( $posts['results'] as $post ) { |
| 90 | $result[] = [ |
| 91 | 'label' => $post['post_title'], |
| 92 | 'value' => $post['ID'], |
| 93 | ]; |
| 94 | } |
| 95 | |
| 96 | return [ |
| 97 | 'options' => $result, |
| 98 | 'hasMore' => $posts['has_more'], |
| 99 | ]; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Search Course. |
| 104 | * |
| 105 | * @param array $data quesry params. |
| 106 | * |
| 107 | * @return array |
| 108 | * @since 1.0.0 |
| 109 | */ |
| 110 | public function search_ld_course( $data ) { |
| 111 | $courses = get_posts( |
| 112 | [ |
| 113 | |
| 114 | 'post_type' => 'product', |
| 115 | 'meta_key' => '_related_course', |
| 116 | 'post_status' => 'publish', |
| 117 | ] |
| 118 | ); |
| 119 | $options = []; |
| 120 | foreach ( $courses as $course ) { |
| 121 | $options[] = [ |
| 122 | 'label' => $course->post_title, |
| 123 | 'value' => $course->ID, |
| 124 | ]; |
| 125 | } |
| 126 | |
| 127 | return [ |
| 128 | 'options' => $options, |
| 129 | 'hasMore' => false, |
| 130 | ]; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Search achievement by post type. |
| 135 | * |
| 136 | * @param array $data Search Params. |
| 137 | * |
| 138 | * @since 1.0.0 |
| 139 | * |
| 140 | * @return array |
| 141 | */ |
| 142 | public function search_achievements( $data ) { |
| 143 | $post = get_post( $data['dynamic'] ); |
| 144 | $slug = $post->post_name; |
| 145 | |
| 146 | $achievements = get_posts( |
| 147 | [ |
| 148 | 'post_type' => $slug, |
| 149 | 'post_status' => 'publish', |
| 150 | ] |
| 151 | ); |
| 152 | $options = []; |
| 153 | foreach ( $achievements as $achievement ) { |
| 154 | $options[] = [ |
| 155 | 'label' => $achievement->post_title, |
| 156 | 'value' => (string) $achievement->ID, |
| 157 | ]; |
| 158 | } |
| 159 | |
| 160 | return [ |
| 161 | 'options' => $options, |
| 162 | 'hasMore' => false, |
| 163 | ]; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Search Course. |
| 168 | * |
| 169 | * @param array $data quesry params. |
| 170 | * |
| 171 | * @return array |
| 172 | * @since 1.0.0 |
| 173 | */ |
| 174 | public function search_tutor_course( $data ) { |
| 175 | $courses = get_posts( |
| 176 | [ |
| 177 | 'post_type' => tutor()->course_post_type, |
| 178 | 'post_status' => 'publish', |
| 179 | 'numberposts' => '-1', |
| 180 | ] |
| 181 | ); |
| 182 | $options = []; |
| 183 | foreach ( $courses as $course ) { |
| 184 | $options[] = [ |
| 185 | 'label' => $course->post_title, |
| 186 | 'value' => $course->ID, |
| 187 | ]; |
| 188 | } |
| 189 | |
| 190 | return [ |
| 191 | 'options' => $options, |
| 192 | 'hasMore' => false, |
| 193 | ]; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Search Products. |
| 198 | * |
| 199 | * @param array $data quesry params. |
| 200 | * |
| 201 | * @return array |
| 202 | * @since 1.0.0 |
| 203 | */ |
| 204 | public function search_product( $data ) { |
| 205 | $result = []; |
| 206 | $posts = Utilities::find_posts_by_title( $data ); |
| 207 | |
| 208 | foreach ( $posts['results'] as $post ) { |
| 209 | $result[] = [ |
| 210 | 'label' => $post['post_title'], |
| 211 | 'value' => $post['post_title'], |
| 212 | ]; |
| 213 | } |
| 214 | |
| 215 | return [ |
| 216 | 'options' => $result, |
| 217 | 'hasMore' => $posts['has_more'], |
| 218 | ]; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Search Product Categories. |
| 223 | * |
| 224 | * @param array $data Search Params. |
| 225 | * |
| 226 | * @since 1.0.0 |
| 227 | */ |
| 228 | public function search_product_category( $data ) { |
| 229 | if ( ! empty( $data['dynamic'] ) ) { |
| 230 | $taxonomy = $data['dynamic']; |
| 231 | } else { |
| 232 | $taxonomy = isset( $data['taxonomy'] ) ? $data['taxonomy'] : ''; |
| 233 | } |
| 234 | |
| 235 | $term = $data['term']; |
| 236 | $result = []; |
| 237 | $terms = Utilities::get_terms( $term, $data['page'], $taxonomy ); |
| 238 | foreach ( $terms['result'] as $tax_term ) { |
| 239 | $result[] = [ |
| 240 | 'label' => $tax_term->name, |
| 241 | 'value' => $tax_term->name, |
| 242 | ]; |
| 243 | } |
| 244 | |
| 245 | return [ |
| 246 | 'options' => $result, |
| 247 | 'hasMore' => $terms['has_more'], |
| 248 | ]; |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Search Product Tags. |
| 253 | * |
| 254 | * @param array $data Search Params. |
| 255 | * |
| 256 | * @since 1.0.0 |
| 257 | */ |
| 258 | public function search_product_tags( $data ) { |
| 259 | if ( ! empty( $data['dynamic'] ) ) { |
| 260 | $taxonomy = $data['dynamic']; |
| 261 | } else { |
| 262 | $taxonomy = isset( $data['taxonomy'] ) ? $data['taxonomy'] : ''; |
| 263 | } |
| 264 | |
| 265 | $term = $data['term']; |
| 266 | $result = []; |
| 267 | $terms = Utilities::get_terms( $term, $data['page'], $taxonomy ); |
| 268 | |
| 269 | foreach ( $terms['result'] as $tax_term ) { |
| 270 | $result[] = [ |
| 271 | 'label' => $tax_term->name, |
| 272 | 'value' => $tax_term->name, |
| 273 | ]; |
| 274 | } |
| 275 | |
| 276 | return [ |
| 277 | 'options' => $result, |
| 278 | 'hasMore' => $terms['has_more'], |
| 279 | ]; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Global ajax search. |
| 284 | * Here you need to add the field action name to work. |
| 285 | * |
| 286 | * @param WP_REST_Request $request Request data. |
| 287 | * |
| 288 | * @return WP_REST_Response |
| 289 | * @since 1.0.0 |
| 290 | */ |
| 291 | public function global_search( $request ) { |
| 292 | $post_type = $request->get_param( 'post_type' ); |
| 293 | $dynamic = $request->get_param( 'dynamic' ); |
| 294 | $search_term = $request->get_param( 'term' ); |
| 295 | $identifier = $request->get_param( 'field_identifier' ); |
| 296 | $page = max( 1, $request->get_param( 'page' ) ); |
| 297 | $taxonomy = $request->get_param( 'taxonomy' ) ? $request->get_param( 'taxonomy' ) : []; |
| 298 | |
| 299 | $filter = $request->get_param( 'filter' ) ? json_decode( stripslashes( $request->get_param( 'filter' ) ), true ) : []; |
| 300 | |
| 301 | $data = [ |
| 302 | 'dynamic' => $dynamic, |
| 303 | 'search_term' => $search_term, |
| 304 | 'page' => $page, |
| 305 | 'taxonomy' => $taxonomy, |
| 306 | 'filter' => $filter, |
| 307 | 'post_type' => $post_type, |
| 308 | ]; |
| 309 | $response = [ |
| 310 | 'hasMore' => false, |
| 311 | 'options' => [], |
| 312 | ]; |
| 313 | |
| 314 | $method_name = 'search_' . $identifier; |
| 315 | |
| 316 | if ( method_exists( $this, $method_name ) ) { |
| 317 | $response = $this->{$method_name}( $data ); |
| 318 | } else { |
| 319 | return RestController::error_message( 'Invalid field Identifier param.' ); |
| 320 | } |
| 321 | |
| 322 | return RestController::success_message( $response ); |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Search Taxonomy Terms. |
| 327 | * |
| 328 | * @param array $data Search Params. |
| 329 | * |
| 330 | * @since 1.0.0 |
| 331 | * |
| 332 | * @return array |
| 333 | */ |
| 334 | public function search_term( $data ) { |
| 335 | if ( ! empty( $data['dynamic'] ) ) { |
| 336 | $taxonomy = $data['dynamic']; |
| 337 | } else { |
| 338 | $taxonomy = isset( $data['taxonomy'] ) ? $data['taxonomy'] : ''; |
| 339 | } |
| 340 | |
| 341 | $term = $data['term']; |
| 342 | $result = []; |
| 343 | $terms = Utilities::get_terms( $term, $data['page'], $taxonomy ); |
| 344 | foreach ( $terms['result'] as $tax_term ) { |
| 345 | $result[] = [ |
| 346 | 'label' => $tax_term->name, |
| 347 | 'value' => $tax_term->term_id, |
| 348 | ]; |
| 349 | } |
| 350 | |
| 351 | return [ |
| 352 | 'options' => $result, |
| 353 | 'hasMore' => $terms['has_more'], |
| 354 | ]; |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Search users. |
| 359 | * |
| 360 | * @param array $data Search Params. |
| 361 | * |
| 362 | * @since 1.0.0 |
| 363 | * |
| 364 | * @return array |
| 365 | */ |
| 366 | public function search_user( $data ) { |
| 367 | $result = []; |
| 368 | $page = $data['page']; |
| 369 | $users = Utilities::get_users( $data, $page ); |
| 370 | |
| 371 | if ( is_array( $users['results'] ) ) { |
| 372 | foreach ( $users['results'] as $user ) { |
| 373 | $result[] = [ |
| 374 | 'label' => $user->user_login, |
| 375 | 'value' => $user->ID, |
| 376 | ]; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | return [ |
| 381 | 'options' => $result, |
| 382 | 'hasMore' => $users['has_more'], |
| 383 | ]; |
| 384 | |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Search WPForm fields. |
| 389 | * |
| 390 | * @param array $data Search Params. |
| 391 | * |
| 392 | * @since 1.0.0 |
| 393 | * |
| 394 | * @return array |
| 395 | */ |
| 396 | public function search_pluggable_wpform_fields( $data ) { |
| 397 | $result = []; |
| 398 | $page = $data['page']; |
| 399 | $form_id = absint( $data['dynamic'] ); |
| 400 | $wpform_fields = Utilities::get_wpform_fields( $data['search_term'], $page, $form_id ); |
| 401 | |
| 402 | if ( is_array( $wpform_fields['results'] ) ) { |
| 403 | foreach ( $wpform_fields['results'] as $field ) { |
| 404 | $result[] = [ |
| 405 | 'label' => $field['label'], |
| 406 | 'value' => '{' . $field['id'] . '}', |
| 407 | ]; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | return [ |
| 412 | 'options' => $result, |
| 413 | 'hasMore' => $wpform_fields['has_more'], |
| 414 | ]; |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * Prepare variable products. |
| 419 | * |
| 420 | * @param array $data data. |
| 421 | * |
| 422 | * @return array |
| 423 | */ |
| 424 | public function search_variable_products( $data ) { |
| 425 | $products = Utilities::get_variable_products( $data['search_term'], $data['page'] ); |
| 426 | $options = []; |
| 427 | |
| 428 | foreach ( $products['result'] as $product ) { |
| 429 | $options[] = [ |
| 430 | 'label' => $product->get_title(), |
| 431 | 'value' => (string) $product->get_id(), |
| 432 | ]; |
| 433 | } |
| 434 | |
| 435 | return [ |
| 436 | 'options' => $options, |
| 437 | 'hasMore' => $products['has_more'], |
| 438 | ]; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Prepare variable products. |
| 443 | * |
| 444 | * @param array $data data. |
| 445 | * |
| 446 | * @return array |
| 447 | */ |
| 448 | public function search_product_variations( $data ) { |
| 449 | $variations = Utilities::get_product_variations( $data['dynamic'] ); |
| 450 | $options = []; |
| 451 | |
| 452 | foreach ( $variations['result'] as $product ) { |
| 453 | $options[] = [ |
| 454 | 'label' => ! empty( $product->post_excerpt ) ? $product->post_excerpt : $product->post_title, |
| 455 | 'value' => (string) $product->ID, |
| 456 | ]; |
| 457 | } |
| 458 | |
| 459 | return [ |
| 460 | 'options' => $options, |
| 461 | 'hasMore' => $variations['has_more'], |
| 462 | ]; |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * Search WooCommerce Subscriptions. |
| 467 | * |
| 468 | * @param array $data Search Params. |
| 469 | * |
| 470 | * @since 1.0.0 |
| 471 | * |
| 472 | * @return array |
| 473 | */ |
| 474 | public function search_subscription_variation( $data ) { |
| 475 | $subscription_products = Utilities::get_subscription_variation( $data['search_term'], $data['page'] ); |
| 476 | $result = []; |
| 477 | |
| 478 | if ( ! function_exists( 'wc_get_products' ) ) { |
| 479 | return $result; |
| 480 | } |
| 481 | |
| 482 | foreach ( $subscription_products['result'] as $post ) { |
| 483 | if ( $data['search_term'] ) { |
| 484 | if ( false !== stripos( $post->get_title(), $data['search_term'] ) ) { |
| 485 | $result[] = [ |
| 486 | 'label' => $post->get_title(), |
| 487 | 'value' => (string) $post->get_id(), |
| 488 | ]; |
| 489 | } |
| 490 | } else { |
| 491 | $result[] = [ |
| 492 | 'label' => $post->get_title(), |
| 493 | 'value' => (string) $post->get_id(), |
| 494 | ]; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | return [ |
| 499 | 'options' => $result, |
| 500 | 'hasMore' => $subscription_products['has_more'], |
| 501 | ]; |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * Prepare WooCommerce Payment Methods. |
| 506 | * |
| 507 | * @param array $data Search Params. |
| 508 | * @return array[] |
| 509 | */ |
| 510 | public function search_woo_payment_methods( $data ) { |
| 511 | $payment_methods = WC()->payment_gateways->get_available_payment_gateways(); |
| 512 | $options = []; |
| 513 | |
| 514 | if ( ! empty( $payment_methods ) ) { |
| 515 | foreach ( $payment_methods as $payment ) { |
| 516 | $options[] = [ |
| 517 | 'label' => $payment->title, |
| 518 | 'value' => $payment->id, |
| 519 | ]; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | return [ |
| 524 | 'options' => $options, |
| 525 | 'hasMore' => false, |
| 526 | ]; |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * Prepare WooCommerce Order Status List. |
| 531 | * |
| 532 | * @param array $data Search Params. |
| 533 | * @return array[] |
| 534 | */ |
| 535 | public function search_woo_order_status_list( $data ) { |
| 536 | $order_status = wc_get_order_statuses(); |
| 537 | $options = []; |
| 538 | |
| 539 | if ( ! empty( $order_status ) ) { |
| 540 | foreach ( $order_status as $key => $status ) { |
| 541 | $options[] = [ |
| 542 | 'label' => $status, |
| 543 | 'value' => $key, |
| 544 | ]; |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | return [ |
| 549 | 'options' => $options, |
| 550 | 'hasMore' => false, |
| 551 | ]; |
| 552 | } |
| 553 | |
| 554 | /** |
| 555 | * Prepare WooCommerce Country List. |
| 556 | * |
| 557 | * @param array $data Search Params. |
| 558 | * @return array[] |
| 559 | */ |
| 560 | public function search_woo_country_list( $data ) { |
| 561 | $countries = WC()->countries->get_countries(); |
| 562 | $options = []; |
| 563 | |
| 564 | if ( ! empty( $countries ) ) { |
| 565 | foreach ( $countries as $key => $country ) { |
| 566 | $options[] = [ |
| 567 | 'label' => $country, |
| 568 | 'value' => $key, |
| 569 | ]; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | return [ |
| 574 | 'options' => $options, |
| 575 | 'hasMore' => false, |
| 576 | ]; |
| 577 | } |
| 578 | |
| 579 | /** |
| 580 | * Prepare WooCommerce Country States List. |
| 581 | * |
| 582 | * @param array $data Search Params. |
| 583 | * @return array[] |
| 584 | */ |
| 585 | public function search_woo_country_state_list( $data ) { |
| 586 | if ( ! empty( $data['dynamic']['shipping_country'] ) ) { |
| 587 | $cc = $data['dynamic']['shipping_country']; |
| 588 | } else { |
| 589 | $cc = $data['dynamic']; |
| 590 | } |
| 591 | |
| 592 | $states = WC()->countries->get_states( $cc ); |
| 593 | |
| 594 | $options = []; |
| 595 | if ( ! empty( $states ) ) { |
| 596 | foreach ( $states as $key => $state ) { |
| 597 | $options[] = [ |
| 598 | 'label' => $state, |
| 599 | 'value' => $key, |
| 600 | ]; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | return [ |
| 605 | 'options' => $options, |
| 606 | 'hasMore' => false, |
| 607 | ]; |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * Get Memberpress gatways (payment methods) for subscription. |
| 612 | * |
| 613 | * @param array $data QueryParams. |
| 614 | * |
| 615 | * @return array |
| 616 | * @since 1.0.0 |
| 617 | */ |
| 618 | public function search_memberpress_gayways( $data ) { |
| 619 | $mp_options = MeprOptions::fetch(); |
| 620 | |
| 621 | $pms = array_keys( $mp_options->integrations ); |
| 622 | $gateways = []; |
| 623 | |
| 624 | foreach ( $pms as $pm_id ) { |
| 625 | $obj = $mp_options->payment_method( $pm_id ); |
| 626 | if ( $obj instanceof MeprBaseRealGateway ) { |
| 627 | $gateways[] = [ |
| 628 | 'label' => sprintf( '%1$s (%2$s)', $obj->label, $obj->name ), |
| 629 | 'value' => $obj->id, |
| 630 | ]; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | return [ |
| 635 | 'options' => $gateways, |
| 636 | 'hasMore' => false, |
| 637 | ]; |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * Prepare roles. |
| 642 | * |
| 643 | * @param array $data data. |
| 644 | * |
| 645 | * @return array |
| 646 | */ |
| 647 | public function search_roles( $data ) { |
| 648 | if ( function_exists( 'get_editable_roles' ) ) { |
| 649 | $roles = get_editable_roles(); |
| 650 | } else { |
| 651 | $roles = wp_roles()->roles; |
| 652 | $roles = apply_filters( 'editable_roles', $roles ); |
| 653 | } |
| 654 | |
| 655 | $options = []; |
| 656 | foreach ( $roles as $role => $details ) { |
| 657 | |
| 658 | $options[] = [ |
| 659 | 'label' => $details['name'], |
| 660 | 'value' => $role, |
| 661 | ]; |
| 662 | |
| 663 | } |
| 664 | |
| 665 | return [ |
| 666 | 'options' => $options, |
| 667 | 'hasMore' => false, |
| 668 | ]; |
| 669 | } |
| 670 | |
| 671 | /** |
| 672 | * Fetch operators. |
| 673 | * |
| 674 | * @return array |
| 675 | */ |
| 676 | public function search_condition_operators() { |
| 677 | return [ |
| 678 | 'options' => EventHelperController::get_instance()->prepare_operators(), |
| 679 | 'hasMore' => false, |
| 680 | ]; |
| 681 | } |
| 682 | |
| 683 | /** |
| 684 | * Prepare post types. |
| 685 | * |
| 686 | * @param array $data data. |
| 687 | * |
| 688 | * @return array |
| 689 | */ |
| 690 | public function search_post_types( $data ) { |
| 691 | $post_types = get_post_types( [ 'public' => true ], 'object' ); |
| 692 | $post_types = apply_filters( 'suretriggers_post_types', $post_types ); |
| 693 | if ( isset( $post_types['attachment'] ) ) { |
| 694 | unset( $post_types['attachment'] ); |
| 695 | } |
| 696 | |
| 697 | $options = []; |
| 698 | foreach ( $post_types as $post_type => $details ) { |
| 699 | $options[] = [ |
| 700 | 'label' => $details->label, |
| 701 | 'value' => $post_type, |
| 702 | ]; |
| 703 | } |
| 704 | |
| 705 | return [ |
| 706 | 'options' => $options, |
| 707 | 'hasMore' => false, |
| 708 | ]; |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * Get post statuses. |
| 713 | * |
| 714 | * @param array $data data. |
| 715 | * |
| 716 | * @return array |
| 717 | */ |
| 718 | public function search_post_statuses( $data ) { |
| 719 | $post_statuses = get_post_stati( [], 'objects' ); |
| 720 | $post_statuses = apply_filters( 'suretriggers_post_types', $post_statuses ); |
| 721 | $options = []; |
| 722 | |
| 723 | foreach ( $post_statuses as $post_status => $details ) { |
| 724 | if ( 'woocommerce' === $details->label_count['domain'] ) { |
| 725 | $options[] = [ |
| 726 | 'label' => 'WooCommerce - ' . $details->label, |
| 727 | 'value' => $post_status, |
| 728 | ]; |
| 729 | } else { |
| 730 | $options[] = [ |
| 731 | 'label' => $details->label, |
| 732 | 'value' => $post_status, |
| 733 | ]; |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | return [ |
| 738 | 'options' => $options, |
| 739 | 'hasMore' => false, |
| 740 | ]; |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * Get Taxonomies. |
| 745 | * |
| 746 | * @param array $data data. |
| 747 | * |
| 748 | * @return array |
| 749 | */ |
| 750 | public function search_taxonomy_list( $data ) { |
| 751 | $taxonomies = get_taxonomies( [ 'public' => true ], 'objects' ); |
| 752 | $options = []; |
| 753 | $options[0] = [ |
| 754 | 'label' => 'Any Taxonomy', |
| 755 | 'value' => -1, |
| 756 | ]; |
| 757 | |
| 758 | foreach ( $taxonomies as $taxonomy => $taxonomy_obj ) { |
| 759 | $options[] = [ |
| 760 | 'label' => $taxonomy_obj->label, |
| 761 | 'value' => $taxonomy_obj->name, |
| 762 | ]; |
| 763 | } |
| 764 | |
| 765 | return [ |
| 766 | 'options' => $options, |
| 767 | 'hasMore' => false, |
| 768 | ]; |
| 769 | } |
| 770 | |
| 771 | /** |
| 772 | * Get WPForms. |
| 773 | * |
| 774 | * @param array $data data. |
| 775 | * |
| 776 | * @return array |
| 777 | */ |
| 778 | public function search_wp_forms( $data ) { |
| 779 | if ( ! class_exists( 'WPForms_Form_Handler' ) ) { |
| 780 | return; |
| 781 | } |
| 782 | |
| 783 | $wpforms = new WPForms_Form_Handler(); |
| 784 | $forms = $wpforms->get( '', [ 'orderby' => 'title' ] ); |
| 785 | $options = []; |
| 786 | |
| 787 | if ( ! empty( $forms ) ) { |
| 788 | foreach ( $forms as $form ) { |
| 789 | $options[] = [ |
| 790 | 'label' => $form->post_title, |
| 791 | 'value' => $form->ID, |
| 792 | ]; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | return [ |
| 797 | 'options' => $options, |
| 798 | 'hasMore' => false, |
| 799 | ]; |
| 800 | } |
| 801 | |
| 802 | /** |
| 803 | * Get Gravity Forms. |
| 804 | * |
| 805 | * @param array $data data. |
| 806 | * |
| 807 | * @return array |
| 808 | */ |
| 809 | public function search_gravity_forms( $data ) { |
| 810 | if ( ! class_exists( 'GFFormsModel' ) ) { |
| 811 | return; |
| 812 | } |
| 813 | |
| 814 | $forms = GFFormsModel::get_forms(); |
| 815 | $options = []; |
| 816 | |
| 817 | if ( ! empty( $forms ) ) { |
| 818 | foreach ( $forms as $form ) { |
| 819 | $options[] = [ |
| 820 | 'label' => $form->title, |
| 821 | 'value' => $form->id, |
| 822 | ]; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | return [ |
| 827 | 'options' => $options, |
| 828 | 'hasMore' => false, |
| 829 | ]; |
| 830 | } |
| 831 | |
| 832 | /** |
| 833 | * Get tag & contact details. |
| 834 | * |
| 835 | * @param array $data data. |
| 836 | * |
| 837 | * @return array |
| 838 | */ |
| 839 | public function search_pluggables_fluentcrm_contact_added_to_tags( $data ) { |
| 840 | $context = []; |
| 841 | $pluggable_data = []; |
| 842 | $tag_id = $data['filter']; |
| 843 | |
| 844 | if ( $tag_id > 0 ) { |
| 845 | $tags = Tag::where( 'id', $tag_id )->first(); |
| 846 | } else { |
| 847 | $tags = Tag::orderBy( 'id', 'DESC' )->first(); |
| 848 | } |
| 849 | $contact = Subscriber::orderBy( 'id', 'DESC' )->first(); |
| 850 | if ( $contact ) { |
| 851 | $pluggable_data['contact'] = $contact; |
| 852 | $context['tag_id'] = $tag_id; |
| 853 | $pluggable_data['tag'] = $tags; |
| 854 | $context['response_type'] = 'live'; |
| 855 | } else { |
| 856 | $pluggable_data['conatct']['full_name'] = 'Test User'; |
| 857 | $pluggable_data['conatct']['first_name'] = 'Test'; |
| 858 | $pluggable_data['conatct']['last_name'] = 'User'; |
| 859 | $pluggable_data['conatct']['company_id'] = 112; |
| 860 | $pluggable_data['conatct']['email'] = 'testuser@gmail.com'; |
| 861 | $pluggable_data['conatct']['address_line_1'] = '33, Vincent Road'; |
| 862 | $pluggable_data['conatct']['address_line_2'] = 'Chicago Street'; |
| 863 | $pluggable_data['conatct']['postal_code'] = '212342'; |
| 864 | $pluggable_data['conatct']['city'] = 'New York City'; |
| 865 | $pluggable_data['conatct']['state'] = 'New York'; |
| 866 | $pluggable_data['conatct']['country'] = 'USA'; |
| 867 | $pluggable_data['conatct']['phone'] = '9992191911'; |
| 868 | $pluggable_data['conatct']['status'] = 'subscribed'; |
| 869 | $pluggable_data['conatct']['contact_type'] = 'lead'; |
| 870 | $pluggable_data['conatct']['source'] = ''; |
| 871 | $pluggable_data['conatct']['date_of_birth'] = '2022-11-09'; |
| 872 | $context['tag_id'] = 1; |
| 873 | $pluggable_data['tag'] = |
| 874 | [ |
| 875 | 'id' => '1', |
| 876 | 'title' => 'new', |
| 877 | 'slug' => 'new', |
| 878 | 'description' => null, |
| 879 | 'created_at' => '2023-01-19 10:23:23', |
| 880 | 'updated_at' => '2023-01-19 10:23:23', |
| 881 | 'pivot' => [ |
| 882 | 'subscriber_id' => '1', |
| 883 | 'object_id' => '1', |
| 884 | 'object_type' => 'FluentCrm\\App\\Models\\Tag', |
| 885 | 'created_at' => '2023-01-19 10:42:55', |
| 886 | 'updated_at' => '2023-01-19 10:42:55', |
| 887 | |
| 888 | ], |
| 889 | ]; |
| 890 | $context['response_type'] = 'sample'; |
| 891 | } |
| 892 | |
| 893 | $context['pluggable_data'] = $pluggable_data; |
| 894 | return $context; |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * Get Divi Forms. |
| 899 | * |
| 900 | * @param array $data data. |
| 901 | * |
| 902 | * @return array |
| 903 | */ |
| 904 | public function search_divi_forms( $data ) { |
| 905 | $form_posts = Utilities::get_divi_forms(); |
| 906 | $options = []; |
| 907 | |
| 908 | if ( empty( $form_posts ) ) { |
| 909 | return [ |
| 910 | 'options' => [], |
| 911 | 'hasMore' => false, |
| 912 | ]; |
| 913 | } |
| 914 | |
| 915 | foreach ( $form_posts as $form_post ) { |
| 916 | $pattern_regex = '/\[et_pb_contact_form(.*?)](.+?)\[\/et_pb_contact_form]/'; |
| 917 | preg_match_all( $pattern_regex, $form_post['post_content'], $forms, PREG_SET_ORDER ); |
| 918 | if ( empty( $forms ) ) { |
| 919 | continue; |
| 920 | } |
| 921 | |
| 922 | $count = 0; |
| 923 | |
| 924 | foreach ( $forms as $form ) { |
| 925 | $pattern_form = get_shortcode_regex( [ 'et_pb_contact_form' ] ); |
| 926 | preg_match_all( "/$pattern_form/", $form[0], $forms_extracted, PREG_SET_ORDER ); |
| 927 | |
| 928 | if ( empty( $forms_extracted ) ) { |
| 929 | continue; |
| 930 | } |
| 931 | |
| 932 | foreach ( $forms_extracted as $form_extracted ) { |
| 933 | $form_attrs = shortcode_parse_atts( $form_extracted[3] ); |
| 934 | $form_id = isset( $form_attrs['_unique_id'] ) ? $form_attrs['_unique_id'] : ''; |
| 935 | if ( empty( $form_id ) ) { |
| 936 | continue; |
| 937 | } |
| 938 | $form_id = sprintf( '%d-%s', $form_post['ID'], $form_id ); |
| 939 | $form_title = isset( $form_attrs['title'] ) ? $form_attrs['title'] : ''; |
| 940 | $form_title = sprintf( '%s %s', $form_post['post_title'], $form_title ); |
| 941 | $options[] = [ |
| 942 | 'label' => $form_title, |
| 943 | 'value' => $form_id, |
| 944 | ]; |
| 945 | } |
| 946 | $count++; |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | return [ |
| 951 | 'options' => $options, |
| 952 | 'hasMore' => false, |
| 953 | ]; |
| 954 | } |
| 955 | |
| 956 | /** |
| 957 | * Get Comment Pluggable data. |
| 958 | * |
| 959 | * @param array $data data. |
| 960 | * |
| 961 | * @return array |
| 962 | */ |
| 963 | public function search_pluggables_wp_insert_comment( $data ) { |
| 964 | $context = []; |
| 965 | $post_data = []; |
| 966 | $args = [ |
| 967 | 'number' => '1', |
| 968 | 'status' => 'approve', |
| 969 | ]; |
| 970 | |
| 971 | if ( isset( $data['filter']['post']['value'] ) ) { |
| 972 | $post_id = $data['filter']['post']['value']; |
| 973 | if ( $post_id > 0 ) { |
| 974 | $args['post_id'] = $post_id; |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | $comments = get_comments( $args ); |
| 979 | if ( empty( $comments ) ) { |
| 980 | unset( $args['post_id'] ); |
| 981 | $comments = get_comments( $args ); |
| 982 | } |
| 983 | $context['context_data'] = $data; |
| 984 | $context['context_args'] = $args; |
| 985 | if ( ! empty( $comments ) ) { |
| 986 | foreach ( $comments as $comment ) : |
| 987 | if ( is_object( $comment ) ) { |
| 988 | $comment = get_object_vars( $comment ); |
| 989 | } |
| 990 | $post = get_post( absint( $comment['comment_post_ID'] ) ); |
| 991 | $user_email = $comment['comment_author_email']; |
| 992 | $user = get_user_by( 'email', $user_email ); |
| 993 | if ( is_object( $post ) ) { |
| 994 | if ( property_exists( $post, 'ID' ) || property_exists( $post, 'post_author' ) || property_exists( $post, 'post_title' ) ) { |
| 995 | $post_id = $post->ID; |
| 996 | $postauthor = (int) $post->post_author; |
| 997 | $context['pluggable_data'] = [ |
| 998 | 'post' => $post_id, |
| 999 | 'post_title' => $post->post_title, |
| 1000 | 'post_author' => get_the_author_meta( 'display_name', $postauthor ), |
| 1001 | 'post_link' => get_the_permalink( $post_id ), |
| 1002 | 'comment_id' => $comment['comment_ID'], |
| 1003 | 'comment' => $comment['comment_content'], |
| 1004 | 'comment_author' => $comment['comment_author'], |
| 1005 | 'comment_author_email' => $comment['comment_author_email'], |
| 1006 | 'comment_date' => $comment['comment_date'], |
| 1007 | ]; |
| 1008 | } |
| 1009 | } |
| 1010 | if ( $user ) { |
| 1011 | $context['pluggable_data']['wp_user_id'] = $user->ID; |
| 1012 | $context['pluggable_data']['user_login'] = $user->user_login; |
| 1013 | $context['pluggable_data']['display_name'] = $user->display_name; |
| 1014 | $context['pluggable_data']['user_firstname'] = $user->user_firstname; |
| 1015 | $context['pluggable_data']['user_lastname'] = $user->user_lastname; |
| 1016 | $context['pluggable_data']['user_email'] = $user->user_email; |
| 1017 | $context['pluggable_data']['user_role'] = $user->roles; |
| 1018 | } |
| 1019 | |
| 1020 | $context['response_type'] = 'live'; |
| 1021 | endforeach; |
| 1022 | } else { |
| 1023 | $sample_comment = [ |
| 1024 | 'post' => 100, |
| 1025 | 'post_title' => 'Sample Post', |
| 1026 | 'comment_id' => 101, |
| 1027 | 'comment' => 'Sample Comment', |
| 1028 | ]; |
| 1029 | $sample_comment['wp_user_id'] = 7; |
| 1030 | $sample_comment['user_login'] = 'testuser@gmail.com'; |
| 1031 | $sample_comment['display_name'] = 'Test User'; |
| 1032 | $sample_comment['user_firstname'] = 'Test'; |
| 1033 | $sample_comment['user_lastname'] = 'User'; |
| 1034 | $sample_comment['user_email'] = 'testuser@gmail.com'; |
| 1035 | $sample_comment['user_role'] = [ 'Subscriber' ]; |
| 1036 | |
| 1037 | $context['pluggable_data'] = $sample_comment; |
| 1038 | $context['response_type'] = 'sample'; |
| 1039 | } |
| 1040 | return $context; |
| 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * User reset password. |
| 1045 | * |
| 1046 | * @param array $data data. |
| 1047 | * @return array |
| 1048 | */ |
| 1049 | public function search_pluggables_user_reset_password( $data ) { |
| 1050 | $user_context = $this->search_pluggables_add_user_role( $data ); |
| 1051 | $user_context['pluggable_data']['new_password'] = '***password***'; |
| 1052 | return $user_context; |
| 1053 | } |
| 1054 | |
| 1055 | /** |
| 1056 | * User pluggable data. |
| 1057 | * |
| 1058 | * @param array $data data. |
| 1059 | * @return array |
| 1060 | */ |
| 1061 | public function search_pluggables_add_user_role( $data ) { |
| 1062 | $context = []; |
| 1063 | $args = [ |
| 1064 | 'order' => 'DESC', |
| 1065 | 'number' => 1, |
| 1066 | 'orderby' => 'ID', |
| 1067 | ]; |
| 1068 | |
| 1069 | if ( isset( $data['filter']['role']['value'] ) ) { |
| 1070 | $role = $data['filter']['role']['value']; |
| 1071 | $args['role'] = $role; |
| 1072 | } |
| 1073 | if ( isset( $data['filter']['new_role']['value'] ) ) { |
| 1074 | $role = $data['filter']['new_role']['value']; |
| 1075 | $args['role'] = $role; |
| 1076 | } |
| 1077 | |
| 1078 | $users = get_users( $args ); |
| 1079 | |
| 1080 | if ( isset( $data['filter']['meta_key']['value'] ) ) { |
| 1081 | $meta_key = $data['filter']['meta_key']['value']; |
| 1082 | $args['st_meta_key'] = $meta_key; |
| 1083 | } |
| 1084 | |
| 1085 | if ( isset( $data['filter']['profile_field']['value'] ) ) { |
| 1086 | $meta_key = $data['filter']['profile_field']['value']; |
| 1087 | $args['profile_field'] = $meta_key; |
| 1088 | } |
| 1089 | |
| 1090 | if ( ! empty( $users ) ) { |
| 1091 | $user = $users[0]; |
| 1092 | $pluggable_data = []; |
| 1093 | $pluggable_data['wp_user_id'] = $user->ID; |
| 1094 | $pluggable_data['user_login'] = $user->user_login; |
| 1095 | $pluggable_data['display_name'] = $user->display_name; |
| 1096 | $pluggable_data['user_firstname'] = $user->user_firstname; |
| 1097 | $pluggable_data['user_lastname'] = $user->user_lastname; |
| 1098 | $pluggable_data['user_email'] = $user->user_email; |
| 1099 | $pluggable_data['user_role'] = $user->roles; |
| 1100 | |
| 1101 | if ( isset( $args['st_meta_key'] ) ) { |
| 1102 | $pluggable_data['meta_key'] = $args['st_meta_key']; |
| 1103 | $pluggable_data['meta_value'] = get_user_meta( $user->ID, $args['st_meta_key'], true ); |
| 1104 | } |
| 1105 | if ( isset( $args['profile_field'] ) ) { |
| 1106 | $userdata = get_userdata( $user->ID ); |
| 1107 | $userdata = json_decode( wp_json_encode( $userdata->data ), true ); |
| 1108 | |
| 1109 | $pluggable_data['profile_field'] = $args['profile_field']; |
| 1110 | $pluggable_data['profile_field_value'] = $userdata[ $args['profile_field'] ]; |
| 1111 | } |
| 1112 | $context['pluggable_data'] = $pluggable_data; |
| 1113 | $context['response_type'] = 'live'; |
| 1114 | } else { |
| 1115 | $role = isset( $args['role'] ) ? $args['role'] : 'subscriber'; |
| 1116 | $context['pluggable_data'] = [ |
| 1117 | 'wp_user_id' => 1, |
| 1118 | 'user_login' => 'admin', |
| 1119 | 'display_name' => 'Test User', |
| 1120 | 'user_firstname' => 'Test', |
| 1121 | 'user_lastname' => 'User', |
| 1122 | 'user_email' => 'testuser@gmail.com', |
| 1123 | 'user_role' => [ $role ], |
| 1124 | ]; |
| 1125 | if ( isset( $args['st_meta_key'] ) ) { |
| 1126 | $context['pluggable_data']['meta_key'] = $args['st_meta_key']; |
| 1127 | $context['pluggable_data']['meta_value'] = 'test meta value'; |
| 1128 | } |
| 1129 | if ( isset( $args['profile_field'] ) ) { |
| 1130 | $context['pluggable_data']['profile_field'] = $args['profile_field']; |
| 1131 | $context['pluggable_data']['profile_field_value'] = 'Profile Field Value'; |
| 1132 | } |
| 1133 | $context['response_type'] = 'sample'; |
| 1134 | } |
| 1135 | return $context; |
| 1136 | } |
| 1137 | |
| 1138 | /** |
| 1139 | * User pluggable data. |
| 1140 | * |
| 1141 | * @param array $data data. |
| 1142 | * @return array |
| 1143 | */ |
| 1144 | public function search_pluggables_last_user_login( $data ) { |
| 1145 | $context = []; |
| 1146 | $args = [ |
| 1147 | 'orderby' => 'meta_value', |
| 1148 | 'meta_key' => 'st_last_login', |
| 1149 | 'order' => 'DESC', |
| 1150 | 'number' => 1, |
| 1151 | ]; |
| 1152 | $users = get_users( $args ); |
| 1153 | |
| 1154 | if ( ! empty( $users ) ) { |
| 1155 | $user = $users[0]; |
| 1156 | $pluggable_data = []; |
| 1157 | $pluggable_data['wp_user_id'] = $user->ID; |
| 1158 | $pluggable_data['user_login'] = $user->user_login; |
| 1159 | $pluggable_data['display_name'] = $user->display_name; |
| 1160 | $pluggable_data['user_firstname'] = $user->user_firstname; |
| 1161 | $pluggable_data['user_lastname'] = $user->user_lastname; |
| 1162 | $pluggable_data['user_email'] = $user->user_email; |
| 1163 | $pluggable_data['user_role'] = $user->roles; |
| 1164 | |
| 1165 | $context['pluggable_data'] = $pluggable_data; |
| 1166 | $context['response_type'] = 'live'; |
| 1167 | } else { |
| 1168 | $role = isset( $args['role'] ) ? $args['role'] : 'subscriber'; |
| 1169 | $context['pluggable_data'] = [ |
| 1170 | 'wp_user_id' => 1, |
| 1171 | 'user_login' => 'admin', |
| 1172 | 'display_name' => 'Test User', |
| 1173 | 'user_firstname' => 'Test', |
| 1174 | 'user_lastname' => 'User', |
| 1175 | 'user_email' => 'testuser@gmail.com', |
| 1176 | 'user_role' => [ $role ], |
| 1177 | ]; |
| 1178 | $context['response_type'] = 'sample'; |
| 1179 | } |
| 1180 | return $context; |
| 1181 | } |
| 1182 | |
| 1183 | /** |
| 1184 | * Donation pluggable data. |
| 1185 | * |
| 1186 | * @param array $data data. |
| 1187 | * @return array |
| 1188 | */ |
| 1189 | public function search_pluggables_wordpress_post( $data ) { |
| 1190 | $context = []; |
| 1191 | $args = [ |
| 1192 | 'post_type' => 'any', |
| 1193 | 'posts_per_page' => 1, |
| 1194 | 'orderby' => 'modified', |
| 1195 | 'order' => 'DESC', |
| 1196 | ]; |
| 1197 | |
| 1198 | if ( isset( $data['filter']['post_type']['value'] ) ) { |
| 1199 | $post_type = $data['filter']['post_type']['value']; |
| 1200 | $args['post_type'] = $post_type; |
| 1201 | } |
| 1202 | |
| 1203 | if ( isset( $data['filter']['status']['value'] ) ) { |
| 1204 | $post_status = $data['filter']['status']['value']; |
| 1205 | $args['post_status'] = $post_status; |
| 1206 | } |
| 1207 | |
| 1208 | if ( isset( $data['filter']['post_status']['value'] ) ) { |
| 1209 | $post_status = $data['filter']['post_status']['value']; |
| 1210 | $args['post_status'] = $post_status; |
| 1211 | } |
| 1212 | |
| 1213 | if ( isset( $data['filter']['post']['value'] ) ) { |
| 1214 | $post_id = $data['filter']['post']['value']; |
| 1215 | if ( $post_id > 0 ) { |
| 1216 | $args['p'] = $post_id; |
| 1217 | unset( $args['post_status'] ); |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | $posts = get_posts( $args ); |
| 1222 | if ( ! empty( $posts ) ) { |
| 1223 | $context['pluggable_data'] = $posts[0]; |
| 1224 | if ( property_exists( $context['pluggable_data'], 'post' ) ) { |
| 1225 | $context['pluggable_data']->post = $posts[0]->ID; |
| 1226 | } |
| 1227 | $context['response_type'] = 'live'; |
| 1228 | } else { |
| 1229 | $context['pluggable_data'] = [ |
| 1230 | 'ID' => 557, |
| 1231 | 'post' => 557, |
| 1232 | 'post_author' => 1, |
| 1233 | 'post_date' => '2022-11-18 12:18:14', |
| 1234 | 'post_date_gmt' => '2022-11-18 12:18:14', |
| 1235 | 'post_content' => 'Test Post Content', |
| 1236 | 'post_title' => 'Test Post', |
| 1237 | 'post_excerpt' => '', |
| 1238 | 'post_status' => $args['post_status'], |
| 1239 | 'comment_status' => 'open', |
| 1240 | 'ping_status' => 'open', |
| 1241 | 'post_password' => '', |
| 1242 | 'post_name' => 'test-post', |
| 1243 | 'to_ping' => '', |
| 1244 | 'pinged' => '', |
| 1245 | 'post_modified' => '2022-11-18 12:18:14', |
| 1246 | 'post_modified_gmt' => '2022-11-18 12:18:14', |
| 1247 | 'post_content_filtered' => '', |
| 1248 | 'post_parent' => 0, |
| 1249 | 'guid' => 'https://abc.com/test-post/', |
| 1250 | 'menu_order' => 0, |
| 1251 | 'post_type' => 'post', |
| 1252 | 'post_mime_type' => '', |
| 1253 | 'comment_count' => 0, |
| 1254 | 'filter' => 'raw', |
| 1255 | ]; |
| 1256 | $context['response_type'] = 'sample'; |
| 1257 | } |
| 1258 | |
| 1259 | return $context; |
| 1260 | } |
| 1261 | |
| 1262 | /** |
| 1263 | * Donation pluggable data |
| 1264 | * |
| 1265 | * @param array $data data. |
| 1266 | * @return array |
| 1267 | */ |
| 1268 | public function search_pluggables_givewp_donation_via_form( $data ) { |
| 1269 | global $wpdb; |
| 1270 | $context = []; |
| 1271 | $pluggable_data = []; |
| 1272 | |
| 1273 | $payment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type=%s ORDER BY id DESC LIMIT 1", 'give_payment' ) ); |
| 1274 | |
| 1275 | if ( ! empty( $payment ) ) { |
| 1276 | $payment = new Give_Payment( $payment->ID ); |
| 1277 | $address_data = $payment->address; |
| 1278 | |
| 1279 | $pluggable_data['first_name'] = $payment->first_name; |
| 1280 | $pluggable_data['last_name'] = $payment->last_name; |
| 1281 | $pluggable_data['email'] = $payment->email; |
| 1282 | $pluggable_data['currency'] = $payment->currency; |
| 1283 | $pluggable_data['donated_amount'] = $payment->subtotal; |
| 1284 | $pluggable_data['donation_amount'] = $payment->subtotal; |
| 1285 | $pluggable_data['form_id'] = (int) $payment->form_id; |
| 1286 | $pluggable_data['form_title'] = $payment->form_title; |
| 1287 | $pluggable_data['name_title_prefix'] = $payment->title_prefix; |
| 1288 | $pluggable_data['date'] = $payment->date; |
| 1289 | |
| 1290 | if ( is_array( $address_data ) ) { |
| 1291 | $pluggable_data['address_line_1'] = $address_data['line1']; |
| 1292 | $pluggable_data['address_line_2'] = $address_data['line2']; |
| 1293 | $pluggable_data['city'] = $address_data['city']; |
| 1294 | $pluggable_data['state'] = $address_data['state']; |
| 1295 | $pluggable_data['zip'] = $address_data['zip']; |
| 1296 | $pluggable_data['country'] = $address_data['country']; |
| 1297 | } |
| 1298 | $donor_comment = give_get_donor_donation_comment( $payment->ID, $payment->donor_id ); |
| 1299 | $pluggable_data['comment'] = isset( $doner['comment_content'] ) ? $donor_comment : ''; |
| 1300 | $context['response_type'] = 'live'; |
| 1301 | } else { |
| 1302 | $pluggable_data['first_name'] = 'Test'; |
| 1303 | $pluggable_data['last_name'] = 'User'; |
| 1304 | $pluggable_data['email'] = 'testuser@gmail.com'; |
| 1305 | $pluggable_data['currency'] = 'USD'; |
| 1306 | $pluggable_data['donated_amount'] = 100; |
| 1307 | $pluggable_data['donation_amount'] = 100; |
| 1308 | $pluggable_data['form_id'] = 23; |
| 1309 | $pluggable_data['form_title'] = 'Test Donation'; |
| 1310 | $pluggable_data['name_title_prefix'] = 'Mr'; |
| 1311 | $pluggable_data['date'] = '2022-11-07 16:06:05'; |
| 1312 | $pluggable_data['address_line_1'] = '33, Vincent Road'; |
| 1313 | $pluggable_data['address_line_2'] = 'Chicago Street'; |
| 1314 | $pluggable_data['city'] = 'New York City'; |
| 1315 | $pluggable_data['state'] = 'New York'; |
| 1316 | $pluggable_data['zip'] = '223131'; |
| 1317 | $pluggable_data['country'] = 'USA'; |
| 1318 | $pluggable_data['comment'] = 'Test Comment'; |
| 1319 | $context['response_type'] = 'sample'; |
| 1320 | } |
| 1321 | |
| 1322 | $context['pluggable_data'] = $pluggable_data; |
| 1323 | return $context; |
| 1324 | } |
| 1325 | |
| 1326 | /** |
| 1327 | * Search Divi Form fields. |
| 1328 | * |
| 1329 | * @param array $data Search Params. |
| 1330 | * |
| 1331 | * @since 1.0.0 |
| 1332 | * |
| 1333 | * @return array |
| 1334 | */ |
| 1335 | public function search_pluggable_divi_form_fields( $data ) { |
| 1336 | $result = []; |
| 1337 | $form_id = absint( $data['dynamic'] ); |
| 1338 | $form_posts = Utilities::get_divi_forms(); |
| 1339 | |
| 1340 | if ( empty( $form_posts ) ) { |
| 1341 | return [ |
| 1342 | 'options' => [], |
| 1343 | 'hasMore' => false, |
| 1344 | ]; |
| 1345 | } |
| 1346 | $fields = []; |
| 1347 | foreach ( $form_posts as $form_post ) { |
| 1348 | $pattern_regex = '/\[et_pb_contact_form(.*?)](.+?)\[\/et_pb_contact_form]/'; |
| 1349 | preg_match_all( $pattern_regex, $form_post['post_content'], $forms, PREG_SET_ORDER ); |
| 1350 | if ( empty( $forms ) ) { |
| 1351 | continue; |
| 1352 | } |
| 1353 | |
| 1354 | $count = 0; |
| 1355 | |
| 1356 | foreach ( $forms as $form ) { |
| 1357 | $pattern = get_shortcode_regex( [ 'et_pb_contact_field' ] ); |
| 1358 | |
| 1359 | preg_match_all( "/$pattern/", $form[0], $contact_fields, PREG_SET_ORDER ); |
| 1360 | |
| 1361 | if ( empty( $contact_fields ) ) { |
| 1362 | return $fields; |
| 1363 | } |
| 1364 | |
| 1365 | foreach ( $contact_fields as $contact_field ) { |
| 1366 | $contact_field_attrs = shortcode_parse_atts( $contact_field[3] ); |
| 1367 | $field_id = strtolower( self::array_get( $contact_field_attrs, 'field_id' ) ); |
| 1368 | $fields[] = [ |
| 1369 | 'field_title' => self::array_get( $contact_field_attrs, 'field_title', __( 'No title', 'suretriggers' ) ), |
| 1370 | 'field_id' => $field_id, |
| 1371 | ]; |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | if ( ! empty( $fields ) ) { |
| 1377 | foreach ( $fields as $field ) { |
| 1378 | $result[] = [ |
| 1379 | 'label' => $field['field_title'], |
| 1380 | 'value' => '{' . $field['field_id'] . '}', |
| 1381 | ]; |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | return [ |
| 1386 | 'options' => $result, |
| 1387 | 'hasMore' => false, |
| 1388 | ]; |
| 1389 | } |
| 1390 | |
| 1391 | /** |
| 1392 | * Pseudo function copied from Divi |
| 1393 | * |
| 1394 | * @param array $array An array which contains value located at `$address`. |
| 1395 | * @param string|array $address The location of the value within `$array` (dot notation). |
| 1396 | * @param mixed $default Value to return if not found. Default is an empty string. |
| 1397 | * |
| 1398 | * @return mixed The value, if found, otherwise $default. |
| 1399 | */ |
| 1400 | public static function array_get( $array, $address, $default = '' ) { |
| 1401 | $keys = is_array( $address ) ? $address : explode( '.', $address ); |
| 1402 | $value = $array; |
| 1403 | |
| 1404 | foreach ( $keys as $key ) { |
| 1405 | if ( ! empty( $key ) && isset( $key[0] ) && '[' === $key[0] ) { |
| 1406 | $index = substr( $key, 1, -1 ); |
| 1407 | |
| 1408 | if ( is_numeric( $index ) ) { |
| 1409 | $key = (int) $index; |
| 1410 | } |
| 1411 | } |
| 1412 | |
| 1413 | if ( ! isset( $value[ $key ] ) ) { |
| 1414 | return $default; |
| 1415 | } |
| 1416 | |
| 1417 | $value = $value[ $key ]; |
| 1418 | } |
| 1419 | |
| 1420 | return $value; |
| 1421 | } |
| 1422 | |
| 1423 | /** |
| 1424 | * Get UAG Forms. |
| 1425 | * |
| 1426 | * @param array $data data. |
| 1427 | * |
| 1428 | * @return array |
| 1429 | */ |
| 1430 | public function search_spectra_forms( $data ) { |
| 1431 | $form_posts = Utilities::get_uag_forms(); |
| 1432 | |
| 1433 | $options = []; |
| 1434 | if ( empty( $form_posts ) ) { |
| 1435 | return [ |
| 1436 | 'options' => [], |
| 1437 | 'hasMore' => false, |
| 1438 | ]; |
| 1439 | } |
| 1440 | |
| 1441 | foreach ( $form_posts as $form_post ) { |
| 1442 | $blocks = parse_blocks( $form_post['post_content'] ); |
| 1443 | $i = 1; |
| 1444 | foreach ( $blocks as $key => $block ) { |
| 1445 | if ( 'uagb/forms' === $block['blockName'] ) { |
| 1446 | $options[] = [ |
| 1447 | 'label' => $form_post['post_title'] . ' (Form ' . ( $i ) . ')', |
| 1448 | 'value' => $block['attrs']['block_id'], |
| 1449 | ]; |
| 1450 | $i++; |
| 1451 | } elseif ( 'uagb/forms' !== $block['blockName'] && isset( $block['innerBlocks'] ) ) { |
| 1452 | $container_key = self::get_column_by_value( $block['innerBlocks'], 'uagb/container' ); |
| 1453 | if ( isset( $container_key ) && '' !== $container_key ) { |
| 1454 | $options[] = [ |
| 1455 | 'label' => $form_post['post_title'] . ' (Form ' . ( $i ) . ')', |
| 1456 | 'value' => $block['innerBlocks'][ $container_key ]['attrs']['block_id'], |
| 1457 | ]; |
| 1458 | $i++; |
| 1459 | } |
| 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | return [ |
| 1465 | 'options' => $options, |
| 1466 | 'hasMore' => false, |
| 1467 | ]; |
| 1468 | } |
| 1469 | |
| 1470 | /** |
| 1471 | * Check array recursive. |
| 1472 | * |
| 1473 | * @param array $array Array. |
| 1474 | * @param string $value search params. |
| 1475 | * @since 1.0.0 |
| 1476 | * |
| 1477 | * @return array|void |
| 1478 | */ |
| 1479 | public static function get_column_by_value( $array, $value ) { |
| 1480 | |
| 1481 | foreach ( $array as $key => $sub_array ) { |
| 1482 | |
| 1483 | if ( is_array( $sub_array ) ) { |
| 1484 | $result = self::get_column_by_value( $sub_array, $value ); |
| 1485 | if ( null !== $result ) { |
| 1486 | return $key; |
| 1487 | } |
| 1488 | } else { |
| 1489 | return $key; |
| 1490 | } |
| 1491 | } |
| 1492 | return null; |
| 1493 | |
| 1494 | } |
| 1495 | |
| 1496 | |
| 1497 | /** |
| 1498 | * Search UAG Form fields. |
| 1499 | * |
| 1500 | * @param array $data Search Params. |
| 1501 | * |
| 1502 | * @since 1.0.0 |
| 1503 | * |
| 1504 | * @return array |
| 1505 | */ |
| 1506 | public function search_spectraform_fields( $data ) { |
| 1507 | $result = []; |
| 1508 | $form_id = absint( $data['dynamic'] ); |
| 1509 | $form_posts = Utilities::get_uag_forms(); |
| 1510 | |
| 1511 | if ( empty( $form_posts ) ) { |
| 1512 | return [ |
| 1513 | 'options' => [], |
| 1514 | 'hasMore' => false, |
| 1515 | ]; |
| 1516 | } |
| 1517 | |
| 1518 | foreach ( $form_posts as $form_post ) { |
| 1519 | $blocks = parse_blocks( $form_post['post_content'] ); |
| 1520 | |
| 1521 | foreach ( $blocks as $block ) { |
| 1522 | if ( (int) $block['attrs']['block_id'] === $form_id ) { |
| 1523 | $doc = new DOMDocument(); |
| 1524 | $rendered_block = render_block( $block ); |
| 1525 | $doc->loadHTML( $rendered_block ); |
| 1526 | $child_node_list = $doc->getElementsByTagName( 'div' ); |
| 1527 | for ( $i = 0; $i < $child_node_list->length; $i++ ) { |
| 1528 | $temp = $child_node_list->item( $i ); |
| 1529 | if ( $temp && stripos( $temp->getAttribute( 'class' ), 'uagb-forms-input-label' ) !== false ) { |
| 1530 | $nodes[] = $temp; |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | foreach ( $nodes as $node ) { |
| 1535 | $result[] = [ |
| 1536 | 'label' => $node->textContent, //phpcs:ignore |
| 1537 | 'value' => $node->textContent, //phpcs:ignore |
| 1538 | ]; |
| 1539 | } |
| 1540 | } |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | return [ |
| 1545 | 'options' => $result, |
| 1546 | 'hasMore' => false, |
| 1547 | ]; |
| 1548 | } |
| 1549 | |
| 1550 | /** |
| 1551 | * Search forms of MetForms. |
| 1552 | * |
| 1553 | * @param array $data data. |
| 1554 | * @return array |
| 1555 | */ |
| 1556 | public function search_met_forms( $data ) { |
| 1557 | $args = [ |
| 1558 | 'post_type' => 'metform-form', |
| 1559 | 'post_status' => 'publish', |
| 1560 | 'numberposts' => -1, |
| 1561 | ]; |
| 1562 | |
| 1563 | $forms = get_posts( $args ); |
| 1564 | |
| 1565 | $options = []; |
| 1566 | |
| 1567 | if ( ! empty( $forms ) ) { |
| 1568 | foreach ( $forms as $form ) { |
| 1569 | $options[] = [ |
| 1570 | 'label' => $form->post_title, |
| 1571 | 'value' => $form->ID, |
| 1572 | ]; |
| 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | return [ |
| 1577 | 'options' => $options, |
| 1578 | 'hasMore' => false, |
| 1579 | ]; |
| 1580 | } |
| 1581 | |
| 1582 | /** |
| 1583 | * Search forms of Ninja Forms. |
| 1584 | * |
| 1585 | * @param array $data data. |
| 1586 | * @return array |
| 1587 | */ |
| 1588 | public function search_ninja_forms( $data ) { |
| 1589 | $options = []; |
| 1590 | |
| 1591 | if ( function_exists( 'Ninja_Forms' ) ) { |
| 1592 | foreach ( Ninja_Forms()->form()->get_forms() as $form ) { |
| 1593 | $options[] = [ |
| 1594 | 'label' => $form->get_setting( 'title' ), |
| 1595 | 'value' => $form->get_id(), |
| 1596 | ]; |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | return [ |
| 1601 | 'options' => $options, |
| 1602 | 'hasMore' => false, |
| 1603 | ]; |
| 1604 | } |
| 1605 | |
| 1606 | /** |
| 1607 | * Search forms of Pie Forms. |
| 1608 | * |
| 1609 | * @param array $data data. |
| 1610 | * @return array |
| 1611 | */ |
| 1612 | public function search_pie_forms( $data ) { |
| 1613 | global $wpdb; |
| 1614 | $options = []; |
| 1615 | |
| 1616 | if ( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'pf_forms' ) ) ) { |
| 1617 | |
| 1618 | $results = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'pf_forms WHERE post_status = "published"' ); |
| 1619 | |
| 1620 | if ( $results ) { |
| 1621 | foreach ( $results as $result ) { |
| 1622 | $options[] = [ |
| 1623 | 'label' => $result->form_title, |
| 1624 | 'value' => $result->id, |
| 1625 | ]; |
| 1626 | } |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | return [ |
| 1631 | 'options' => $options, |
| 1632 | 'hasMore' => false, |
| 1633 | ]; |
| 1634 | } |
| 1635 | |
| 1636 | /** |
| 1637 | * Get Fluent Forms. |
| 1638 | * |
| 1639 | * @param array $data data. |
| 1640 | * |
| 1641 | * @return array |
| 1642 | */ |
| 1643 | public function search_fluent_forms( $data ) { |
| 1644 | |
| 1645 | if ( ! function_exists( 'wpFluent' ) ) { |
| 1646 | return [ |
| 1647 | 'options' => [], |
| 1648 | 'hasMore' => false, |
| 1649 | ]; |
| 1650 | } |
| 1651 | |
| 1652 | $forms = wpFluent()->table( 'fluentform_forms' ) |
| 1653 | ->select( [ 'id', 'title' ] ) |
| 1654 | ->orderBy( 'id', 'DESC' ) |
| 1655 | ->get(); |
| 1656 | |
| 1657 | $options = []; |
| 1658 | if ( ! empty( $forms ) ) { |
| 1659 | foreach ( $forms as $form ) { |
| 1660 | $options[] = [ |
| 1661 | 'label' => $form->title, |
| 1662 | 'value' => $form->id, |
| 1663 | ]; |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | return [ |
| 1668 | 'options' => $options, |
| 1669 | 'hasMore' => false, |
| 1670 | ]; |
| 1671 | |
| 1672 | } |
| 1673 | |
| 1674 | /** |
| 1675 | * Get Fluent Forms. |
| 1676 | * |
| 1677 | * @param array $data data. |
| 1678 | * |
| 1679 | * @return array |
| 1680 | */ |
| 1681 | public function search_bricks_builder_forms( $data ) { |
| 1682 | $bricks_theme = wp_get_theme( 'bricks' ); |
| 1683 | if ( ! $bricks_theme->exists() ) { |
| 1684 | return [ |
| 1685 | 'options' => [], |
| 1686 | 'hasMore' => false, |
| 1687 | ]; |
| 1688 | } |
| 1689 | |
| 1690 | $args = [ |
| 1691 | 'post_type' => 'bricks_template', |
| 1692 | 'post_status' => 'publish', |
| 1693 | 'posts_per_page' => -1, |
| 1694 | ]; |
| 1695 | |
| 1696 | $templates = get_posts( $args ); |
| 1697 | |
| 1698 | $options = []; |
| 1699 | if ( ! empty( $templates ) ) { |
| 1700 | foreach ( $templates as $template ) { |
| 1701 | $fetch_content = get_post_meta( $template->ID, BRICKS_DB_PAGE_CONTENT, true ); |
| 1702 | if ( is_array( $fetch_content ) ) { |
| 1703 | foreach ( $fetch_content as $content ) { |
| 1704 | if ( 'form' === $content['name'] ) { |
| 1705 | $options[] = [ |
| 1706 | 'label' => $template->post_title . ' - ' . ( isset( $content['label'] ) ? $content['label'] : 'Form' ), |
| 1707 | 'value' => $content['id'], |
| 1708 | ]; |
| 1709 | } |
| 1710 | } |
| 1711 | } |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | return [ |
| 1716 | 'options' => $options, |
| 1717 | 'hasMore' => false, |
| 1718 | ]; |
| 1719 | |
| 1720 | } |
| 1721 | |
| 1722 | /** |
| 1723 | * Bricks builder form fields. |
| 1724 | * |
| 1725 | * @param array $data data. |
| 1726 | * @return array |
| 1727 | */ |
| 1728 | public function search_pluggable_bricks_builder_form_fields( $data ) { |
| 1729 | $result = []; |
| 1730 | $fields = []; |
| 1731 | $form_id_str = $data['dynamic']; |
| 1732 | $ids = explode( '_', $form_id_str ); |
| 1733 | $post_id = $ids[0]; |
| 1734 | $form_id = $ids[1]; |
| 1735 | $fetch_content = get_post_meta( $post_id, BRICKS_DB_PAGE_CONTENT, true ); |
| 1736 | if ( is_array( $fetch_content ) ) { |
| 1737 | foreach ( $fetch_content as $content ) { |
| 1738 | if ( 'form' === $content['name'] && $form_id === $content['id'] ) { |
| 1739 | $fields = $content['settings']['fields']; |
| 1740 | break; |
| 1741 | } |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | if ( ! empty( $fields ) ) { |
| 1746 | foreach ( $fields as $field ) { |
| 1747 | $result[] = [ |
| 1748 | 'label' => $field['label'], |
| 1749 | 'value' => '{' . strtolower( $field['label'] ) . '}', |
| 1750 | ]; |
| 1751 | } |
| 1752 | } |
| 1753 | |
| 1754 | return [ |
| 1755 | 'options' => $result, |
| 1756 | 'hasMore' => false, |
| 1757 | ]; |
| 1758 | } |
| 1759 | |
| 1760 | /** |
| 1761 | * Get fluent form fields |
| 1762 | * |
| 1763 | * @param array $data Data array. |
| 1764 | * |
| 1765 | * @return array |
| 1766 | */ |
| 1767 | public function search_pluggable_fluent_form_fields( $data ) { |
| 1768 | $result = []; |
| 1769 | $form_id = absint( $data['dynamic'] ); |
| 1770 | |
| 1771 | $fluentform_fields = Utilities::get_fluentform_fields( $data['search_term'], -1, $form_id ); |
| 1772 | |
| 1773 | if ( is_array( $fluentform_fields['results'] ) ) { |
| 1774 | foreach ( $fluentform_fields['results'] as $field ) { |
| 1775 | $result[] = [ |
| 1776 | 'label' => $field['text'], |
| 1777 | 'value' => "{{$field['value']}}", |
| 1778 | ]; |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | $result[] = [ |
| 1783 | 'value' => '{form_id}', |
| 1784 | 'label' => 'Form ID', |
| 1785 | ]; |
| 1786 | |
| 1787 | $result[] = [ |
| 1788 | 'value' => '{form_title}', |
| 1789 | 'label' => 'Form Title', |
| 1790 | ]; |
| 1791 | $result[] = [ |
| 1792 | 'value' => '{entry_id}', |
| 1793 | 'label' => 'Entry ID', |
| 1794 | ]; |
| 1795 | |
| 1796 | $result[] = [ |
| 1797 | 'value' => '{entry_source_url}', |
| 1798 | 'label' => 'Entry Source URL', |
| 1799 | ]; |
| 1800 | |
| 1801 | $result[] = [ |
| 1802 | 'value' => '{submission_date}', |
| 1803 | 'label' => 'Submission Date', |
| 1804 | ]; |
| 1805 | |
| 1806 | $result[] = [ |
| 1807 | 'value' => '{user_ip}', |
| 1808 | 'label' => 'User IP', |
| 1809 | ]; |
| 1810 | |
| 1811 | return [ |
| 1812 | 'options' => $result, |
| 1813 | 'hasMore' => false, |
| 1814 | ]; |
| 1815 | } |
| 1816 | |
| 1817 | /** |
| 1818 | * Search Gravity Form fields. |
| 1819 | * |
| 1820 | * @param array $data Search Params. |
| 1821 | * |
| 1822 | * @since 1.0.0 |
| 1823 | */ |
| 1824 | public function search_gform_fields( $data ) { |
| 1825 | if ( ! class_exists( 'RGFormsModel' ) ) { |
| 1826 | return [ |
| 1827 | 'options' => [], |
| 1828 | 'hasMore' => false, |
| 1829 | ]; |
| 1830 | } |
| 1831 | $result = []; |
| 1832 | $page = $data['page']; |
| 1833 | $form_id = absint( $data['dynamic'] ); |
| 1834 | |
| 1835 | $form = RGFormsModel::get_form_meta( $form_id ); |
| 1836 | |
| 1837 | if ( is_array( $form['fields'] ) ) { |
| 1838 | foreach ( $form['fields'] as $field ) { |
| 1839 | if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { |
| 1840 | foreach ( $field['inputs'] as $input ) { |
| 1841 | if ( ! isset( $input['isHidden'] ) || ( isset( $input['isHidden'] ) && ! $input['isHidden'] ) ) { |
| 1842 | $result[] = [ |
| 1843 | 'value' => $input['id'], |
| 1844 | 'label' => GFCommon::get_label( $field, $input['id'] ), |
| 1845 | ]; |
| 1846 | } |
| 1847 | } |
| 1848 | } elseif ( ! rgar( $field, 'displayOnly' ) ) { |
| 1849 | $result[] = [ |
| 1850 | 'value' => $field['id'], |
| 1851 | 'label' => GFCommon::get_label( $field ), |
| 1852 | ]; |
| 1853 | } |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | return [ |
| 1858 | 'options' => $result, |
| 1859 | 'hasMore' => false, |
| 1860 | ]; |
| 1861 | |
| 1862 | } |
| 1863 | |
| 1864 | /** |
| 1865 | * Search Gravity Form fields. |
| 1866 | * |
| 1867 | * @param array $data Search Params. |
| 1868 | * |
| 1869 | * @since 1.0.0 |
| 1870 | */ |
| 1871 | public function search_pluggable_gravity_form_fields( $data ) { |
| 1872 | if ( ! class_exists( 'RGFormsModel' ) ) { |
| 1873 | return [ |
| 1874 | 'options' => [], |
| 1875 | 'hasMore' => false, |
| 1876 | ]; |
| 1877 | } |
| 1878 | $result = []; |
| 1879 | $form_id = absint( $data['dynamic'] ); |
| 1880 | |
| 1881 | $form = RGFormsModel::get_form_meta( $form_id ); |
| 1882 | |
| 1883 | if ( is_array( $form['fields'] ) ) { |
| 1884 | foreach ( $form['fields'] as $field ) { |
| 1885 | if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { |
| 1886 | foreach ( $field['inputs'] as $input ) { |
| 1887 | if ( ! isset( $input['isHidden'] ) || ( isset( $input['isHidden'] ) && ! $input['isHidden'] ) ) { |
| 1888 | $result[] = [ |
| 1889 | 'value' => '{' . $input['id'] . '}', |
| 1890 | 'label' => GFCommon::get_label( $field, $input['id'] ), |
| 1891 | ]; |
| 1892 | } |
| 1893 | } |
| 1894 | } elseif ( ! rgar( $field, 'displayOnly' ) ) { |
| 1895 | $result[] = [ |
| 1896 | 'value' => '{' . $field['id'] . '}', |
| 1897 | 'label' => GFCommon::get_label( $field ), |
| 1898 | ]; |
| 1899 | } |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | $result[] = [ |
| 1904 | 'value' => '{gravity_form}', |
| 1905 | 'label' => 'Form ID', |
| 1906 | ]; |
| 1907 | $result[] = [ |
| 1908 | 'value' => '{form_title}', |
| 1909 | 'label' => 'Form Title', |
| 1910 | ]; |
| 1911 | $result[] = [ |
| 1912 | 'value' => '{entry_id}', |
| 1913 | 'label' => 'Entry ID', |
| 1914 | ]; |
| 1915 | $result[] = [ |
| 1916 | 'value' => '{user_ip}', |
| 1917 | 'label' => 'User IP', |
| 1918 | ]; |
| 1919 | $result[] = [ |
| 1920 | 'value' => '{entry_source_url}', |
| 1921 | 'label' => 'Entry Source URL', |
| 1922 | ]; |
| 1923 | $result[] = [ |
| 1924 | 'value' => '{entry_submission_date}', |
| 1925 | 'label' => 'Entry Submission Date', |
| 1926 | ]; |
| 1927 | |
| 1928 | return [ |
| 1929 | 'options' => $result, |
| 1930 | 'hasMore' => false, |
| 1931 | ]; |
| 1932 | |
| 1933 | } |
| 1934 | |
| 1935 | /** |
| 1936 | * Prepare fluentcrm lists. |
| 1937 | * |
| 1938 | * @param array $data Search Params. |
| 1939 | * |
| 1940 | * @return array[] |
| 1941 | */ |
| 1942 | public function search_fluentcrm_lists( $data ) { |
| 1943 | |
| 1944 | $list_api = FluentCrmApi( 'lists' ); |
| 1945 | $all_lists = $list_api->all(); |
| 1946 | $options = []; |
| 1947 | |
| 1948 | if ( ! empty( $all_lists ) ) { |
| 1949 | foreach ( $all_lists as $list ) { |
| 1950 | $options[] = [ |
| 1951 | 'label' => $list->title, |
| 1952 | 'value' => $list->id, |
| 1953 | ]; |
| 1954 | } |
| 1955 | } |
| 1956 | |
| 1957 | return [ |
| 1958 | 'options' => $options, |
| 1959 | 'hasMore' => false, |
| 1960 | ]; |
| 1961 | } |
| 1962 | |
| 1963 | /** |
| 1964 | * Prepare fluentcrm contact status. |
| 1965 | * |
| 1966 | * @param array $data Search Params. |
| 1967 | * |
| 1968 | * @return array[] |
| 1969 | */ |
| 1970 | public function search_fluentcrm_contact_status( $data ) { |
| 1971 | |
| 1972 | $options = [ |
| 1973 | [ |
| 1974 | 'label' => __( 'Subscribed', 'suretriggers' ), |
| 1975 | 'value' => 'subscribed', |
| 1976 | ], |
| 1977 | [ |
| 1978 | 'label' => __( 'Pending', 'suretriggers' ), |
| 1979 | 'value' => 'pending', |
| 1980 | ], |
| 1981 | [ |
| 1982 | 'label' => __( 'Unsubscribed', 'suretriggers' ), |
| 1983 | 'value' => 'unsubscribed', |
| 1984 | ], |
| 1985 | [ |
| 1986 | 'label' => __( 'Bounced', 'suretriggers' ), |
| 1987 | 'value' => 'bounced', |
| 1988 | ], |
| 1989 | [ |
| 1990 | 'label' => __( 'Complained', 'suretriggers' ), |
| 1991 | 'value' => 'complained', |
| 1992 | ], |
| 1993 | ]; |
| 1994 | |
| 1995 | return [ |
| 1996 | 'options' => $options, |
| 1997 | 'hasMore' => false, |
| 1998 | ]; |
| 1999 | } |
| 2000 | |
| 2001 | /** |
| 2002 | * Prepare fluentcrm contact status. |
| 2003 | * |
| 2004 | * @param array $data Search Params. |
| 2005 | * |
| 2006 | * @return array[] |
| 2007 | */ |
| 2008 | public function search_fluentcrm_fetch_custom_fields( $data ) { |
| 2009 | |
| 2010 | $options = [ |
| 2011 | [ |
| 2012 | 'label' => __( 'Yes', 'suretriggers' ), |
| 2013 | 'value' => 'true', |
| 2014 | ], |
| 2015 | [ |
| 2016 | 'label' => __( 'No', 'suretriggers' ), |
| 2017 | 'value' => 'false', |
| 2018 | ], |
| 2019 | ]; |
| 2020 | |
| 2021 | return [ |
| 2022 | 'options' => $options, |
| 2023 | 'hasMore' => false, |
| 2024 | ]; |
| 2025 | } |
| 2026 | |
| 2027 | /** |
| 2028 | * Prepare fluentcrm tags. |
| 2029 | * |
| 2030 | * @param array $data Search Params. |
| 2031 | * |
| 2032 | * @return array[] |
| 2033 | */ |
| 2034 | public function search_fluentcrm_tags( $data ) { |
| 2035 | |
| 2036 | $tag_api = FluentCrmApi( 'tags' ); |
| 2037 | $all_tags = $tag_api->all(); |
| 2038 | $options = []; |
| 2039 | |
| 2040 | if ( ! empty( $all_tags ) ) { |
| 2041 | foreach ( $all_tags as $tag ) { |
| 2042 | $options[] = [ |
| 2043 | 'label' => $tag->title, |
| 2044 | 'value' => $tag->id, |
| 2045 | ]; |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | return [ |
| 2050 | 'options' => $options, |
| 2051 | 'hasMore' => false, |
| 2052 | ]; |
| 2053 | } |
| 2054 | |
| 2055 | /** |
| 2056 | * Prepare JetpackCRM Contact tags. |
| 2057 | * |
| 2058 | * @param array $data Search Params. |
| 2059 | * |
| 2060 | * @return array |
| 2061 | */ |
| 2062 | public function search_jetpack_crm_contact_tags( $data ) { |
| 2063 | |
| 2064 | if ( ! function_exists( 'zeroBSCRM_getCustomerTags' ) ) { |
| 2065 | return []; |
| 2066 | } |
| 2067 | |
| 2068 | $all_tags = zeroBSCRM_getCustomerTags(); |
| 2069 | $options = []; |
| 2070 | |
| 2071 | if ( ! empty( $all_tags ) ) { |
| 2072 | foreach ( $all_tags as $tag ) { |
| 2073 | $options[] = [ |
| 2074 | 'label' => $tag['name'], |
| 2075 | 'value' => $tag['id'], |
| 2076 | ]; |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | return [ |
| 2081 | 'options' => $options, |
| 2082 | 'hasMore' => false, |
| 2083 | ]; |
| 2084 | } |
| 2085 | |
| 2086 | /** |
| 2087 | * Prepare JetpackCRM Company tags. |
| 2088 | * |
| 2089 | * @param array $data Search Params. |
| 2090 | * |
| 2091 | * @return array |
| 2092 | */ |
| 2093 | public function search_jetpack_crm_company_tags( $data ) { |
| 2094 | |
| 2095 | if ( ! defined( 'ZBS_TYPE_COMPANY' ) ) { |
| 2096 | return []; |
| 2097 | } |
| 2098 | |
| 2099 | global $wpdb; |
| 2100 | $all_tags = $wpdb->get_results( $wpdb->prepare( "SELECT `ID`,`zbstag_name` FROM `{$wpdb->prefix}zbs_tags` WHERE zbstag_objtype = %d", ZBS_TYPE_COMPANY ) ); |
| 2101 | |
| 2102 | $options = []; |
| 2103 | if ( ! empty( $all_tags ) ) { |
| 2104 | foreach ( $all_tags as $tag ) { |
| 2105 | $options[] = [ |
| 2106 | 'label' => $tag->zbstag_name, |
| 2107 | 'value' => $tag->ID, |
| 2108 | ]; |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | return [ |
| 2113 | 'options' => $options, |
| 2114 | 'hasMore' => false, |
| 2115 | ]; |
| 2116 | } |
| 2117 | |
| 2118 | /** |
| 2119 | * Prepare JetpackCRM Companies list. |
| 2120 | * |
| 2121 | * @param array $data Search Params. |
| 2122 | * |
| 2123 | * @return array |
| 2124 | */ |
| 2125 | public function search_jetpack_crm_companies_list( $data ) { |
| 2126 | |
| 2127 | if ( ! function_exists( 'zeroBS_getCompanies' ) ) { |
| 2128 | return []; |
| 2129 | } |
| 2130 | |
| 2131 | $all_companies = zeroBS_getCompanies(); |
| 2132 | $options = []; |
| 2133 | |
| 2134 | if ( ! empty( $all_companies ) ) { |
| 2135 | foreach ( $all_companies as $company ) { |
| 2136 | $options[] = [ |
| 2137 | 'label' => $company['name'], |
| 2138 | 'value' => $company['id'], |
| 2139 | ]; |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | return [ |
| 2144 | 'options' => $options, |
| 2145 | 'hasMore' => false, |
| 2146 | ]; |
| 2147 | } |
| 2148 | |
| 2149 | /** |
| 2150 | * Prepare JetpackCRM contact status. |
| 2151 | * |
| 2152 | * @param array $data Search Params. |
| 2153 | * |
| 2154 | * @return array |
| 2155 | */ |
| 2156 | public function search_jetpack_crm_contact_statuses( $data ) { |
| 2157 | |
| 2158 | $options = [ |
| 2159 | [ |
| 2160 | 'label' => __( 'Lead', 'suretriggers' ), |
| 2161 | 'value' => 'Lead', |
| 2162 | ], |
| 2163 | [ |
| 2164 | 'label' => __( 'Customer', 'suretriggers' ), |
| 2165 | 'value' => 'Customer', |
| 2166 | ], |
| 2167 | [ |
| 2168 | 'label' => __( 'Refused', 'suretriggers' ), |
| 2169 | 'value' => 'Refused', |
| 2170 | ], |
| 2171 | [ |
| 2172 | 'label' => __( 'Blacklisted', 'suretriggers' ), |
| 2173 | 'value' => 'Blacklisted', |
| 2174 | ], |
| 2175 | [ |
| 2176 | 'label' => __( 'Cancelled by Customer', 'suretriggers' ), |
| 2177 | 'value' => 'Cancelled by Customer', |
| 2178 | ], |
| 2179 | [ |
| 2180 | 'label' => __( 'Cancelled by Us (Pre-Quote)', 'suretriggers' ), |
| 2181 | 'value' => 'Cancelled by Us (Pre-Quote)', |
| 2182 | ], |
| 2183 | [ |
| 2184 | 'label' => __( 'Cancelled by Us (Post-Quote)', 'suretriggers' ), |
| 2185 | 'value' => 'Cancelled by Us (Post-Quote)', |
| 2186 | ], |
| 2187 | ]; |
| 2188 | |
| 2189 | return [ |
| 2190 | 'options' => $options, |
| 2191 | 'hasMore' => false, |
| 2192 | ]; |
| 2193 | } |
| 2194 | |
| 2195 | /** |
| 2196 | * Prepare FunnelKit Automations' lists. |
| 2197 | * |
| 2198 | * @param array $data Search Params. |
| 2199 | * |
| 2200 | * @return array |
| 2201 | */ |
| 2202 | public function search_funnel_kit_automations_lists( $data ) { |
| 2203 | |
| 2204 | if ( ! class_exists( 'BWFCRM_Lists' ) ) { |
| 2205 | return []; |
| 2206 | } |
| 2207 | |
| 2208 | $bwfcrm_lists = \BWFCRM_Lists::get_lists(); |
| 2209 | |
| 2210 | $options = []; |
| 2211 | |
| 2212 | foreach ( $bwfcrm_lists as $list ) { |
| 2213 | $options[] = [ |
| 2214 | 'label' => $list['name'], |
| 2215 | 'value' => $list['ID'], |
| 2216 | ]; |
| 2217 | } |
| 2218 | |
| 2219 | return [ |
| 2220 | 'options' => $options, |
| 2221 | 'hasMore' => false, |
| 2222 | ]; |
| 2223 | } |
| 2224 | |
| 2225 | /** |
| 2226 | * Prepare FunnelKit Automations' tags. |
| 2227 | * |
| 2228 | * @param array $data Search Params. |
| 2229 | * |
| 2230 | * @return array |
| 2231 | */ |
| 2232 | public function search_funnel_kit_automations_tags( $data ) { |
| 2233 | |
| 2234 | if ( ! class_exists( 'BWFCRM_Tag' ) ) { |
| 2235 | return []; |
| 2236 | } |
| 2237 | |
| 2238 | $bwfcrm_tags = \BWFCRM_Tag::get_tags(); |
| 2239 | |
| 2240 | $options = []; |
| 2241 | |
| 2242 | foreach ( $bwfcrm_tags as $tag ) { |
| 2243 | $options[] = [ |
| 2244 | 'label' => $tag['name'], |
| 2245 | 'value' => $tag['ID'], |
| 2246 | ]; |
| 2247 | } |
| 2248 | |
| 2249 | return [ |
| 2250 | 'options' => $options, |
| 2251 | 'hasMore' => false, |
| 2252 | ]; |
| 2253 | } |
| 2254 | |
| 2255 | /** |
| 2256 | * Prepare Wishlist Memberlists level. |
| 2257 | * |
| 2258 | * @param array $data Search Params. |
| 2259 | * |
| 2260 | * @return array[] |
| 2261 | */ |
| 2262 | public function search_wishlistmember_lists( $data ) { |
| 2263 | |
| 2264 | $wlm_levels = wlmapi_get_levels(); |
| 2265 | $options = []; |
| 2266 | |
| 2267 | if ( ! empty( $wlm_levels ) ) { |
| 2268 | foreach ( $wlm_levels['levels']['level'] as $list ) { |
| 2269 | $options[] = [ |
| 2270 | 'label' => $list['name'], |
| 2271 | 'value' => (string) $list['id'], |
| 2272 | ]; |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | return [ |
| 2277 | 'options' => $options, |
| 2278 | 'hasMore' => false, |
| 2279 | ]; |
| 2280 | } |
| 2281 | |
| 2282 | /** |
| 2283 | * Prepare elementor popups. |
| 2284 | * |
| 2285 | * @param array $data Search Params. |
| 2286 | * |
| 2287 | * @return array[] |
| 2288 | */ |
| 2289 | public function search_elementor_popups( $data ) { |
| 2290 | |
| 2291 | $posts = get_posts( |
| 2292 | [ |
| 2293 | 'post_type' => 'elementor_library', |
| 2294 | 'orderby' => 'title', |
| 2295 | 'order' => 'ASC', |
| 2296 | 'post_status' => 'publish', |
| 2297 | 'meta_query' => [ |
| 2298 | [ |
| 2299 | 'key' => '_elementor_template_type', |
| 2300 | 'value' => 'popup', |
| 2301 | 'compare' => '=', |
| 2302 | ], |
| 2303 | ], |
| 2304 | ] |
| 2305 | ); |
| 2306 | |
| 2307 | $options = []; |
| 2308 | if ( ! empty( $posts ) ) { |
| 2309 | foreach ( $posts as $post ) { |
| 2310 | $options[] = [ |
| 2311 | 'label' => $post->post_title, |
| 2312 | 'value' => $post->ID, |
| 2313 | ]; |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | return [ |
| 2318 | 'options' => $options, |
| 2319 | 'hasMore' => false, |
| 2320 | ]; |
| 2321 | } |
| 2322 | |
| 2323 | /** |
| 2324 | * Prepare givewp forms. |
| 2325 | * |
| 2326 | * @param array $data Search Params. |
| 2327 | * |
| 2328 | * @return array[] |
| 2329 | */ |
| 2330 | public function search_givewp_forms( $data ) { |
| 2331 | |
| 2332 | $posts = get_posts( |
| 2333 | [ |
| 2334 | 'post_type' => 'give_forms', |
| 2335 | 'orderby' => 'title', |
| 2336 | 'order' => 'ASC', |
| 2337 | 'post_status' => 'publish', |
| 2338 | ] |
| 2339 | ); |
| 2340 | |
| 2341 | $options = []; |
| 2342 | if ( ! empty( $posts ) ) { |
| 2343 | foreach ( $posts as $post ) { |
| 2344 | $options[] = [ |
| 2345 | 'label' => $post->post_title, |
| 2346 | 'value' => $post->ID, |
| 2347 | ]; |
| 2348 | } |
| 2349 | } |
| 2350 | |
| 2351 | return [ |
| 2352 | 'options' => $options, |
| 2353 | 'hasMore' => false, |
| 2354 | ]; |
| 2355 | } |
| 2356 | |
| 2357 | /** |
| 2358 | * Prepare buddyboss group users. |
| 2359 | * |
| 2360 | * @param array $data Search Params. |
| 2361 | * |
| 2362 | * @return array[] |
| 2363 | */ |
| 2364 | public function search_bb_group_users( $data ) { |
| 2365 | $options = []; |
| 2366 | |
| 2367 | $group_id = $data['dynamic']; |
| 2368 | $admins = groups_get_group_admins( $group_id ); |
| 2369 | |
| 2370 | if ( ! empty( $admins ) ) { |
| 2371 | foreach ( $admins as $admin ) { |
| 2372 | $admin_user = get_user_by( 'id', $admin->user_id ); |
| 2373 | $options[] = [ |
| 2374 | 'label' => $admin_user->display_name, |
| 2375 | 'value' => $admin_user->ID, |
| 2376 | ]; |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | $members = groups_get_group_members( [ 'group_id' => $group_id ] ); |
| 2381 | |
| 2382 | if ( isset( $members['members'] ) && ! empty( $members['members'] ) ) { |
| 2383 | foreach ( $members['members'] as $member ) { |
| 2384 | $options[] = [ |
| 2385 | 'label' => $member->display_name, |
| 2386 | 'value' => $member->ID, |
| 2387 | ]; |
| 2388 | } |
| 2389 | } |
| 2390 | return [ |
| 2391 | 'options' => $options, |
| 2392 | 'hasMore' => false, |
| 2393 | ]; |
| 2394 | } |
| 2395 | |
| 2396 | /** |
| 2397 | * Prepare buddyboss groups. |
| 2398 | * |
| 2399 | * @param array $data Search Params. |
| 2400 | * |
| 2401 | * @return array[] |
| 2402 | */ |
| 2403 | public function search_buddyboss_groups( $data ) { |
| 2404 | global $wpdb; |
| 2405 | |
| 2406 | $options = []; |
| 2407 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups" ); |
| 2408 | if ( ! empty( $groups ) ) { |
| 2409 | foreach ( $groups as $group ) { |
| 2410 | $options[] = [ |
| 2411 | 'label' => $group->name, |
| 2412 | 'value' => $group->id, |
| 2413 | ]; |
| 2414 | } |
| 2415 | } |
| 2416 | return [ |
| 2417 | 'options' => $options, |
| 2418 | 'hasMore' => false, |
| 2419 | ]; |
| 2420 | } |
| 2421 | |
| 2422 | /** |
| 2423 | * Prepare buddyboss public groups. |
| 2424 | * |
| 2425 | * @param array $data Search Params. |
| 2426 | * |
| 2427 | * @return array[] |
| 2428 | */ |
| 2429 | public function search_buddyboss_public_groups( $data ) { |
| 2430 | $options = []; |
| 2431 | $groups = groups_get_groups(); |
| 2432 | if ( isset( $groups['groups'] ) && ! empty( $groups['groups'] ) ) { |
| 2433 | foreach ( $groups['groups'] as $group ) { |
| 2434 | if ( 'public' === $group->status ) { |
| 2435 | $options[] = [ |
| 2436 | 'label' => $group->name, |
| 2437 | 'value' => $group->id, |
| 2438 | ]; |
| 2439 | } |
| 2440 | } |
| 2441 | } |
| 2442 | return [ |
| 2443 | 'options' => $options, |
| 2444 | 'hasMore' => false, |
| 2445 | ]; |
| 2446 | } |
| 2447 | |
| 2448 | /** |
| 2449 | * Prepare elementor forms. |
| 2450 | * |
| 2451 | * @param array $data Search Params. |
| 2452 | * |
| 2453 | * @return array[] |
| 2454 | */ |
| 2455 | public function search_elementor_forms( $data ) { |
| 2456 | |
| 2457 | $elementor_forms = Utilities::get_elementor_forms(); |
| 2458 | |
| 2459 | $options = []; |
| 2460 | if ( ! empty( $elementor_forms ) ) { |
| 2461 | foreach ( $elementor_forms as $key => $value ) { |
| 2462 | $options[] = [ |
| 2463 | 'label' => $value, |
| 2464 | 'value' => $key, |
| 2465 | ]; |
| 2466 | } |
| 2467 | } |
| 2468 | |
| 2469 | return [ |
| 2470 | 'options' => $options, |
| 2471 | 'hasMore' => false, |
| 2472 | ]; |
| 2473 | } |
| 2474 | |
| 2475 | /** |
| 2476 | * Prepare elementor form fields. |
| 2477 | * |
| 2478 | * @param array $data Search Params. |
| 2479 | * |
| 2480 | * @return array[] |
| 2481 | */ |
| 2482 | public function search_pluggable_elementor_form_fields( $data ) { |
| 2483 | $result = []; |
| 2484 | $form_id = absint( $data['dynamic'] ); |
| 2485 | $elementor_form_fields = ( new Utilities() )->get_elementor_form_fields( $data ); |
| 2486 | $options = []; |
| 2487 | if ( ! empty( $elementor_form_fields ) ) { |
| 2488 | foreach ( $elementor_form_fields as $key => $value ) { |
| 2489 | $options[] = [ |
| 2490 | 'label' => $value, |
| 2491 | 'value' => '{' . $key . '}', |
| 2492 | ]; |
| 2493 | } |
| 2494 | } |
| 2495 | |
| 2496 | return [ |
| 2497 | 'options' => $options, |
| 2498 | 'hasMore' => false, |
| 2499 | ]; |
| 2500 | } |
| 2501 | |
| 2502 | /** |
| 2503 | * Get all events |
| 2504 | * |
| 2505 | * @param array $data Data array. |
| 2506 | * |
| 2507 | * @return array |
| 2508 | */ |
| 2509 | public function search_event_calendar_event( $data ) { |
| 2510 | $page = $data['page']; |
| 2511 | $limit = Utilities::get_search_page_limit(); |
| 2512 | $offset = $limit * ( $page - 1 ); |
| 2513 | |
| 2514 | $posts = get_posts( |
| 2515 | [ |
| 2516 | 'post_type' => 'tribe_events', |
| 2517 | 'orderby' => 'title', |
| 2518 | 'order' => 'ASC', |
| 2519 | 'post_status' => 'publish', |
| 2520 | 'posts_per_page' => $limit, |
| 2521 | 'offset' => $offset, |
| 2522 | ] |
| 2523 | ); |
| 2524 | |
| 2525 | $options = []; |
| 2526 | if ( ! empty( $posts ) ) { |
| 2527 | foreach ( $posts as $post ) { |
| 2528 | $options[] = [ |
| 2529 | 'label' => $post->post_title, |
| 2530 | 'value' => $post->ID, |
| 2531 | ]; |
| 2532 | } |
| 2533 | } |
| 2534 | |
| 2535 | $count = count( $options ); |
| 2536 | |
| 2537 | return [ |
| 2538 | 'options' => $options, |
| 2539 | 'hasMore' => $count > $limit && $count > $offset, |
| 2540 | ]; |
| 2541 | } |
| 2542 | |
| 2543 | /** |
| 2544 | * Prepare rsvp event calendar events. |
| 2545 | * |
| 2546 | * @param array $data Search Params. |
| 2547 | * |
| 2548 | * @return array[] |
| 2549 | */ |
| 2550 | public function search_event_calendar_rsvp_event( $data ) { |
| 2551 | |
| 2552 | $posts = get_posts( |
| 2553 | [ |
| 2554 | 'post_type' => 'tribe_events', |
| 2555 | 'orderby' => 'title', |
| 2556 | 'order' => 'ASC', |
| 2557 | 'post_status' => 'publish', |
| 2558 | ] |
| 2559 | ); |
| 2560 | |
| 2561 | $options = []; |
| 2562 | if ( ! empty( $posts ) ) { |
| 2563 | $ticket_handler = new Tribe__Tickets__Tickets_Handler(); |
| 2564 | foreach ( $posts as $post ) { |
| 2565 | |
| 2566 | $get_rsvp_ticket = $ticket_handler->get_event_rsvp_tickets( $post->ID ); |
| 2567 | |
| 2568 | if ( ! empty( $get_rsvp_ticket ) ) { |
| 2569 | $options[] = [ |
| 2570 | 'label' => $post->post_title, |
| 2571 | 'value' => $post->ID, |
| 2572 | ]; |
| 2573 | } |
| 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | return [ |
| 2578 | 'options' => $options, |
| 2579 | 'hasMore' => false, |
| 2580 | ]; |
| 2581 | } |
| 2582 | |
| 2583 | /** |
| 2584 | * Prepare Restrict Content Membership Level. |
| 2585 | * |
| 2586 | * @param array $data Search Params. |
| 2587 | * |
| 2588 | * @return array[] |
| 2589 | */ |
| 2590 | public function search_restrictcontent_membership_level( $data ) { |
| 2591 | |
| 2592 | $rcp_memberships = rcp_get_membership_levels(); |
| 2593 | $options = []; |
| 2594 | |
| 2595 | if ( ! empty( $rcp_memberships ) ) { |
| 2596 | foreach ( $rcp_memberships as $list ) { |
| 2597 | $options[] = [ |
| 2598 | 'label' => ucfirst( $list->name ), |
| 2599 | 'value' => $list->id, |
| 2600 | ]; |
| 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | return [ |
| 2605 | 'options' => $options, |
| 2606 | 'hasMore' => false, |
| 2607 | ]; |
| 2608 | } |
| 2609 | |
| 2610 | /** |
| 2611 | * Prepare Restrict Content Customer. |
| 2612 | * |
| 2613 | * @param array $data Search Params. |
| 2614 | * |
| 2615 | * @return array[] |
| 2616 | */ |
| 2617 | public function search_restrictcontent_customer( $data ) { |
| 2618 | |
| 2619 | $rcp_users = rcp_get_memberships(); |
| 2620 | $options = []; |
| 2621 | |
| 2622 | if ( ! empty( $rcp_users ) ) { |
| 2623 | foreach ( $rcp_users as $list ) { |
| 2624 | $user = get_user_by( 'ID', $list->get_user_id() ); |
| 2625 | $user_label = $user->user_email; |
| 2626 | |
| 2627 | if ( $user->display_name !== $user->user_email ) { |
| 2628 | $user_label .= ' (' . $user->display_name . ')'; |
| 2629 | } |
| 2630 | |
| 2631 | $options[] = [ |
| 2632 | 'label' => $user_label, |
| 2633 | 'value' => $list->get_customer_id(), |
| 2634 | ]; |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | return [ |
| 2639 | 'options' => $options, |
| 2640 | 'hasMore' => false, |
| 2641 | ]; |
| 2642 | } |
| 2643 | |
| 2644 | |
| 2645 | /** |
| 2646 | * Fetch the Presto Player video List. |
| 2647 | * |
| 2648 | * @param array $data Search Params. |
| 2649 | * |
| 2650 | * @return array[] |
| 2651 | */ |
| 2652 | public function search_ap_presto_player_video_list( $data ) { |
| 2653 | |
| 2654 | $videos = ( new Video() )->all(); |
| 2655 | $options = []; |
| 2656 | if ( ! empty( $videos ) ) { |
| 2657 | foreach ( $videos as $video ) { |
| 2658 | $options[] = [ |
| 2659 | 'label' => $video->__get( 'title' ), |
| 2660 | 'value' => (string) $video->__get( 'id' ), |
| 2661 | ]; |
| 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | return [ |
| 2666 | 'options' => $options, |
| 2667 | 'hasMore' => false, |
| 2668 | ]; |
| 2669 | } |
| 2670 | |
| 2671 | /** |
| 2672 | * Presto Player Video percentage. |
| 2673 | * |
| 2674 | * @param array $data Search Params. |
| 2675 | * |
| 2676 | * @return array[] |
| 2677 | */ |
| 2678 | public function search_prestoplayer_video_percent( $data ) { |
| 2679 | |
| 2680 | $percents = [ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ]; |
| 2681 | $options = []; |
| 2682 | |
| 2683 | foreach ( $percents as $percent ) { |
| 2684 | $options[] = [ |
| 2685 | 'label' => $percent . '%', |
| 2686 | 'value' => (string) $percent, |
| 2687 | ]; |
| 2688 | } |
| 2689 | |
| 2690 | return [ |
| 2691 | 'options' => $options, |
| 2692 | 'hasMore' => false, |
| 2693 | ]; |
| 2694 | } |
| 2695 | |
| 2696 | /** |
| 2697 | * Get user profile field options. |
| 2698 | * |
| 2699 | * @return array |
| 2700 | * @since 1.0.0 |
| 2701 | */ |
| 2702 | public function search_user_field_options() { |
| 2703 | |
| 2704 | $options = apply_filters( |
| 2705 | 'sure_trigger_get_user_field_options', |
| 2706 | [ |
| 2707 | [ |
| 2708 | 'label' => __( 'User Name', 'suretriggers' ), |
| 2709 | 'value' => 'user_login', |
| 2710 | ], |
| 2711 | [ |
| 2712 | 'label' => __( 'User Email', 'suretriggers' ), |
| 2713 | 'value' => 'user_email', |
| 2714 | ], |
| 2715 | [ |
| 2716 | 'label' => __( 'Display Name', 'suretriggers' ), |
| 2717 | 'value' => 'display_name', |
| 2718 | ], |
| 2719 | [ |
| 2720 | 'label' => __( 'User Password', 'suretriggers' ), |
| 2721 | 'value' => 'user_pass', |
| 2722 | ], |
| 2723 | [ |
| 2724 | 'label' => __( 'Website', 'suretriggers' ), |
| 2725 | 'value' => 'user_url', |
| 2726 | ], |
| 2727 | ] |
| 2728 | ); |
| 2729 | |
| 2730 | return [ |
| 2731 | 'options' => $options, |
| 2732 | 'hasMore' => false, |
| 2733 | ]; |
| 2734 | } |
| 2735 | |
| 2736 | /** |
| 2737 | * Get user post field options. |
| 2738 | * |
| 2739 | * @return array |
| 2740 | * @since 1.0.0 |
| 2741 | */ |
| 2742 | public function search_post_field_options() { |
| 2743 | |
| 2744 | return [ |
| 2745 | 'options' => [ |
| 2746 | [ |
| 2747 | 'label' => __( 'Type', 'suretriggers' ), |
| 2748 | 'value' => 'post_type', |
| 2749 | 'dynamic_field' => [ |
| 2750 | 'type' => 'select-creatable', |
| 2751 | 'ajaxIdentifier' => 'post_types', |
| 2752 | ], |
| 2753 | ], |
| 2754 | [ |
| 2755 | 'label' => __( 'Status', 'suretriggers' ), |
| 2756 | 'value' => 'post_status', |
| 2757 | 'dynamic_field' => [ |
| 2758 | 'type' => 'select-async', |
| 2759 | 'ajaxIdentifier' => 'post_statuses', |
| 2760 | ], |
| 2761 | ], |
| 2762 | [ |
| 2763 | 'label' => __( 'Author', 'suretriggers' ), |
| 2764 | 'value' => 'post_author', |
| 2765 | 'dynamic_field' => [ |
| 2766 | 'type' => 'select-async', |
| 2767 | 'ajaxIdentifier' => 'user', |
| 2768 | ], |
| 2769 | ], |
| 2770 | [ |
| 2771 | 'label' => __( 'Title', 'suretriggers' ), |
| 2772 | 'value' => 'post_title', |
| 2773 | 'dynamic_field' => [ |
| 2774 | 'type' => 'select-creatable', |
| 2775 | ], |
| 2776 | ], |
| 2777 | [ |
| 2778 | 'label' => __( 'Slug', 'suretriggers' ), |
| 2779 | 'value' => 'post_slug', |
| 2780 | 'dynamic_field' => [ |
| 2781 | 'type' => 'select-creatable', |
| 2782 | ], |
| 2783 | ], |
| 2784 | [ |
| 2785 | 'label' => __( 'Content', 'suretriggers' ), |
| 2786 | 'value' => 'post_content', |
| 2787 | 'dynamic_field' => [ |
| 2788 | 'type' => 'html-editor', |
| 2789 | ], |
| 2790 | ], |
| 2791 | ], |
| 2792 | 'hasMore' => false, |
| 2793 | ]; |
| 2794 | } |
| 2795 | |
| 2796 | /** |
| 2797 | * Bricksbuilder grouped data. |
| 2798 | * |
| 2799 | * @param array $data data. |
| 2800 | * @return array |
| 2801 | */ |
| 2802 | public function search_bb_groups( $data ) { |
| 2803 | |
| 2804 | global $wpdb; |
| 2805 | $options = []; |
| 2806 | |
| 2807 | if ( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'bp_groups' ) ) ) { |
| 2808 | |
| 2809 | $results = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %s', $wpdb->prefix . 'bp_groups' ) ); |
| 2810 | |
| 2811 | if ( $results ) { |
| 2812 | foreach ( $results as $result ) { |
| 2813 | $options[] = [ |
| 2814 | 'label' => $result->name, |
| 2815 | 'value' => $result->id, |
| 2816 | ]; |
| 2817 | } |
| 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | return [ |
| 2822 | 'options' => $options, |
| 2823 | 'hasMore' => false, |
| 2824 | ]; |
| 2825 | } |
| 2826 | |
| 2827 | /** |
| 2828 | * Search forms. |
| 2829 | * |
| 2830 | * @return array |
| 2831 | */ |
| 2832 | public function search_bb_forums() { |
| 2833 | $options = []; |
| 2834 | $allowed_atatus = [ 'publish', 'private' ]; |
| 2835 | $forum_args = [ |
| 2836 | 'post_type' => bbp_get_forum_post_type(), |
| 2837 | 'posts_per_page' => -1, |
| 2838 | 'orderby' => 'title', |
| 2839 | 'order' => 'ASC', |
| 2840 | 'post_status' => 'any', |
| 2841 | ]; |
| 2842 | $forums = get_posts( $forum_args ); |
| 2843 | |
| 2844 | if ( ! empty( $forums ) ) { |
| 2845 | foreach ( $forums as $forum ) { |
| 2846 | if ( in_array( $forum->post_status, $allowed_atatus, true ) ) { |
| 2847 | $options[] = [ |
| 2848 | 'label' => $forum->post_title, |
| 2849 | 'value' => $forum->ID, |
| 2850 | ]; |
| 2851 | } |
| 2852 | } |
| 2853 | } |
| 2854 | return [ |
| 2855 | 'options' => $options, |
| 2856 | 'hasMore' => false, |
| 2857 | ]; |
| 2858 | } |
| 2859 | |
| 2860 | /** |
| 2861 | * Get last data for trigger. |
| 2862 | * |
| 2863 | * @param array $data data. |
| 2864 | * @return array |
| 2865 | */ |
| 2866 | public function search_affiliate_wp_triggers_last_data( $data ) { |
| 2867 | global $wpdb; |
| 2868 | |
| 2869 | $context = []; |
| 2870 | $context['response_type'] = 'sample'; |
| 2871 | |
| 2872 | $user_data = WordPress::get_sample_user_context(); |
| 2873 | |
| 2874 | $affiliate_data = [ |
| 2875 | 'affiliate_id' => 1, |
| 2876 | 'rest_id' => '', |
| 2877 | 'user_id' => 1, |
| 2878 | 'rate' => '', |
| 2879 | 'rate_type' => '', |
| 2880 | 'flat_rate_basis' => '', |
| 2881 | 'payment_email' => 'admin@bsf.io', |
| 2882 | 'status' => 'active', |
| 2883 | 'earnings' => 0, |
| 2884 | 'unpaid_earnings' => 0, |
| 2885 | 'referrals' => 0, |
| 2886 | 'visits' => 0, |
| 2887 | 'date_registered' => '2023-01-18 13:35:22', |
| 2888 | 'dynamic_coupon' => 'KDJSKS', |
| 2889 | ]; |
| 2890 | |
| 2891 | $referral_data = [ |
| 2892 | 'referral_id' => 1, |
| 2893 | 'affiliate_id' => 1, |
| 2894 | 'visit_id' => 0, |
| 2895 | 'rest_id' => '', |
| 2896 | 'customer_id' => 0, |
| 2897 | 'parent_id' => 0, |
| 2898 | 'description' => 'Testing', |
| 2899 | 'status' => 'unpaid', |
| 2900 | 'amount' => '12.00', |
| 2901 | 'currency' => '', |
| 2902 | 'custom' => 'custom', |
| 2903 | 'context' => '', |
| 2904 | 'campaign' => '', |
| 2905 | 'reference' => 'Reference', |
| 2906 | 'products' => '', |
| 2907 | 'date' => '2023-01-18 16:36:59', |
| 2908 | 'type' => 'opt-in', |
| 2909 | 'payout_id' => 0, |
| 2910 | ]; |
| 2911 | |
| 2912 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 2913 | |
| 2914 | if ( in_array( $term, [ 'affiliate_approved', 'affiliate_awaiting_approval' ], true ) ) { |
| 2915 | $affiliate = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}affiliate_wp_affiliates WHERE affiliate_id = ( SELECT max(affiliate_id) FROM {$wpdb->prefix}affiliate_wp_affiliates )" ); |
| 2916 | |
| 2917 | if ( ! empty( $affiliate ) ) { |
| 2918 | $affiliate = affwp_get_affiliate( $affiliate->affiliate_id ); |
| 2919 | $affiliate_data = get_object_vars( $affiliate ); |
| 2920 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 2921 | $context['response_type'] = 'live'; |
| 2922 | } |
| 2923 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data ); |
| 2924 | |
| 2925 | } else { |
| 2926 | $referral = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}affiliate_wp_referrals WHERE referral_id = ( SELECT max(referral_id) FROM {$wpdb->prefix}affiliate_wp_referrals )" ); |
| 2927 | |
| 2928 | if ( ! empty( $referral ) ) { |
| 2929 | $referral = affwp_get_referral( $referral->referral_id ); |
| 2930 | $affiliate = affwp_get_affiliate( $referral->affiliate_id ); |
| 2931 | $affiliate_data = get_object_vars( $affiliate ); |
| 2932 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 2933 | $referral_data = get_object_vars( $referral ); |
| 2934 | $context['response_type'] = 'live'; |
| 2935 | } |
| 2936 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data, $referral_data ); |
| 2937 | } |
| 2938 | |
| 2939 | return $context; |
| 2940 | } |
| 2941 | |
| 2942 | /** |
| 2943 | * Get last data for trigger. |
| 2944 | * |
| 2945 | * @param array $data data. |
| 2946 | * @return array |
| 2947 | */ |
| 2948 | public function search_jetpack_crm_triggers_last_data( $data ) { |
| 2949 | |
| 2950 | if ( ! function_exists( 'zeroBS_getCompanyCount' ) || ! function_exists( 'zeroBS_getCustomerCount' ) || ! function_exists( 'zeroBS_getQuoteCount' ) ) { |
| 2951 | return []; |
| 2952 | } |
| 2953 | |
| 2954 | global $wpdb; |
| 2955 | |
| 2956 | $context = []; |
| 2957 | $context['response_type'] = 'sample'; |
| 2958 | |
| 2959 | $company_id = [ 'company_id' => 1 ]; |
| 2960 | $contact_id = [ 'contact_id' => 1 ]; |
| 2961 | $quote_id = [ 'quote_id' => 1 ]; |
| 2962 | $event_id = [ 'event_id' => 1 ]; |
| 2963 | $invoice_id = [ 'invoice_id' => 1 ]; |
| 2964 | $transaction_id = [ 'transaction_id' => 1 ]; |
| 2965 | |
| 2966 | $company = [ |
| 2967 | 'company_id' => 1, |
| 2968 | 'company_status' => 'Lead', |
| 2969 | 'company_name' => 'Example Company', |
| 2970 | 'company_email' => 'info@example.com', |
| 2971 | 'main_address_line_1' => '123 Main Street', |
| 2972 | 'main_address_line_2' => 'Suite 456', |
| 2973 | 'main_address_city' => 'New York', |
| 2974 | 'main_address_state' => 'NY', |
| 2975 | 'main_address_postal_code' => '10001', |
| 2976 | 'main_address_country' => 'United States', |
| 2977 | 'second_address_line_1' => '789 Second Avenue', |
| 2978 | 'second_address_line_2' => 'Floor 10', |
| 2979 | 'second_address_city' => 'Los Angeles', |
| 2980 | 'second_address_state' => 'CA', |
| 2981 | 'second_address_postal_code' => '90001', |
| 2982 | 'second_address_country' => 'United States', |
| 2983 | 'main_telephone' => '+1 123-456-7890', |
| 2984 | 'secondary_telephone' => '+1 987-654-3210', |
| 2985 | ]; |
| 2986 | |
| 2987 | $contact = [ |
| 2988 | 'contact_id' => 1, |
| 2989 | 'status' => 'Lead', |
| 2990 | 'prefix' => 'Mr.', |
| 2991 | 'full_name' => 'John Doe', |
| 2992 | 'first_name' => 'John', |
| 2993 | 'last_name' => 'Doe', |
| 2994 | 'email' => 'johndoe@example.com', |
| 2995 | 'main_address_line_1' => '123 Main Street', |
| 2996 | 'main_address_line_2' => 'Suite 456', |
| 2997 | 'main_address_city' => 'New York', |
| 2998 | 'main_address_state' => 'NY', |
| 2999 | 'main_address_postal_code' => '10001', |
| 3000 | 'main_address_country' => 'United States', |
| 3001 | 'second_address_line_1' => '789 Second Avenue', |
| 3002 | 'second_address_line_2' => 'Floor 10', |
| 3003 | 'second_address_city' => 'Los Angeles', |
| 3004 | 'second_address_state' => 'CA', |
| 3005 | 'second_address_postal_code' => '90001', |
| 3006 | 'second_address_country' => 'United States', |
| 3007 | 'home_telephone' => '+1 123-456-7890', |
| 3008 | 'work_telephone' => '+1 987-654-3210', |
| 3009 | 'mobile_telephone' => '+1 555-555-5555', |
| 3010 | ]; |
| 3011 | |
| 3012 | $quote = [ |
| 3013 | 'quote_id' => 1, |
| 3014 | 'contact_id' => 2, |
| 3015 | 'contact_email' => 'john@example.com', |
| 3016 | 'contact_name' => 'John Doe', |
| 3017 | 'status' => '<strong>Created, not yet accepted</strong>', |
| 3018 | 'title' => 'Sample Quote', |
| 3019 | 'value' => 1000, |
| 3020 | 'date' => '2023-05-23', |
| 3021 | 'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', |
| 3022 | 'notes' => 'Additional notes about the quote.', |
| 3023 | ]; |
| 3024 | |
| 3025 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3026 | |
| 3027 | switch ( $term ) { |
| 3028 | case 'company_created': |
| 3029 | if ( zeroBS_getCompanyCount() > 0 ) { |
| 3030 | $company_data = $wpdb->get_row( "SELECT ID FROM {$wpdb->prefix}zbs_companies WHERE ID = ( SELECT max(ID) FROM {$wpdb->prefix}zbs_companies )" ); |
| 3031 | $company = JetpackCRM::get_company_context( $company_data->ID ); |
| 3032 | $context['response_type'] = 'live'; |
| 3033 | } |
| 3034 | $context['pluggable_data'] = $company; |
| 3035 | break; |
| 3036 | case 'company_deleted': |
| 3037 | $context['pluggable_data'] = $company_id; |
| 3038 | break; |
| 3039 | case 'contact_created': |
| 3040 | if ( zeroBS_getCustomerCount() > 0 ) { |
| 3041 | $contact_data = $wpdb->get_row( "SELECT ID FROM {$wpdb->prefix}zbs_contacts WHERE ID = ( SELECT max(ID) FROM {$wpdb->prefix}zbs_contacts )" ); |
| 3042 | $contact = JetpackCRM::get_contact_context( $contact_data->ID ); |
| 3043 | $context['response_type'] = 'live'; |
| 3044 | } |
| 3045 | $context['pluggable_data'] = $contact; |
| 3046 | break; |
| 3047 | case 'contact_deleted': |
| 3048 | $context['pluggable_data'] = $contact_id; |
| 3049 | break; |
| 3050 | case 'event_deleted': |
| 3051 | $context['pluggable_data'] = $event_id; |
| 3052 | break; |
| 3053 | case 'invoice_deleted': |
| 3054 | $context['pluggable_data'] = $invoice_id; |
| 3055 | break; |
| 3056 | case 'quote_accepted': |
| 3057 | case 'quote_created': |
| 3058 | if ( zeroBS_getQuoteCount() > 0 ) { |
| 3059 | $quote_data = $wpdb->get_row( "SELECT ID FROM {$wpdb->prefix}zbs_quotes WHERE ID = ( SELECT max(ID) FROM {$wpdb->prefix}zbs_quotes )" ); |
| 3060 | $quote = JetpackCRM::get_quote_context( $quote_data->ID ); |
| 3061 | $context['response_type'] = 'live'; |
| 3062 | } |
| 3063 | $context['pluggable_data'] = $quote; |
| 3064 | break; |
| 3065 | case 'quote_deleted': |
| 3066 | $context['pluggable_data'] = $quote_id; |
| 3067 | break; |
| 3068 | case 'transaction_deleted': |
| 3069 | $context['pluggable_data'] = $transaction_id; |
| 3070 | break; |
| 3071 | } |
| 3072 | |
| 3073 | return $context; |
| 3074 | } |
| 3075 | |
| 3076 | /** |
| 3077 | * Get last data for trigger. |
| 3078 | * |
| 3079 | * @param array $data data. |
| 3080 | * @return array |
| 3081 | */ |
| 3082 | public function search_funnel_kit_automations_triggers_last_data( $data ) { |
| 3083 | |
| 3084 | if ( ! class_exists( 'BWFCRM_Contact' ) || ! class_exists( 'BWFCRM_Lists' ) || ! class_exists( 'BWFCRM_Tag' ) ) { |
| 3085 | return []; |
| 3086 | } |
| 3087 | |
| 3088 | $context = []; |
| 3089 | $context['response_type'] = 'sample'; |
| 3090 | |
| 3091 | $contact = [ |
| 3092 | 'contact_id' => '1', |
| 3093 | 'wpid' => '0', |
| 3094 | 'uid' => '9e74246335fd81b1c4a9123842c12549', |
| 3095 | 'email' => 'johndoe@example.com', |
| 3096 | 'first_name' => 'John', |
| 3097 | 'last_name' => 'Doe', |
| 3098 | 'contact_no' => '+1 555-555-5555', |
| 3099 | 'state' => 'NY', |
| 3100 | 'country' => 'United States', |
| 3101 | 'timezone' => 'New York', |
| 3102 | 'creation_date' => '2023-05-29 15:26:03', |
| 3103 | 'last_modified' => '2023-05-29 17:08:30', |
| 3104 | 'source' => '', |
| 3105 | 'type' => 'Los Angeles', |
| 3106 | 'status' => '0', |
| 3107 | 'tags' => '["1"]', |
| 3108 | 'lists' => '["2","1"]', |
| 3109 | ]; |
| 3110 | |
| 3111 | $list = [ |
| 3112 | 'list_id' => 1, |
| 3113 | 'list_name' => 'Sample List', |
| 3114 | ]; |
| 3115 | |
| 3116 | $tag = [ |
| 3117 | 'tag_id' => 1, |
| 3118 | 'tag_name' => 'Sample Tag', |
| 3119 | ]; |
| 3120 | |
| 3121 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3122 | |
| 3123 | $recent_contacts = \BWFCRM_Contact::get_recent_contacts( 0, 1, [] ); |
| 3124 | $contact_email = count( $recent_contacts['contacts'] ) > 0 && isset( $recent_contacts['contacts'][0]['email'] ) ? $recent_contacts['contacts'][0]['email'] : ''; |
| 3125 | |
| 3126 | $real_contact = false; |
| 3127 | if ( ! empty( $contact_email ) ) { |
| 3128 | $contact_obj = \BWFCRM_Contact::get_contacts( $contact_email, 0, 1, [], [], OBJECT ); |
| 3129 | |
| 3130 | if ( isset( $contact_obj['contacts'][0] ) ) { |
| 3131 | $contact = FunnelKitAutomations::get_contact_context( $contact_obj['contacts'][0]->contact ); |
| 3132 | $real_contact = true; |
| 3133 | } |
| 3134 | } |
| 3135 | |
| 3136 | if ( 'contact_added_to_list' === $term || 'contact_removed_from_list' === $term ) { |
| 3137 | $list_id = (int) ( isset( $data['filter']['list_id']['value'] ) ? $data['filter']['list_id']['value'] : '-1' ); |
| 3138 | |
| 3139 | if ( -1 === $list_id ) { |
| 3140 | $lists = \BWFCRM_Lists::get_lists( [], '', 0, 1 ); |
| 3141 | $list_id = count( $lists ) > 0 ? $lists[0]['ID'] : -1; |
| 3142 | } |
| 3143 | |
| 3144 | |
| 3145 | if ( -1 !== $list_id ) { |
| 3146 | $list = FunnelKitAutomations::get_list_context( $list_id ); |
| 3147 | $context['response_type'] = $real_contact ? 'live' : 'sample'; |
| 3148 | } |
| 3149 | |
| 3150 | $context['pluggable_data'] = array_merge( $list, $contact ); |
| 3151 | } else { |
| 3152 | $tag_id = (int) ( isset( $data['filter']['tag_id']['value'] ) ? $data['filter']['tag_id']['value'] : '-1' ); |
| 3153 | |
| 3154 | if ( -1 === $tag_id ) { |
| 3155 | $tags = \BWFCRM_Tag::get_tags( [], '', 0, 1 ); |
| 3156 | $tag_id = count( $tags ) > 0 ? $tags[0]['ID'] : -1; |
| 3157 | } |
| 3158 | |
| 3159 | |
| 3160 | if ( -1 !== $tag_id ) { |
| 3161 | $tag = FunnelKitAutomations::get_tag_context( $tag_id ); |
| 3162 | $context['response_type'] = $real_contact ? 'live' : 'sample'; |
| 3163 | } |
| 3164 | |
| 3165 | $context['pluggable_data'] = array_merge( $tag, $contact ); |
| 3166 | } |
| 3167 | |
| 3168 | return $context; |
| 3169 | } |
| 3170 | |
| 3171 | /** |
| 3172 | * Get last data for trigger. |
| 3173 | * |
| 3174 | * @param array $data data. |
| 3175 | * @return array |
| 3176 | */ |
| 3177 | public function search_edd_triggers_last_data( $data ) { |
| 3178 | |
| 3179 | global $wpdb; |
| 3180 | $context = []; |
| 3181 | $context['response_type'] = 'sample'; |
| 3182 | |
| 3183 | $order_data = [ |
| 3184 | 'order_id' => '1', |
| 3185 | 'customer_email' => 'john_doe@bsf.io', |
| 3186 | 'customer_first_name' => 'John', |
| 3187 | 'customer_last_name' => 'Doe', |
| 3188 | 'ordered_items' => 'Any Sample Book', |
| 3189 | 'currency' => 'USD', |
| 3190 | 'status' => 'complete', |
| 3191 | 'discount_codes' => 'KDJSKS', |
| 3192 | 'order_discounts' => '2.00', |
| 3193 | 'order_subtotal' => '48.00', |
| 3194 | 'order_tax' => '0.00', |
| 3195 | 'order_total' => '48.00', |
| 3196 | 'payment_method' => 'stripe', |
| 3197 | ]; |
| 3198 | |
| 3199 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3200 | |
| 3201 | if ( 'order_created' === $term ) { |
| 3202 | $order_data['purchase_key'] = '06d3b7d923ca922dc889354f9bc33fbb'; |
| 3203 | |
| 3204 | $args = [ |
| 3205 | 'number' => 1, |
| 3206 | 'status' => [ 'complete', 'refunded', 'partially_refunded' ], |
| 3207 | ]; |
| 3208 | $payments = edd_get_payments( $args ); |
| 3209 | |
| 3210 | if ( count( $payments ) > 0 ) { |
| 3211 | $order_data = EDD::get_product_purchase_context( $payments[0] ); |
| 3212 | $context['response_type'] = 'live'; |
| 3213 | } |
| 3214 | } elseif ( 'edd_triggers_last_data' === $term ) { |
| 3215 | $args = [ |
| 3216 | 'number' => 1, |
| 3217 | 'status' => 'complete', |
| 3218 | 'type' => 'refund', |
| 3219 | ]; |
| 3220 | $payments = edd_get_payments( $args ); |
| 3221 | |
| 3222 | if ( count( $payments ) > 0 ) { |
| 3223 | $order_data = EDD::get_purchase_refund_context( $payments[0] ); |
| 3224 | $context['response_type'] = 'live'; |
| 3225 | } |
| 3226 | } else { |
| 3227 | $status = isset( $data['post_type'] ) ? $data['post_type'] : ''; |
| 3228 | if ( ! empty( $status ) ) { |
| 3229 | $licesnses = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_licenses WHERE status= %s ORDER BY id DESC", $status ) ); |
| 3230 | } else { |
| 3231 | $licesnses = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}edd_licenses ORDER BY id DESC" ); |
| 3232 | } |
| 3233 | if ( ! empty( $licesnses ) ) { |
| 3234 | $order_data = EDD::edd_get_license_data( $licesnses->id, $licesnses->download_id, $licesnses->payment_id ); |
| 3235 | $context['response_type'] = 'live'; |
| 3236 | } else { |
| 3237 | $order_data = [ |
| 3238 | 'ID' => 1, |
| 3239 | 'key' => '23232323232', |
| 3240 | 'customer_email' => 'suretest@example.com', |
| 3241 | 'customer_name' => 'Sure Test', |
| 3242 | 'product_id' => 1, |
| 3243 | 'product_name' => 'Test', |
| 3244 | 'activation_limit' => 2, |
| 3245 | 'activation_count' => 1, |
| 3246 | 'activated_urls' => 'https://example.com', |
| 3247 | 'expiration' => '1686297914', |
| 3248 | 'is_lifetime' => '0', |
| 3249 | 'status' => 'active', |
| 3250 | ]; |
| 3251 | |
| 3252 | } |
| 3253 | } |
| 3254 | |
| 3255 | $context['pluggable_data'] = $order_data; |
| 3256 | return $context; |
| 3257 | } |
| 3258 | |
| 3259 | /** |
| 3260 | * Get last data for trigger. |
| 3261 | * |
| 3262 | * @param array $data data. |
| 3263 | * @return array |
| 3264 | */ |
| 3265 | public function search_presto_player_triggers_last_data( $data ) { |
| 3266 | $context = []; |
| 3267 | $context['response_type'] = 'sample'; |
| 3268 | |
| 3269 | $user_data = WordPress::get_sample_user_context(); |
| 3270 | |
| 3271 | $video_data = [ |
| 3272 | 'pp_video' => '1', |
| 3273 | 'pp_video_percentage' => '100', |
| 3274 | 'video_id' => '1', |
| 3275 | 'video_title' => 'SureTriggers Is Here 🎉 The Easiest Automation Builder WordPress Websites & Apps', |
| 3276 | 'video_type' => 'youtube', |
| 3277 | 'video_external_id' => '-cYbNYgylLs', |
| 3278 | 'video_attachment_id' => '0', |
| 3279 | 'video_post_id' => '127', |
| 3280 | 'video_src' => 'https://www.youtube.com/watch?v=-cYbNYgylLs', |
| 3281 | 'video_created_by' => '1', |
| 3282 | 'video_created_at' => '2022-11-10 00:28:25', |
| 3283 | 'video_updated_at' => '2022-11-10 00:34:40', |
| 3284 | 'video_deleted_at' => '', |
| 3285 | ]; |
| 3286 | |
| 3287 | $videos = ( new Video() )->all(); |
| 3288 | |
| 3289 | if ( count( $videos ) > 0 ) { |
| 3290 | $video_id = '-1' === $data['filter']['pp_video']['value'] ? $videos[0]->id : $data['filter']['pp_video']['value']; |
| 3291 | $video_data = ( new Video( $video_id ) )->toArray(); |
| 3292 | $video_data['pp_video'] = $video_id; |
| 3293 | $video_data['pp_video_percentage'] = isset( $data['filter']['pp_video_percentage']['value'] ) ? $data['filter']['pp_video_percentage']['value'] : '100'; |
| 3294 | $user_data = WordPress::get_user_context( $video_data['created_by'] ); |
| 3295 | |
| 3296 | $context['response_type'] = 'live'; |
| 3297 | } |
| 3298 | |
| 3299 | $context['pluggable_data'] = array_merge( $user_data, $video_data ); |
| 3300 | |
| 3301 | return $context; |
| 3302 | } |
| 3303 | |
| 3304 | /** |
| 3305 | * Get last data for trigger. |
| 3306 | * |
| 3307 | * @param array $data data. |
| 3308 | * @return array |
| 3309 | */ |
| 3310 | public function search_member_press_triggers_last_data( $data ) { |
| 3311 | global $wpdb; |
| 3312 | |
| 3313 | $context = []; |
| 3314 | $context['response_type'] = 'sample'; |
| 3315 | |
| 3316 | $user_data = WordPress::get_sample_user_context(); |
| 3317 | |
| 3318 | $membership_data = [ |
| 3319 | 'membership_id' => '190', |
| 3320 | 'membership_title' => 'Sample Membership', |
| 3321 | 'amount' => '12.00', |
| 3322 | 'total' => '12.00', |
| 3323 | 'tax_amount' => '0.00', |
| 3324 | 'tax_rate' => '0.00', |
| 3325 | 'trans_num' => 't_63a03f3334f44', |
| 3326 | 'status' => 'complete', |
| 3327 | 'subscription_id' => '0', |
| 3328 | 'membership_url' => site_url() . '/register/premium/', |
| 3329 | 'membership_featured_image_id' => '521', |
| 3330 | 'membership_featured_image_url' => SURE_TRIGGERS_URL . 'assets/images/sample.svg', |
| 3331 | ]; |
| 3332 | |
| 3333 | $membership_id = (int) ( isset( $data['filter']['membership_id']['value'] ) ? $data['filter']['membership_id']['value'] : '-1' ); |
| 3334 | |
| 3335 | if ( $membership_id > 0 ) { |
| 3336 | |
| 3337 | $subscription = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mepr_transactions WHERE product_id= %s ORDER BY id DESC LIMIT 1", $membership_id ) ); |
| 3338 | } else { |
| 3339 | $subscription = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}mepr_transactions ORDER BY id DESC LIMIT 1" ); |
| 3340 | } |
| 3341 | |
| 3342 | if ( ! empty( $subscription ) ) { |
| 3343 | $membership_data = MemberPress::get_membership_context( $subscription ); |
| 3344 | $user_data = WordPress::get_user_context( $subscription->user_id ); |
| 3345 | |
| 3346 | $context['response_type'] = 'live'; |
| 3347 | } |
| 3348 | |
| 3349 | $context['pluggable_data'] = array_merge( $user_data, $membership_data ); |
| 3350 | |
| 3351 | return $context; |
| 3352 | } |
| 3353 | |
| 3354 | /** |
| 3355 | * Get last data for trigger. |
| 3356 | * |
| 3357 | * @param array $data data. |
| 3358 | * @return array |
| 3359 | */ |
| 3360 | public function search_wishlist_member_triggers_last_data( $data ) { |
| 3361 | global $wpdb; |
| 3362 | |
| 3363 | $context = []; |
| 3364 | $context['response_type'] = 'sample'; |
| 3365 | |
| 3366 | $user_data = WordPress::get_sample_user_context(); |
| 3367 | |
| 3368 | $membership_data = [ |
| 3369 | 'membership_level_id' => '1', |
| 3370 | 'membership_level_name' => 'Sample Membership Level', |
| 3371 | ]; |
| 3372 | |
| 3373 | $membership_level_id = (int) ( isset( $data['filter']['membership_level_id']['value'] ) ? $data['filter']['membership_level_id']['value'] : '-1' ); |
| 3374 | |
| 3375 | if ( $membership_level_id > 0 ) { |
| 3376 | $membership = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wlm_userlevels WHERE level_id= %s ORDER BY id DESC LIMIT 1", $membership_level_id ) ); |
| 3377 | } else { |
| 3378 | $membership = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}wlm_userlevels ORDER BY id DESC LIMIT 1" ); |
| 3379 | } |
| 3380 | if ( ! empty( $membership ) ) { |
| 3381 | $membership_data = WishlistMember::get_membership_detail_context( (int) $membership->level_id ); |
| 3382 | $user_data = WordPress::get_user_context( $membership->user_id ); |
| 3383 | |
| 3384 | $context['response_type'] = 'live'; |
| 3385 | } |
| 3386 | |
| 3387 | $context['pluggable_data'] = array_merge( $user_data, $membership_data ); |
| 3388 | |
| 3389 | return $context; |
| 3390 | } |
| 3391 | |
| 3392 | /** |
| 3393 | * Get last data for trigger. |
| 3394 | * |
| 3395 | * @param array $data data. |
| 3396 | * @return array |
| 3397 | */ |
| 3398 | public function search_peepso_triggers_last_data( $data ) { |
| 3399 | global $wpdb; |
| 3400 | |
| 3401 | $context = []; |
| 3402 | $context['response_type'] = 'sample'; |
| 3403 | |
| 3404 | $user_data = WordPress::get_sample_user_context(); |
| 3405 | |
| 3406 | $post_data = [ |
| 3407 | 'post_id' => '1', |
| 3408 | 'activity_id' => '2', |
| 3409 | 'post_author' => '1', |
| 3410 | 'post_content' => 'New sample post...!', |
| 3411 | 'post_title' => 'Sample Post', |
| 3412 | 'post_excerpt' => 'sample', |
| 3413 | 'post_status' => 'publish', |
| 3414 | 'post_type' => 'peepso-post', |
| 3415 | ]; |
| 3416 | |
| 3417 | $post = $wpdb->get_row( "SELECT act_id, act_owner_id, act_external_id FROM {$wpdb->prefix}peepso_activities ORDER BY act_id DESC LIMIT 1" ); |
| 3418 | |
| 3419 | if ( ! empty( $post ) ) { |
| 3420 | $post_data = PeepSo::get_pp_activity_context( (int) $post->act_external_id, (int) $post->act_id ); |
| 3421 | $user_data = WordPress::get_user_context( $post->act_owner_id ); |
| 3422 | |
| 3423 | $context['response_type'] = 'live'; |
| 3424 | } |
| 3425 | |
| 3426 | $context['pluggable_data'] = array_merge( $user_data, $post_data ); |
| 3427 | |
| 3428 | return $context; |
| 3429 | } |
| 3430 | |
| 3431 | /** |
| 3432 | * Get last data for trigger |
| 3433 | * |
| 3434 | * @param array $data data. |
| 3435 | * @return array |
| 3436 | */ |
| 3437 | public function search_restrict_content_pro_triggers_last_data( $data ) { |
| 3438 | $context = []; |
| 3439 | $context['response_type'] = 'sample'; |
| 3440 | |
| 3441 | $user_data = WordPress::get_sample_user_context(); |
| 3442 | |
| 3443 | $membership_data = [ |
| 3444 | 'membership_level_id' => '190', |
| 3445 | 'membership_level' => 'Sample Membership', |
| 3446 | 'membership_initial_payment' => '0.00', |
| 3447 | 'membership_recurring_payment' => '0.00', |
| 3448 | 'membership_expiry_date' => 'January 22, 2023', |
| 3449 | ]; |
| 3450 | |
| 3451 | $customer_id = (int) ( isset( $data['filter']['membership_customer_id']['value'] ) ? $data['filter']['membership_customer_id']['value'] : '-1' ); |
| 3452 | $membership_id = (int) ( isset( $data['filter']['membership_level_id']['value'] ) ? $data['filter']['membership_level_id']['value'] : '-1' ); |
| 3453 | |
| 3454 | $args = [ |
| 3455 | 'status' => 'expired', |
| 3456 | 'number' => 1, |
| 3457 | 'orderby' => 'id', |
| 3458 | ]; |
| 3459 | |
| 3460 | if ( -1 !== $customer_id ) { |
| 3461 | $args['customer_id'] = $customer_id; |
| 3462 | } |
| 3463 | |
| 3464 | if ( -1 !== $membership_id ) { |
| 3465 | $args['object_id'] = $membership_id; |
| 3466 | } |
| 3467 | |
| 3468 | $memberships = rcp_get_memberships( $args ); |
| 3469 | if ( count( $memberships ) > 0 ) { |
| 3470 | $membership_data = RestrictContent::get_rcp_membership_detail_context( $memberships[0] ); |
| 3471 | $user_data = WordPress::get_user_context( $memberships[0]->get_user_id() ); |
| 3472 | |
| 3473 | $context['response_type'] = 'live'; |
| 3474 | } |
| 3475 | |
| 3476 | $context['pluggable_data'] = array_merge( $user_data, $membership_data ); |
| 3477 | |
| 3478 | return $context; |
| 3479 | } |
| 3480 | |
| 3481 | /** |
| 3482 | * Get last data for trigger |
| 3483 | * |
| 3484 | * @param array $data data. |
| 3485 | * @return array |
| 3486 | */ |
| 3487 | public function search_events_calendar_triggers_last_data( $data ) { |
| 3488 | $context = []; |
| 3489 | $context['response_type'] = 'sample'; |
| 3490 | |
| 3491 | $event_data = [ |
| 3492 | 'event' => [ |
| 3493 | 'ID' => 58, |
| 3494 | 'post_author' => 1, |
| 3495 | 'post_date' => '2023-01-19 09:27:58', |
| 3496 | 'post_date_gmt' => '2023-01-19 09:27:58', |
| 3497 | 'post_content' => '', |
| 3498 | 'post_title' => 'New event', |
| 3499 | 'post_excerpt' => '', |
| 3500 | 'post_status' => 'publish', |
| 3501 | 'comment_status' => 'open', |
| 3502 | 'ping_status' => 'closed', |
| 3503 | 'post_password' => '', |
| 3504 | 'post_name' => 'new-event', |
| 3505 | 'to_ping' => '', |
| 3506 | 'pinged' => '', |
| 3507 | 'post_modified' => '2023-01-19 09:44:25', |
| 3508 | 'post_modified_gmt' => '2023-01-19 09:44:25', |
| 3509 | 'post_content_filtered' => '', |
| 3510 | 'post_parent' => 0, |
| 3511 | 'guid' => 'http://connector.com/?post_type=tribe_events&p=58', |
| 3512 | 'menu_order' => -1, |
| 3513 | 'post_type' => 'tribe_events', |
| 3514 | 'post_mime_type' => '', |
| 3515 | 'comment_count' => 0, |
| 3516 | 'filter' => 'raw', |
| 3517 | ], |
| 3518 | 'attendies' => [ |
| 3519 | 'order_id' => 68, |
| 3520 | 'purchaser_name' => 'sapna Rana', |
| 3521 | 'purchaser_email' => 'sapnar@bsf.io', |
| 3522 | 'provider' => 'Tribe__Tickets__RSVP', |
| 3523 | 'provider_slug' => 'rsvp', |
| 3524 | 'purchase_time' => '2023-01-19 09:48:43', |
| 3525 | 'optout' => 1, |
| 3526 | 'ticket' => 'Prime', |
| 3527 | 'attendee_id' => 68, |
| 3528 | 'security' => '2cefc3b53e', |
| 3529 | 'product_id' => 65, |
| 3530 | 'check_in' => '', |
| 3531 | 'order_status' => 'yes', |
| 3532 | 'order_status_label' => 'Going', |
| 3533 | 'user_id' => 1, |
| 3534 | 'ticket_sent' => 1, |
| 3535 | 'event_id' => 58, |
| 3536 | 'ticket_name' => 'Prime', |
| 3537 | 'holder_name' => 'sapna Rana', |
| 3538 | 'holder_email' => 'sapnar@bsf.io', |
| 3539 | 'ticket_id' => 68, |
| 3540 | 'qr_ticket_id' => 68, |
| 3541 | 'security_code' => '2cefc3b53e', |
| 3542 | 'attendee_meta' => '', |
| 3543 | 'is_subscribed' => '', |
| 3544 | 'is_purchaser' => 1, |
| 3545 | 'ticket_exists' => 1, |
| 3546 | ], |
| 3547 | ]; |
| 3548 | |
| 3549 | $event_id = (int) ( isset( $data['filter']['event_id']['value'] ) ? $data['filter']['event_id']['value'] : '-1' ); |
| 3550 | |
| 3551 | $args = [ |
| 3552 | 'post_type' => 'tribe_rsvp_attendees', |
| 3553 | 'orderby' => 'ID', |
| 3554 | 'order' => 'DESC', |
| 3555 | 'post_status' => 'publish', |
| 3556 | 'numberposts' => 1, |
| 3557 | ]; |
| 3558 | |
| 3559 | if ( -1 !== $event_id ) { |
| 3560 | $args['meta_query'] = [ |
| 3561 | [ |
| 3562 | 'key' => '_tribe_rsvp_event', |
| 3563 | 'value' => $event_id, |
| 3564 | ], |
| 3565 | ]; |
| 3566 | } |
| 3567 | |
| 3568 | $attendees = get_posts( $args ); |
| 3569 | |
| 3570 | if ( count( $attendees ) > 0 ) { |
| 3571 | $attendee = $attendees[0]; |
| 3572 | $attendee_id = $attendee->ID; |
| 3573 | |
| 3574 | $product_id = get_post_meta( $attendee_id, '_tribe_rsvp_product', true ); |
| 3575 | $order_id = get_post_meta( $attendee_id, '_tribe_rsvp_order', true ); |
| 3576 | |
| 3577 | $event_data = TheEventCalendar::get_event_context( $product_id, $order_id ); |
| 3578 | $context['response_type'] = 'live'; |
| 3579 | } |
| 3580 | |
| 3581 | $context['pluggable_data'] = $event_data; |
| 3582 | |
| 3583 | return $context; |
| 3584 | } |
| 3585 | |
| 3586 | /** |
| 3587 | * Get last data for trigger |
| 3588 | * |
| 3589 | * @param array $data data. |
| 3590 | * @return array |
| 3591 | */ |
| 3592 | public function search_woo_commerce_triggers_last_data( $data ) { |
| 3593 | $context = []; |
| 3594 | $context['response_type'] = 'sample'; |
| 3595 | $user_data = WordPress::get_sample_user_context(); |
| 3596 | |
| 3597 | $product_data['product'] = [ |
| 3598 | 'id' => '169', |
| 3599 | 'name' => 'Sample Product', |
| 3600 | 'description' => 'This is description of sample product.', |
| 3601 | 'short_description' => 'This is short description of sample product.', |
| 3602 | 'image_url' => SURE_TRIGGERS_URL . 'assets/images/sample.svg', |
| 3603 | 'slug' => 'sample-product', |
| 3604 | 'status' => 'publish', |
| 3605 | 'type' => 'simple', |
| 3606 | 'price' => '89', |
| 3607 | 'featured' => '0', |
| 3608 | 'sku' => 'hoodie-blue-sm', |
| 3609 | 'regular_price' => '90', |
| 3610 | 'sale_price' => '89', |
| 3611 | 'total_sales' => '21', |
| 3612 | 'category' => 'Uncategorized', |
| 3613 | 'tags' => 'sample, new, 2022', |
| 3614 | ]; |
| 3615 | |
| 3616 | $comment_data = [ |
| 3617 | 'comment_id' => '1', |
| 3618 | 'comment' => 'This is a sample comment..!', |
| 3619 | ]; |
| 3620 | |
| 3621 | $order_data = [ |
| 3622 | 'order_id' => '500', |
| 3623 | 'total_order_value' => '45', |
| 3624 | 'currency' => 'USD', |
| 3625 | 'shipping_total' => '5', |
| 3626 | 'order_payment_method' => 'cod', |
| 3627 | 'billing_firstname' => 'John', |
| 3628 | 'billing_lastname' => 'Doe', |
| 3629 | 'billing_company' => 'BSF', |
| 3630 | 'billing_address_1' => '1004 Beaumont', |
| 3631 | 'billing_address_2' => '', |
| 3632 | 'billing_city' => 'Casper', |
| 3633 | 'billing_state' => 'Wyoming', |
| 3634 | 'billing_postcode' => '82601', |
| 3635 | 'billing_country' => 'US', |
| 3636 | 'billing_email' => 'john_doe@bsf.io', |
| 3637 | 'billing_phone' => '(307) 7626541', |
| 3638 | 'shipping_firstname' => 'John', |
| 3639 | 'shipping_lastname' => 'Doe', |
| 3640 | 'shipping_company' => 'BSF', |
| 3641 | 'shipping_address_1' => '1004 Beaumont', |
| 3642 | 'shipping_address_2' => '', |
| 3643 | 'shipping_city' => 'Casper', |
| 3644 | 'shipping_state' => 'Wyoming', |
| 3645 | 'shipping_postcode' => '82601', |
| 3646 | 'shipping_country' => 'US', |
| 3647 | 'coupon_codes' => 'e3mstekq, f24sjakb', |
| 3648 | 'total_items_in_order' => '1', |
| 3649 | 'user_id' => '1', |
| 3650 | ]; |
| 3651 | |
| 3652 | $variation_data = [ |
| 3653 | 'product_variation_id' => '626', |
| 3654 | 'product_variation' => 'Color: Silver', |
| 3655 | ]; |
| 3656 | |
| 3657 | $order_sample_data = json_decode( '{"id":37,"parent_id":0,"status":"processing","currency":"USD","version":"7.3.0","prices_include_tax":false,"date_created":{"date":"2023-01-18 08:00:49.000000","timezone_type":1,"timezone":"+00:00"},"date_modified":{"date":"2023-01-18 08:00:50.000000","timezone_type":1,"timezone":"+00:00"},"discount_total":"0","discount_tax":"0","shipping_total":"0","shipping_tax":"0","cart_tax":"0","total":"22.00","total_tax":"0","customer_id":1,"order_key":"wc_order_VdLfjJ9vP7pDs","billing":{"first_name":"John","last_name":"Rana","company":"","address_1":"test","address_2":"","city":"Mohali","state":"AL","postcode":"12344","country":"US","email":"test@example.com","phone":"13232323"},"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":"::1","customer_user_agent":"Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/108.0.0.0 Safari\/537.36","created_via":"checkout","customer_note":"","date_completed":null,"date_paid":null,"cart_hash":"10b8e2799df0f88e1506edc0f3ed99c9","order_stock_reduced":true,"download_permissions_granted":true,"new_order_email_sent":true,"recorded_sales":true,"recorded_coupon_usage_counts":true,"number":"37","meta_data":[{"id":204,"key":"is_vat_exempt","value":"no"}],"line_items":{"id":"2, 3","order_id":"37, 37","name":"Variable product - Red, Test product","product_id":"34, 31","variation_id":"35, 0","quantity":"1, 1","tax_class":", ","subtotal":"12, 10","subtotal_tax":"0, 0","total":"12, 10","total_tax":"0, 0","taxes":", ","meta_data":", "},"tax_lines":[],"shipping_lines":[],"fee_lines":[],"coupon_lines":[],"products":[{"id":2,"order_id":37,"name":"Variable product - Red","product_id":34,"variation_id":35,"quantity":1,"tax_class":"","subtotal":"12","subtotal_tax":"0","total":"12","total_tax":"0","taxes":{"total":[],"subtotal":[]},"meta_data":{"19":{"key":"color","value":"Red","display_key":"Color","display_value":"<p>Red<\/p>\n"}}},{"id":3,"order_id":37,"name":"Test product","product_id":31,"variation_id":0,"quantity":1,"tax_class":"","subtotal":"10","subtotal_tax":"0","total":"10","total_tax":"0","taxes":{"total":[],"subtotal":[]},"meta_data":[]}],"quantity":"1, 1","wp_user_id":1,"user_login":"john","display_name":"john smith","user_firstname":"John","user_lastname":"Smith","user_email":"test@example.com","user_role":["subscriber"]}', true ); //phpcs:ignore |
| 3658 | |
| 3659 | $product_id = (int) ( isset( $data['filter']['product_id']['value'] ) ? $data['filter']['product_id']['value'] : -1 ); |
| 3660 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3661 | |
| 3662 | if ( in_array( $term, [ 'product_added_to_cart', 'product_viewed' ], true ) ) { |
| 3663 | if ( -1 === $product_id ) { |
| 3664 | $args = [ |
| 3665 | 'post_type' => 'product', |
| 3666 | 'orderby' => 'ID', |
| 3667 | 'order' => 'DESC', |
| 3668 | 'post_status' => 'publish', |
| 3669 | 'numberposts' => 1, |
| 3670 | ]; |
| 3671 | $products = get_posts( $args ); |
| 3672 | |
| 3673 | if ( count( $products ) > 0 ) { |
| 3674 | $product_id = $products[0]->ID; |
| 3675 | } |
| 3676 | } |
| 3677 | |
| 3678 | if ( -1 !== $product_id ) { |
| 3679 | $post = get_post( $product_id ); |
| 3680 | $user_data = WordPress::get_user_context( $post->post_author ); |
| 3681 | $product_data['product_id'] = $product_id; |
| 3682 | $product_data['product'] = WooCommerce::get_product_context( $product_id ); |
| 3683 | unset( $product_data['product']['id'] ); //phpcs:ignore |
| 3684 | $context['response_type'] = 'live'; |
| 3685 | } |
| 3686 | |
| 3687 | if ( 'product_added_to_cart' === $term ) { |
| 3688 | $product_data['product_quantity'] = 1; |
| 3689 | } |
| 3690 | |
| 3691 | $context['pluggable_data'] = array_merge( $product_data, $user_data ); |
| 3692 | |
| 3693 | } elseif ( 'product_reviewed' === $term ) { |
| 3694 | $comment_args = [ |
| 3695 | 'number' => 1, |
| 3696 | 'type' => 'review', |
| 3697 | 'orderby' => 'comment_ID', |
| 3698 | 'post_id' => -1 !== $product_id ? $product_id : 0, |
| 3699 | ]; |
| 3700 | |
| 3701 | $comments = get_comments( $comment_args ); |
| 3702 | |
| 3703 | if ( count( $comments ) > 0 ) { |
| 3704 | $comment = $comments[0]; |
| 3705 | $comment_data = [ |
| 3706 | 'comment_id' => $comment->comment_ID, |
| 3707 | 'comment' => $comment->comment_content, |
| 3708 | ]; |
| 3709 | $product_data = WooCommerce::get_product_context( $comment->comment_post_ID ); |
| 3710 | $user_data = WordPress::get_user_context( $comment->user_id ); |
| 3711 | $context['response_type'] = 'live'; |
| 3712 | } |
| 3713 | |
| 3714 | $context['pluggable_data'] = array_merge( $product_data, $user_data, $comment_data ); |
| 3715 | |
| 3716 | } elseif ( 'product_purchased' === $term ) { |
| 3717 | $order_id = 0; |
| 3718 | $product_data['quantity'] = '1'; |
| 3719 | if ( -1 !== $product_id ) { |
| 3720 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 3721 | if ( count( $order_ids ) > 0 ) { |
| 3722 | $order_id = $order_ids[0]; |
| 3723 | } |
| 3724 | } else { |
| 3725 | $orders = wc_get_orders( [ 'numberposts' => 1 ] ); |
| 3726 | if ( count( $orders ) > 0 ) { |
| 3727 | $order_id = $orders[0]->get_id(); |
| 3728 | } |
| 3729 | } |
| 3730 | |
| 3731 | if ( 0 !== $order_id ) { |
| 3732 | $order = wc_get_order( $order_id ); |
| 3733 | |
| 3734 | if ( $order ) { |
| 3735 | $user_id = $order->get_customer_id(); |
| 3736 | $items = $order->get_items(); |
| 3737 | |
| 3738 | $product_ids = []; |
| 3739 | |
| 3740 | $iteration = 0; |
| 3741 | foreach ( $items as $item ) { |
| 3742 | $item_id = $item->get_product_id(); |
| 3743 | |
| 3744 | if ( -1 === $product_id && 0 === $iteration ) { |
| 3745 | $product_ids[] = $item_id; |
| 3746 | break; |
| 3747 | } elseif ( $item_id === $product_id ) { |
| 3748 | $product_ids[] = $item_id; |
| 3749 | break; |
| 3750 | } |
| 3751 | |
| 3752 | $iteration++; |
| 3753 | } |
| 3754 | $order_data = WooCommerce::get_order_context( $order_id ); |
| 3755 | $user_data = WordPress::get_user_context( $user_id ); |
| 3756 | $order_data['total_items_in_order'] = count( $product_ids ); |
| 3757 | |
| 3758 | $context['response_type'] = 'live'; |
| 3759 | } |
| 3760 | } |
| 3761 | |
| 3762 | $context['pluggable_data'] = array_merge( $order_data, $product_data, $user_data ); |
| 3763 | |
| 3764 | } elseif ( 'variable_product_purchased' === $term ) { |
| 3765 | $product_variation_id = (int) ( isset( $data['filter']['product_variation_id']['value'] ) ? $data['filter']['product_variation_id']['value'] : -1 ); |
| 3766 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 3767 | |
| 3768 | foreach ( $order_ids as $order_id ) { |
| 3769 | $order = wc_get_order( $order_id ); |
| 3770 | |
| 3771 | if ( $order ) { |
| 3772 | $user_id = $order->get_customer_id(); |
| 3773 | $items = $order->get_items(); |
| 3774 | $product_variations = []; |
| 3775 | |
| 3776 | $iteration = 0; |
| 3777 | foreach ( $items as $item ) { |
| 3778 | $variation_id = $item->get_variation_id(); |
| 3779 | |
| 3780 | if ( -1 === $product_variation_id && 0 === $iteration ) { |
| 3781 | $product_variations[] = $variation_id; |
| 3782 | break; |
| 3783 | } elseif ( $variation_id === $product_variation_id ) { |
| 3784 | $product_variations[] = $variation_id; |
| 3785 | break; |
| 3786 | } |
| 3787 | |
| 3788 | $iteration++; |
| 3789 | } |
| 3790 | |
| 3791 | if ( count( $product_variations ) > 0 ) { |
| 3792 | $product_data = WooCommerce::get_product_context( $product_variation_id ); |
| 3793 | $order_data = WooCommerce::get_order_context( $order_id ); |
| 3794 | $user_data = WordPress::get_user_context( $user_id ); |
| 3795 | $variation_data = [ |
| 3796 | 'product_variation_id' => $product_variations[0], |
| 3797 | 'product_variation' => get_the_excerpt( $product_variations[0] ), |
| 3798 | ]; |
| 3799 | |
| 3800 | $context['response_type'] = 'live'; |
| 3801 | break; |
| 3802 | } |
| 3803 | } |
| 3804 | } |
| 3805 | |
| 3806 | $context['pluggable_data'] = array_merge( $order_data, $user_data, $variation_data ); |
| 3807 | |
| 3808 | } elseif ( 'variable_subscription_purchased' === $term ) { |
| 3809 | $product_data['quantity'] = '1'; |
| 3810 | $product_data['product_name'] = 'Sample Product'; |
| 3811 | $product_data['billing_period'] = '2021-2022'; |
| 3812 | |
| 3813 | $context['pluggable_data'] = array_merge( $order_data, $product_data, $user_data ); |
| 3814 | |
| 3815 | $subscription_order_id = 0; |
| 3816 | $order_ids = []; |
| 3817 | |
| 3818 | if ( -1 !== $product_id ) { |
| 3819 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 3820 | |
| 3821 | } else { |
| 3822 | $orders = wc_get_orders( [] ); |
| 3823 | if ( count( $orders ) > 0 ) { |
| 3824 | $order_ids[] = $orders[0]->get_id(); |
| 3825 | } |
| 3826 | } |
| 3827 | |
| 3828 | foreach ( $order_ids as $order_id ) { |
| 3829 | $query_args = [ |
| 3830 | 'post_type' => 'shop_subscription', |
| 3831 | 'orderby' => 'ID', |
| 3832 | 'order' => 'DESC', |
| 3833 | 'post_status' => 'wc-active', |
| 3834 | 'posts_per_page' => 1, |
| 3835 | 'post_parent' => $order_id, |
| 3836 | ]; |
| 3837 | $query_result = new WP_Query( $query_args ); |
| 3838 | $subscription_orders = $query_result->get_posts(); |
| 3839 | |
| 3840 | if ( count( $subscription_orders ) > 0 ) { |
| 3841 | $subscription_order_id = $subscription_orders[0]->ID; |
| 3842 | break; |
| 3843 | } |
| 3844 | } |
| 3845 | |
| 3846 | if ( 0 !== $subscription_order_id ) { |
| 3847 | $subscription = wcs_get_subscription( $subscription_order_id ); |
| 3848 | if ( $subscription instanceof WC_Subscription ) { |
| 3849 | $last_order_id = $subscription->get_last_order(); |
| 3850 | if ( ! empty( $last_order_id ) && $last_order_id === $subscription->get_parent_id() ) { |
| 3851 | $user_id = wc_get_order( $last_order_id )->get_customer_id(); |
| 3852 | $items = $subscription->get_items(); |
| 3853 | |
| 3854 | foreach ( $items as $item ) { |
| 3855 | $product = $item->get_product(); |
| 3856 | if ( class_exists( '\WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $product ) ) { |
| 3857 | if ( $product->is_type( [ 'subscription', 'subscription_variation', 'variable-subscription' ] ) ) { |
| 3858 | |
| 3859 | $product_data = WooCommerce::get_variable_subscription_product_context( $item, $last_order_id ); |
| 3860 | $user_data = WordPress::get_user_context( $user_id ); |
| 3861 | |
| 3862 | $context['response_type'] = 'live'; |
| 3863 | $context['pluggable_data'] = array_merge( $product_data, $user_data ); |
| 3864 | } |
| 3865 | } |
| 3866 | } |
| 3867 | } |
| 3868 | } |
| 3869 | } |
| 3870 | } elseif ( 'order_created' === $term ) { |
| 3871 | $orders = wc_get_orders( [ 'numberposts' => 1 ] ); |
| 3872 | if ( count( $orders ) > 0 ) { |
| 3873 | $order_id = $orders[0]->get_id(); |
| 3874 | } |
| 3875 | $order = wc_get_order( $order_id ); |
| 3876 | $user_id = $order->get_customer_id(); |
| 3877 | $order_sample_data = array_merge( |
| 3878 | WooCommerce::get_order_context( $order_id ), |
| 3879 | WordPress::get_user_context( $user_id ) |
| 3880 | ); |
| 3881 | $context['response_type'] = 'live'; |
| 3882 | $context['pluggable_data'] = $order_sample_data; |
| 3883 | |
| 3884 | } |
| 3885 | |
| 3886 | return $context; |
| 3887 | } |
| 3888 | |
| 3889 | /** |
| 3890 | * Search LMS data. |
| 3891 | * |
| 3892 | * @param array $data data. |
| 3893 | * @return array |
| 3894 | */ |
| 3895 | public function search_lifter_lms_last_data( $data ) { |
| 3896 | global $wpdb; |
| 3897 | $post_type = $data['post_type']; |
| 3898 | $meta_key = '_is_complete'; |
| 3899 | $trigger = $data['search_term']; |
| 3900 | $context = []; |
| 3901 | if ( 'lifterlms_purchase_course' === $trigger ) { |
| 3902 | $product_type = 'course'; |
| 3903 | $post_id = $data['filter']['course_id']['value']; |
| 3904 | } elseif ( 'lifterlms_purchase_membership' === $trigger ) { |
| 3905 | $product_type = 'membership'; |
| 3906 | $post_id = $data['filter']['membership_id']['value']; |
| 3907 | } elseif ( 'lifterlms_lesson_completed' === $trigger ) { |
| 3908 | $post_id = $data['filter']['lesson']['value']; |
| 3909 | } elseif ( 'lifterlms_course_completed' === $trigger ) { |
| 3910 | $post_id = $data['filter']['course']['value']; |
| 3911 | } |
| 3912 | |
| 3913 | $where = 'postmeta.post_id = "' . $post_id . '" AND'; |
| 3914 | |
| 3915 | if ( 'llms_order' === $post_type ) { |
| 3916 | if ( -1 === $post_id ) { |
| 3917 | $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 ='llms_order' AND posts.post_status= 'llms-completed' AND postmeta.meta_value=%s AND postmeta.meta_key= '_llms_product_type'", $product_type ) ); |
| 3918 | } else { |
| 3919 | $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 ='llms_order' AND posts.post_status= 'llms-completed' AND postmeta.meta_value=%s AND postmeta.meta_key= '_llms_product_id'", $post_id ) ); |
| 3920 | } |
| 3921 | } else { |
| 3922 | if ( -1 === $post_id ) { |
| 3923 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}lifterlms_user_postmeta as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.post_id WHERE postmeta.meta_value='yes' AND postmeta.meta_key=%s AND posts.post_type=%s", $meta_key, $post_type ) ); |
| 3924 | } else { |
| 3925 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}lifterlms_user_postmeta as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.post_id WHERE postmeta.post_id = %s AND postmeta.meta_value='yes' AND postmeta.meta_key=%s AND posts.post_type=%s", $post_id, $meta_key, $post_type ) ); |
| 3926 | } |
| 3927 | } |
| 3928 | |
| 3929 | $response = []; |
| 3930 | if ( ! empty( $result ) ) { |
| 3931 | $result_post_id = $result[0]->post_id; |
| 3932 | $result_user_id = $result[0]->user_id; |
| 3933 | |
| 3934 | switch ( $trigger ) { |
| 3935 | case 'lifterlms_lesson_completed': |
| 3936 | $context = array_merge( |
| 3937 | WordPress::get_user_context( $result_user_id ), |
| 3938 | LifterLMS::get_lms_lesson_context( $result_post_id ) |
| 3939 | ); |
| 3940 | |
| 3941 | $context['course'] = get_the_title( get_post_meta( $result_post_id, '_llms_parent_course', true ) ); |
| 3942 | if ( '' !== ( get_post_meta( $result_post_id, '_llms_parent_section', true ) ) ) { |
| 3943 | $context['parent_section'] = get_the_title( get_post_meta( $result_post_id, '_llms_parent_section', true ) ); |
| 3944 | } |
| 3945 | break; |
| 3946 | case 'lifterlms_course_completed': |
| 3947 | $context = array_merge( |
| 3948 | WordPress::get_user_context( $result_user_id ), |
| 3949 | LifterLMS::get_lms_course_context( $result_post_id ) |
| 3950 | ); |
| 3951 | break; |
| 3952 | case 'lifterlms_purchase_course': |
| 3953 | $user_id = get_post_meta( $result_post_id, '_llms_user_id', true ); |
| 3954 | $context['course_id'] = get_post_meta( $result_post_id, '_llms_product_id', true ); |
| 3955 | $context['course_name'] = get_post_meta( $result_post_id, '_llms_product_title', true ); |
| 3956 | $context['course_amount'] = get_post_meta( $result_post_id, '_llms_original_total', true ); |
| 3957 | $context['currency'] = get_post_meta( $result_post_id, '_llms_currency', true ); |
| 3958 | $context ['order'] = WordPress::get_post_context( $result_post_id ); |
| 3959 | $context['order_type'] = get_post_meta( $result_post_id, '_llms_order_type', true ); |
| 3960 | $context['trial_offer'] = get_post_meta( $result_post_id, '_llms_trial_offer', true ); |
| 3961 | $context['billing_frequency'] = get_post_meta( $result_post_id, '_llms_billing_frequency', true ); |
| 3962 | $context = array_merge( $context, WordPress::get_user_context( $user_id ) ); |
| 3963 | break; |
| 3964 | case 'lifterlms_purchase_membership': |
| 3965 | $user_id = get_post_meta( $result_post_id, '_llms_user_id', true ); |
| 3966 | $context['membership_id'] = get_post_meta( $result_post_id, '_llms_product_id', true ); |
| 3967 | $context['membership_name'] = get_post_meta( $result_post_id, '_llms_product_title', true ); |
| 3968 | $context['membership_amount'] = get_post_meta( $result_post_id, '_llms_original_total', true ); |
| 3969 | $context['currency'] = get_post_meta( $result_post_id, '_llms_currency', true ); |
| 3970 | $context ['order'] = WordPress::get_post_context( $result_post_id ); |
| 3971 | $context['order_type'] = get_post_meta( $result_post_id, '_llms_order_type', true ); |
| 3972 | $context['trial_offer'] = get_post_meta( $result_post_id, '_llms_trial_offer', true ); |
| 3973 | $context['billing_frequency'] = get_post_meta( $result_post_id, '_llms_billing_frequency', true ); |
| 3974 | $context = array_merge( $context, WordPress::get_user_context( $user_id ) ); |
| 3975 | break; |
| 3976 | default: |
| 3977 | return; |
| 3978 | |
| 3979 | } |
| 3980 | $response['pluggable_data'] = $context; |
| 3981 | $response['response_type'] = 'live'; |
| 3982 | |
| 3983 | } |
| 3984 | |
| 3985 | return $response; |
| 3986 | |
| 3987 | } |
| 3988 | |
| 3989 | /** |
| 3990 | * Search SM data. |
| 3991 | * |
| 3992 | * @param array $data data. |
| 3993 | * @return array |
| 3994 | */ |
| 3995 | public function search_suremember_last_data( $data ) { |
| 3996 | global $wpdb; |
| 3997 | $post_type = $data['post_type']; |
| 3998 | $meta_key = '_is_complete'; |
| 3999 | $trigger = $data['search_term']; |
| 4000 | $post_id = $data['filter']['group_id']['value']; |
| 4001 | |
| 4002 | if ( 'suremember_updated_group' === $trigger ) { |
| 4003 | if ( -1 === $post_id ) { |
| 4004 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts WHERE posts.post_type=%s", $post_type ) ); |
| 4005 | } else { |
| 4006 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts WHERE posts.ID=%s AND posts.post_type=%s", $post_id, $post_type ) ); |
| 4007 | } |
| 4008 | } else { |
| 4009 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usermeta as usermeta WHERE usermeta.meta_key = %s", 'suremembers_user_access_group_' . $post_id ) ); |
| 4010 | } |
| 4011 | |
| 4012 | $response = []; |
| 4013 | |
| 4014 | if ( ! empty( $result ) ) { |
| 4015 | $context = []; |
| 4016 | switch ( $trigger ) { |
| 4017 | case 'suremember_updated_group': |
| 4018 | $group_id = $result[0]->ID; |
| 4019 | $suremembers_post['rules'] = get_post_meta( $group_id, 'suremembers_plan_include', true ); |
| 4020 | $suremembers_post['exclude'] = get_post_meta( $group_id, 'suremembers_plan_exclude', true ); //phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude |
| 4021 | $suremembers_post['suremembers_user_roles'] = get_post_meta( $group_id, 'suremembers_user_roles', true ); |
| 4022 | $suremembers_post['title'] = get_the_title( $group_id ); |
| 4023 | $suremembers_post['restrict'] = get_post_meta( $group_id, 'suremembers_plan_rules', true )['restrict']; |
| 4024 | $context['group'] = array_merge( WordPress::get_post_context( $group_id ), $suremembers_post ); |
| 4025 | $context['group_id'] = $group_id; |
| 4026 | unset( $context['group']['ID'] ); |
| 4027 | $response['pluggable_data'] = $context; |
| 4028 | $response['response_type'] = 'live'; |
| 4029 | break; |
| 4030 | case 'suremember_user_added_in_group': |
| 4031 | foreach ( $result as $res ) { |
| 4032 | $meta_value = unserialize( $res->meta_value ); |
| 4033 | if ( 'active' === $meta_value['status'] ) { |
| 4034 | $context = WordPress::get_user_context( $res->user_id ); |
| 4035 | $context['group'] = WordPress::get_post_context( $post_id ); |
| 4036 | $response['pluggable_data'] = $context; |
| 4037 | $response['response_type'] = 'live'; |
| 4038 | } |
| 4039 | } |
| 4040 | break; |
| 4041 | case 'suremember_user_removed_from_group': |
| 4042 | foreach ( $result as $res ) { |
| 4043 | $meta_value = unserialize( $res->meta_value ); |
| 4044 | if ( 'revoked' === $meta_value['status'] ) { |
| 4045 | $context = WordPress::get_user_context( $res->user_id ); |
| 4046 | $context['group'] = WordPress::get_post_context( $post_id ); |
| 4047 | $response['pluggable_data'] = $context; |
| 4048 | $response['response_type'] = 'live'; |
| 4049 | } |
| 4050 | } |
| 4051 | break; |
| 4052 | default: |
| 4053 | return; |
| 4054 | |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | return $response; |
| 4059 | |
| 4060 | } |
| 4061 | |
| 4062 | /** |
| 4063 | * Search CartFlows data. |
| 4064 | * |
| 4065 | * @param array $data data. |
| 4066 | * @return array |
| 4067 | */ |
| 4068 | public function search_cartflows_last_data( $data ) { |
| 4069 | global $wpdb; |
| 4070 | $trigger = $data['search_term']; |
| 4071 | $context = []; |
| 4072 | if ( 'cartflows_offer_accepted' === $trigger ) { |
| 4073 | $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 ='shop_order' AND postmeta.meta_value='upsell' AND postmeta.meta_key= '_cartflows_offer_type'" ); |
| 4074 | } |
| 4075 | $response = []; |
| 4076 | if ( ! empty( $result ) ) { |
| 4077 | $context = []; |
| 4078 | $order_upsell_id = $result[0]->post_id; |
| 4079 | $step_id = get_post_meta( $order_upsell_id, '_cartflows_offer_step_id', true ); |
| 4080 | $order_id = get_post_meta( $order_upsell_id, '_cartflows_offer_parent_id', true ); |
| 4081 | $order = wc_get_order( $order_id ); |
| 4082 | $upsell_order = wc_get_order( $order_upsell_id ); |
| 4083 | $variation_id = $upsell_order->get_items()[0]['product_id']; |
| 4084 | $input_qty = $upsell_order->get_items()[0]['quantity']; |
| 4085 | $offer_product = wcf_pro()->utils->get_offer_data( $step_id, $variation_id, $input_qty, $order_id ); |
| 4086 | $user_id = get_post_meta( $order_upsell_id, '_customer_user', true ); |
| 4087 | $context = WordPress::get_user_context( $user_id ); |
| 4088 | $context['order'] = $order->get_data(); |
| 4089 | $context['upsell'] = $offer_product; |
| 4090 | $response['pluggable_data'] = $context; |
| 4091 | $response['response_type'] = 'live'; |
| 4092 | } |
| 4093 | |
| 4094 | return $response; |
| 4095 | |
| 4096 | } |
| 4097 | |
| 4098 | |
| 4099 | /** |
| 4100 | * Fetch user context. |
| 4101 | * |
| 4102 | * @param int $initiator_id initiator id. |
| 4103 | * @param int $friend_id friend id. |
| 4104 | * @return array |
| 4105 | */ |
| 4106 | public function get_user_context( $initiator_id, $friend_id ) { |
| 4107 | $context = WordPress::get_user_context( $initiator_id ); |
| 4108 | |
| 4109 | $friend_context = WordPress::get_user_context( $friend_id ); |
| 4110 | |
| 4111 | $avatar = get_avatar_url( $initiator_id ); |
| 4112 | |
| 4113 | $context['avatar_url'] = ( $avatar ) ? $avatar : ''; |
| 4114 | |
| 4115 | $context['friend_id'] = $friend_id; |
| 4116 | $context['friend_first_name'] = $friend_context['user_firstname']; |
| 4117 | $context['friend_last_name'] = $friend_context['user_lastname']; |
| 4118 | $context['friend_email'] = $friend_context['user_email']; |
| 4119 | |
| 4120 | $friend_avatar = get_avatar_url( $friend_id ); |
| 4121 | $context['friend_avatar_url'] = $friend_avatar; |
| 4122 | return $context; |
| 4123 | } |
| 4124 | |
| 4125 | /** |
| 4126 | * Search BP data. |
| 4127 | * |
| 4128 | * @param array $data data. |
| 4129 | * @return array |
| 4130 | */ |
| 4131 | public function search_pluggables_bp_friendships( $data ) { |
| 4132 | global $wpdb, $bp; |
| 4133 | $context = []; |
| 4134 | $sample['pluggable_data'] = [ |
| 4135 | 'wp_user_id' => 4, |
| 4136 | 'user_login' => 'katy1ßßßß', |
| 4137 | 'display_name' => 'Katy Smith', |
| 4138 | 'user_firstname' => 'Katy', |
| 4139 | 'user_lastname' => 'Smith', |
| 4140 | 'user_email' => 'katy1@gmail.com', |
| 4141 | 'user_role' => [ 'subscriber' ], |
| 4142 | 'avatar_url' => 'http://pqr.com/avatar', |
| 4143 | 'friend_id' => 1, |
| 4144 | 'friend_first_name' => 'John', |
| 4145 | 'friend_last_name' => 'Wick', |
| 4146 | 'friend_email' => 'john@gmail.com', |
| 4147 | 'friend_avatar_url' => 'http://abc.com/avatar', |
| 4148 | ]; |
| 4149 | $sample['response_type'] = 'sample'; |
| 4150 | |
| 4151 | $table_exists = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}bp_friends'" ); |
| 4152 | if ( $table_exists ) { |
| 4153 | $friendships = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_friends LIMIT 1" ); |
| 4154 | if ( ! empty( $friendships ) ) { |
| 4155 | $friendship = $friendships[0]; |
| 4156 | $initiator_id = $friendship['initiator_user_id']; |
| 4157 | $friend_user_id = $friendship['friend_user_id']; |
| 4158 | $context['pluggable_data'] = $this->get_user_context( $initiator_id, $friend_user_id ); |
| 4159 | $context['response_type'] = 'live'; |
| 4160 | } else { |
| 4161 | $context = $sample; |
| 4162 | } |
| 4163 | } else { |
| 4164 | $context = $sample; |
| 4165 | } |
| 4166 | |
| 4167 | |
| 4168 | return $context; |
| 4169 | } |
| 4170 | |
| 4171 | /** |
| 4172 | * Search BP data. |
| 4173 | * |
| 4174 | * @param array $data data. |
| 4175 | * @return array |
| 4176 | */ |
| 4177 | public function search_pluggables_bp_groups( $data ) { |
| 4178 | global $wpdb, $bp; |
| 4179 | $context = []; |
| 4180 | $group_data = []; |
| 4181 | $args = [ |
| 4182 | 'orderby' => 'user_nicename', |
| 4183 | 'order' => 'ASC', |
| 4184 | 'number' => 1, |
| 4185 | ]; |
| 4186 | |
| 4187 | $users = get_users( $args ); |
| 4188 | |
| 4189 | if ( isset( $data['filter']['group_id']['value'] ) ) { |
| 4190 | $group_id = $data['filter']['group_id']['value']; |
| 4191 | $args['group_id'] = $group_id; |
| 4192 | if ( $group_id > 0 ) { |
| 4193 | $group = groups_get_group( $group_id ); |
| 4194 | $group_data['group_id'] = ( property_exists( $group, 'id' ) ) ? (int) $group->id : ''; |
| 4195 | $group_data['group_name'] = ( property_exists( $group, 'name' ) ) ? $group->name : ''; |
| 4196 | $group_data['group_description'] = ( property_exists( $group, 'description' ) ) ? $group->description : ''; |
| 4197 | } else { |
| 4198 | $table_exists = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}bp_groups'" ); |
| 4199 | if ( $table_exists ) { |
| 4200 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups LIMIT 1" ); |
| 4201 | $context['groups'] = $groups; |
| 4202 | if ( ! empty( $groups ) ) { |
| 4203 | foreach ( $groups as $group ) { |
| 4204 | $group_data['group_id'] = $group->id; |
| 4205 | $group_data['group_name'] = $group->name; |
| 4206 | $group_data['group_description'] = $group->description; |
| 4207 | } |
| 4208 | } |
| 4209 | } |
| 4210 | } |
| 4211 | } |
| 4212 | |
| 4213 | if ( ! empty( $users ) ) { |
| 4214 | $user = $users[0]; |
| 4215 | $pluggable_data = $group_data; |
| 4216 | |
| 4217 | $avatar = get_avatar_url( $user->ID ); |
| 4218 | $pluggable_data['wp_user_id'] = $user->ID; |
| 4219 | $pluggable_data['avatar_url'] = ( $avatar ) ? $avatar : ''; |
| 4220 | $pluggable_data['user_login'] = $user->user_login; |
| 4221 | $pluggable_data['display_name'] = $user->display_name; |
| 4222 | $pluggable_data['user_firstname'] = $user->user_firstname; |
| 4223 | $pluggable_data['user_lastname'] = $user->user_lastname; |
| 4224 | $pluggable_data['user_email'] = $user->user_email; |
| 4225 | $pluggable_data['user_role'] = $user->roles; |
| 4226 | $context['pluggable_data'] = $pluggable_data; |
| 4227 | $context['response_type'] = 'live'; |
| 4228 | } else { |
| 4229 | $context['pluggable_data'] = [ |
| 4230 | 'wp_user_id' => 1, |
| 4231 | 'user_login' => 'admin', |
| 4232 | 'display_name' => 'Test User', |
| 4233 | 'user_firstname' => 'Test', |
| 4234 | 'user_lastname' => 'User', |
| 4235 | 'user_email' => 'testuser@gmail.com', |
| 4236 | 'user_role' => [ 'subscriber' ], |
| 4237 | 'group_id' => 112, |
| 4238 | 'group_name' => 'Test Group', |
| 4239 | 'group_description' => 'Test Group Description', |
| 4240 | ]; |
| 4241 | $context['response_type'] = 'sample'; |
| 4242 | } |
| 4243 | |
| 4244 | return $context; |
| 4245 | } |
| 4246 | |
| 4247 | /** |
| 4248 | * Search complete courses. |
| 4249 | * |
| 4250 | * @param array $data data. |
| 4251 | * @return array |
| 4252 | */ |
| 4253 | public function search_pluggables_complete_course( $data ) { |
| 4254 | global $wpdb; |
| 4255 | $context = []; |
| 4256 | |
| 4257 | if ( isset( $data['filter']['sfwd_course_id']['value'] ) ) { |
| 4258 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 4259 | } |
| 4260 | if ( -1 === $course_id ) { |
| 4261 | $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 ='course' AND activity.activity_status= %d AND activity.course_id= %d", 1, $course_id ) ); |
| 4262 | } else { |
| 4263 | $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 ='course' AND activity.activity_status= %d AND activity.post_id= %d AND activity.course_id= %d", 1, $course_id, $course_id ) ); |
| 4264 | } |
| 4265 | |
| 4266 | if ( ! empty( $courses ) ) { |
| 4267 | $course = $courses[0]; |
| 4268 | $course_data['course_name'] = $course->post_title; |
| 4269 | $course_data['sfwd_course_id'] = $course->ID; |
| 4270 | $course_data['course_url'] = get_permalink( $course->ID ); |
| 4271 | $course_data['course_featured_image_id'] = get_post_meta( $course->ID, '_thumbnail_id', true ); |
| 4272 | $course_data['course_featured_image_url'] = get_the_post_thumbnail_url( $course->ID ); |
| 4273 | $context['response_type'] = 'live'; |
| 4274 | } else { |
| 4275 | $course_data['course_name'] = 'Test Course'; |
| 4276 | $course_data['sfwd_course_id'] = 112; |
| 4277 | $course_data['course_url'] = 'https://abc.com/test-course'; |
| 4278 | $course_data['course_featured_image_id'] = 113; |
| 4279 | $course_data['course_featured_image_url'] = 'https://pqr.com/test-course-img'; |
| 4280 | $context['response_type'] = 'sample'; |
| 4281 | } |
| 4282 | |
| 4283 | $users_data = $this->search_pluggables_add_user_role( [] ); |
| 4284 | $user_data = $users_data['pluggable_data']; |
| 4285 | |
| 4286 | $context['pluggable_data'] = array_merge( $course_data, $user_data ); |
| 4287 | return $context; |
| 4288 | } |
| 4289 | |
| 4290 | /** |
| 4291 | * Search lessons. |
| 4292 | * |
| 4293 | * @param array $data data. |
| 4294 | * @return array |
| 4295 | */ |
| 4296 | public function search_pluggables_complete_lesson( $data ) { |
| 4297 | global $wpdb; |
| 4298 | $context = []; |
| 4299 | |
| 4300 | if ( isset( $data['filter']['sfwd_lesson_id']['value'] ) ) { |
| 4301 | $lesson_id = $data['filter']['sfwd_lesson_id']['value']; |
| 4302 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 4303 | } |
| 4304 | $course = get_post( $course_id ); |
| 4305 | $pluggable_data = LearnDash::get_course_context( $course ); |
| 4306 | |
| 4307 | if ( -1 === $lesson_id ) { |
| 4308 | $lessons = $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 ='lesson' AND activity.activity_status= %d AND activity.course_id= %d", 1, $course_id ) ); |
| 4309 | } else { |
| 4310 | $lessons = $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 ='lesson' AND activity.activity_status= %d AND activity.post_id= %d AND activity.course_id= %d", 1, $lesson_id, $course_id ) ); |
| 4311 | } |
| 4312 | |
| 4313 | if ( ! empty( $lessons ) ) { |
| 4314 | $lesson = $lessons[0]; |
| 4315 | |
| 4316 | $pluggable_data['lesson_name'] = $lesson->post_title; |
| 4317 | $pluggable_data['sfwd_lesson_id'] = $lesson->ID; |
| 4318 | $pluggable_data['lesson_url'] = get_permalink( $lesson->ID ); |
| 4319 | $pluggable_data['lesson_featured_image_id'] = get_post_meta( $lesson->ID, '_thumbnail_id', true ); |
| 4320 | $pluggable_data['lesson_featured_image_url'] = get_the_post_thumbnail_url( $lesson->ID ); |
| 4321 | $context['response_type'] = 'live'; |
| 4322 | } else { |
| 4323 | $pluggable_data['lesson_name'] = 'Test Lesson'; |
| 4324 | $pluggable_data['sfwd_lesson_id'] = 114; |
| 4325 | $pluggable_data['lesson_url'] = 'https://abc.com/test-lesson'; |
| 4326 | $pluggable_data['lesson_featured_image_id'] = 116; |
| 4327 | $pluggable_data['lesson_featured_image_url'] = 'https://pqr.com/test-lesson-img'; |
| 4328 | $context['response_type'] = 'sample'; |
| 4329 | } |
| 4330 | |
| 4331 | $context['pluggable_data'] = $pluggable_data; |
| 4332 | return $context; |
| 4333 | } |
| 4334 | |
| 4335 | /** |
| 4336 | * Search topics. |
| 4337 | * |
| 4338 | * @param array $data data. |
| 4339 | * @return array |
| 4340 | */ |
| 4341 | public function search_pluggables_complete_topic( $data ) { |
| 4342 | global $wpdb; |
| 4343 | $context = []; |
| 4344 | |
| 4345 | if ( isset( $data['filter']['sfwd_topic_id']['value'] ) ) { |
| 4346 | $topic_id = $data['filter']['sfwd_topic_id']['value']; |
| 4347 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 4348 | } |
| 4349 | $course = get_post( $course_id ); |
| 4350 | $pluggable_data = LearnDash::get_course_context( $course ); |
| 4351 | |
| 4352 | if ( -1 === $topic_id ) { |
| 4353 | $topics = $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 ='topic' AND activity.activity_status= %d AND activity.course_id= %d", 1, $course_id ) ); |
| 4354 | } else { |
| 4355 | $topics = $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 ='topic' AND activity.activity_status= %d AND activity.post_id= %d AND activity.course_id= %d", 1, $topic_id, $course_id ) ); |
| 4356 | } |
| 4357 | |
| 4358 | if ( ! empty( $topics ) ) { |
| 4359 | $topic = $topics[0]; |
| 4360 | |
| 4361 | $pluggable_data['topic_name'] = $topic->post_title; |
| 4362 | $pluggable_data['sfwd_topic_id'] = $topic->ID; |
| 4363 | $pluggable_data['topic_url'] = get_permalink( $topic->ID ); |
| 4364 | $pluggable_data['topic_featured_image_id'] = get_post_meta( $topic->ID, '_thumbnail_id', true ); |
| 4365 | $pluggable_data['topic_featured_image_url'] = get_the_post_thumbnail_url( $topic->ID ); |
| 4366 | $context['response_type'] = 'live'; |
| 4367 | } else { |
| 4368 | $pluggable_data['topic_name'] = 'Test Topic'; |
| 4369 | $pluggable_data['sfwd_topic_id'] = 117; |
| 4370 | $pluggable_data['topic_url'] = 'https://abc.com/test-topic'; |
| 4371 | $pluggable_data['topic_featured_image_id'] = 118; |
| 4372 | $pluggable_data['topic_featured_image_url'] = 'https://pqr.com/test-topic-img'; |
| 4373 | $context['response_type'] = 'sample'; |
| 4374 | } |
| 4375 | |
| 4376 | $context['pluggable_data'] = $pluggable_data; |
| 4377 | return $context; |
| 4378 | } |
| 4379 | |
| 4380 | /** |
| 4381 | * Search purchase courses. |
| 4382 | * |
| 4383 | * @param array $data data. |
| 4384 | * @return array |
| 4385 | */ |
| 4386 | public function search_pluggables_purchase_course( $data ) { |
| 4387 | $context = []; |
| 4388 | $context['response_type'] = 'sample'; |
| 4389 | |
| 4390 | $purchase_data = [ |
| 4391 | 'course_product_id' => '1', |
| 4392 | 'course_product_name' => 'Sample Course', |
| 4393 | 'currency' => 'USD', |
| 4394 | 'total_amount' => '100', |
| 4395 | 'first_name' => 'John', |
| 4396 | 'last_name' => 'Doe', |
| 4397 | 'email' => 'john_doe@bsf.io', |
| 4398 | 'phone' => '+923007626541', |
| 4399 | ]; |
| 4400 | |
| 4401 | $product_id = (int) ( isset( $data['filter']['course_product_id']['value'] ) ? $data['filter']['course_product_id']['value'] : '-1' ); |
| 4402 | $order_id = 0; |
| 4403 | |
| 4404 | if ( -1 !== $product_id ) { |
| 4405 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 4406 | |
| 4407 | if ( count( $order_ids ) > 0 ) { |
| 4408 | $order_id = $order_ids[0]; |
| 4409 | } |
| 4410 | } else { |
| 4411 | $orders = wc_get_orders( [] ); |
| 4412 | if ( count( $orders ) > 0 ) { |
| 4413 | foreach ( $orders as $order ) { |
| 4414 | $items = $order->get_items(); |
| 4415 | |
| 4416 | if ( count( $items ) > 1 ) { |
| 4417 | continue; |
| 4418 | } |
| 4419 | |
| 4420 | foreach ( $items as $item ) { |
| 4421 | if ( ! empty( get_post_meta( $item->get_product_id(), '_related_course', true ) ) ) { |
| 4422 | $order_id = $order->get_id(); |
| 4423 | break; |
| 4424 | } |
| 4425 | } |
| 4426 | } |
| 4427 | } |
| 4428 | } |
| 4429 | |
| 4430 | if ( 0 !== $order_id ) { |
| 4431 | $order = wc_get_order( $order_id ); |
| 4432 | |
| 4433 | if ( $order ) { |
| 4434 | |
| 4435 | $purchase_data = LearnDash::get_purchase_course_context( $order ); |
| 4436 | |
| 4437 | $context['response_type'] = 'live'; |
| 4438 | } |
| 4439 | } |
| 4440 | |
| 4441 | $context['pluggable_data'] = $purchase_data; |
| 4442 | |
| 4443 | return $context; |
| 4444 | } |
| 4445 | |
| 4446 | /** |
| 4447 | * Fetch BB templates. |
| 4448 | * |
| 4449 | * @return array |
| 4450 | */ |
| 4451 | public function get_beaver_builder_templates() { |
| 4452 | $allowed_types = [ 'subscribe-form', 'contact-form' ]; |
| 4453 | $templates = []; |
| 4454 | $all_templates = get_posts( |
| 4455 | [ |
| 4456 | 'post_type' => 'fl-builder-template', |
| 4457 | 'meta_key' => '_fl_builder_data', |
| 4458 | 'posts_per_page' => -1, |
| 4459 | ] |
| 4460 | ); |
| 4461 | $posts = get_posts( |
| 4462 | [ |
| 4463 | 'post_type' => 'any', |
| 4464 | 'meta_key' => '_fl_builder_data', |
| 4465 | 'posts_per_page' => -1, |
| 4466 | ] |
| 4467 | ); |
| 4468 | $posts = array_merge( $all_templates, $posts ); |
| 4469 | |
| 4470 | if ( ! empty( $posts ) ) { |
| 4471 | foreach ( $posts as $post ) { |
| 4472 | $meta = get_post_meta( $post->ID, '_fl_builder_data', true ); |
| 4473 | foreach ( (array) $meta as $node_id => $node ) { |
| 4474 | if ( isset( $node->type ) && 'module' === $node->type ) { |
| 4475 | $settings = $node->settings; |
| 4476 | if ( in_array( $settings->type, $allowed_types, true ) ) { |
| 4477 | $label = $post->post_title; |
| 4478 | if ( '' !== $settings->node_label ) { |
| 4479 | $label .= ' - ' . $settings->node_label; |
| 4480 | } |
| 4481 | $templates[] = [ |
| 4482 | 'label' => $label, |
| 4483 | 'value' => $node_id, |
| 4484 | ]; |
| 4485 | } |
| 4486 | } |
| 4487 | } |
| 4488 | } |
| 4489 | } |
| 4490 | return $templates; |
| 4491 | } |
| 4492 | |
| 4493 | /** |
| 4494 | * Search beaver builder forms. |
| 4495 | * |
| 4496 | * @param array $data data. |
| 4497 | * @return array |
| 4498 | */ |
| 4499 | public function search_beaver_builder_forms( $data ) { |
| 4500 | $templates = $this->get_beaver_builder_templates(); |
| 4501 | return [ |
| 4502 | 'options' => $templates, |
| 4503 | 'hasMore' => false, |
| 4504 | ]; |
| 4505 | } |
| 4506 | |
| 4507 | /** |
| 4508 | * Search fluentcrm fields. |
| 4509 | * |
| 4510 | * @param array $data data. |
| 4511 | * @return array |
| 4512 | */ |
| 4513 | public function search_fluentcrm_custom_fields( $data ) { |
| 4514 | $context = []; |
| 4515 | $custom_fields = ( new CustomContactField() )->getGlobalFields()['fields']; |
| 4516 | $context['fields'] = $custom_fields; |
| 4517 | return $context; |
| 4518 | } |
| 4519 | |
| 4520 | /** |
| 4521 | * Fetch WP JOB Manager Last Data. |
| 4522 | * |
| 4523 | * @param array $data data. |
| 4524 | * @return array |
| 4525 | */ |
| 4526 | public function search_wp_job_manger_last_data( $data ) { |
| 4527 | global $wpdb; |
| 4528 | $job_type = $data['filter']['job_type']['value']; |
| 4529 | $args = [ |
| 4530 | 'posts_per_page' => 1, |
| 4531 | 'post_type' => 'job_listing', |
| 4532 | 'orderby' => 'id', |
| 4533 | 'order' => 'DESC', |
| 4534 | ]; |
| 4535 | |
| 4536 | if ( -1 !== $job_type ) { |
| 4537 | $args['tax_query'] = [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query |
| 4538 | [ |
| 4539 | 'taxonomy' => 'job_listing_type', |
| 4540 | 'field' => 'term_id', |
| 4541 | 'terms' => $job_type, |
| 4542 | ], |
| 4543 | ]; |
| 4544 | } |
| 4545 | $posts = get_posts( $args ); |
| 4546 | if ( empty( $posts ) ) { |
| 4547 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"ID":145,"wpjob_author":"1","wpjob_date":"2023-01-22 17:38:03","wpjob_date_gmt":"2023-01-22 17:38:03","wpjob_content":"","wpjob_title":"PHP Developer","wpjob_excerpt":"","wpjob_status":"publish","comment_status":"closed","ping_status":"closed","wpjob_password":"","wpjob_name":"project-manager","to_ping":"","pinged":"","wpjob_modified":"2023-01-23 03:23:35","wpjob_modified_gmt":"2023-01-23 03:23:35","wpjob_content_filtered":"","wpjob_parent":0,"guid":"http:\/\/connector.com\/?post_type=job_listing&p=145","menu_order":-1,"wpjob_type":"job_listing","wpjob_mime_type":"","comment_count":"0","filter":"raw","_filled":["0"],"_featured":["1"],"_tribe_ticket_capacity":["0"],"_tribe_ticket_version":["5.5.6"],"_edit_lock":["1674444219:1"],"_job_expires":["2023-02-21"],"_tracked_submitted":["1674409083"],"_edit_last":["1"],"_job_location":[""],"_application":["johnsmith@bexample.com"],"_company_name":["test"],"_company_website":[""],"_company_tagline":[""],"_company_twitter":[""],"_company_video":[""],"_remote_position":["1"],"_llms_reviews_enabled":[""],"_llms_display_reviews":[""],"_llms_num_reviews":["0"],"_llms_multiple_reviews_disabled":[""],"wp_user_id":1,"user_login":"john","display_name":"john","user_firstname":"john","user_lastname":"smith","user_email":"johnsmith@bexample.com","user_role":["administrator","subscriber","tutor_instructor"]}}', true ); |
| 4548 | return $context; |
| 4549 | } |
| 4550 | |
| 4551 | $post = $posts[0]; |
| 4552 | $post_content = WordPress::get_post_context( $post->ID ); |
| 4553 | $post_meta = WordPress::get_post_meta( $post->ID ); |
| 4554 | $job_data = array_merge( $post_content, $post_meta, WordPress::get_user_context( $post->post_author ) ); |
| 4555 | foreach ( $job_data as $key => $job ) { |
| 4556 | $newkey = str_replace( 'post', 'wpjob', $key ); |
| 4557 | unset( $job_data[ $key ] ); |
| 4558 | $job_data[ $newkey ] = $job; |
| 4559 | } |
| 4560 | $context['response_type'] = 'live'; |
| 4561 | $context['pluggable_data'] = $job_data; |
| 4562 | return $context; |
| 4563 | |
| 4564 | } |
| 4565 | |
| 4566 | /** |
| 4567 | * Get Amelia Appointment Category. |
| 4568 | * |
| 4569 | * @param array $data data. |
| 4570 | * |
| 4571 | * @return array |
| 4572 | */ |
| 4573 | public function search_amelia_category_list( $data ) { |
| 4574 | |
| 4575 | global $wpdb; |
| 4576 | |
| 4577 | $page = $data['page']; |
| 4578 | $limit = Utilities::get_search_page_limit(); |
| 4579 | $offset = $limit * ( $page - 1 ); |
| 4580 | |
| 4581 | $categories = $wpdb->get_results( |
| 4582 | $wpdb->prepare( |
| 4583 | "SELECT SQL_CALC_FOUND_ROWS id, name FROM {$wpdb->prefix}amelia_categories WHERE status = %s ORDER BY name ASC LIMIT %d OFFSET %d", |
| 4584 | [ 'visible', $limit, $offset ] |
| 4585 | ), |
| 4586 | OBJECT |
| 4587 | ); |
| 4588 | |
| 4589 | $categories_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 4590 | |
| 4591 | $options = []; |
| 4592 | if ( ! empty( $categories ) ) { |
| 4593 | foreach ( $categories as $category ) { |
| 4594 | $options[] = [ |
| 4595 | 'label' => $category->name, |
| 4596 | 'value' => $category->id, |
| 4597 | ]; |
| 4598 | } |
| 4599 | } |
| 4600 | |
| 4601 | return [ |
| 4602 | 'options' => $options, |
| 4603 | 'hasMore' => $categories_count > $limit && $categories_count > $offset, |
| 4604 | ]; |
| 4605 | |
| 4606 | } |
| 4607 | |
| 4608 | /** |
| 4609 | * Get Amelia Appointment Services. |
| 4610 | * |
| 4611 | * @param array $data data. |
| 4612 | * |
| 4613 | * @return array |
| 4614 | */ |
| 4615 | public function search_amelia_service_list( $data ) { |
| 4616 | |
| 4617 | global $wpdb; |
| 4618 | |
| 4619 | $page = $data['page']; |
| 4620 | $limit = Utilities::get_search_page_limit(); |
| 4621 | $offset = $limit * ( $page - 1 ); |
| 4622 | |
| 4623 | $services = $wpdb->get_results( |
| 4624 | $wpdb->prepare( |
| 4625 | "SELECT SQL_CALC_FOUND_ROWS id, name FROM {$wpdb->prefix}amelia_services |
| 4626 | WHERE categoryId = %d AND status = %s |
| 4627 | ORDER BY name ASC LIMIT %d OFFSET %d", |
| 4628 | [ $data['dynamic'], 'visible', $limit, $offset ] |
| 4629 | ), |
| 4630 | OBJECT |
| 4631 | ); |
| 4632 | |
| 4633 | $services_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 4634 | |
| 4635 | $options = []; |
| 4636 | if ( ! empty( $services ) ) { |
| 4637 | foreach ( $services as $category ) { |
| 4638 | $options[] = [ |
| 4639 | 'label' => $category->name, |
| 4640 | 'value' => $category->id, |
| 4641 | ]; |
| 4642 | } |
| 4643 | } |
| 4644 | |
| 4645 | return [ |
| 4646 | 'options' => $options, |
| 4647 | 'hasMore' => $services_count > $limit && $services_count > $offset, |
| 4648 | ]; |
| 4649 | |
| 4650 | } |
| 4651 | |
| 4652 | /** |
| 4653 | * Get Amelia Events. |
| 4654 | * |
| 4655 | * @param array $data data. |
| 4656 | * |
| 4657 | * @return array |
| 4658 | */ |
| 4659 | public function search_amelia_events_list( $data ) { |
| 4660 | |
| 4661 | global $wpdb; |
| 4662 | |
| 4663 | $page = $data['page']; |
| 4664 | $limit = Utilities::get_search_page_limit(); |
| 4665 | $offset = $limit * ( $page - 1 ); |
| 4666 | |
| 4667 | $events = $wpdb->get_results( |
| 4668 | $wpdb->prepare( |
| 4669 | "SELECT SQL_CALC_FOUND_ROWS id, name from {$wpdb->prefix}amelia_events WHERE status = %s ORDER BY name ASC LIMIT %d OFFSET %d", |
| 4670 | [ 'approved', $limit, $offset ] |
| 4671 | ), |
| 4672 | OBJECT |
| 4673 | ); |
| 4674 | |
| 4675 | $list_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 4676 | |
| 4677 | $options = []; |
| 4678 | if ( ! empty( $events ) ) { |
| 4679 | foreach ( $events as $event ) { |
| 4680 | $options[] = [ |
| 4681 | 'label' => $event->name, |
| 4682 | 'value' => $event->id, |
| 4683 | ]; |
| 4684 | } |
| 4685 | } |
| 4686 | |
| 4687 | return [ |
| 4688 | 'options' => $options, |
| 4689 | 'hasMore' => $list_count > $limit && $list_count > $offset, |
| 4690 | ]; |
| 4691 | |
| 4692 | } |
| 4693 | |
| 4694 | /** |
| 4695 | * Get last data for trigger. |
| 4696 | * |
| 4697 | * @param array $data data. |
| 4698 | * @return array |
| 4699 | */ |
| 4700 | public function search_amelia_appointment_booked_triggers_last_data( $data ) { |
| 4701 | global $wpdb; |
| 4702 | |
| 4703 | $context = []; |
| 4704 | |
| 4705 | $appointment_category = $data['filter']['amelia_category_list']['value']; |
| 4706 | $appointment_service = $data['filter']['amelia_service_list']['value']; |
| 4707 | |
| 4708 | if ( -1 === $appointment_service ) { |
| 4709 | // If service exists as per category selected. |
| 4710 | $service_exist = $wpdb->get_row( |
| 4711 | $wpdb->prepare( |
| 4712 | 'SELECT id, name, description FROM ' . $wpdb->prefix . 'amelia_services WHERE categoryId = %d', |
| 4713 | [ $appointment_category ] |
| 4714 | ), |
| 4715 | ARRAY_A |
| 4716 | ); |
| 4717 | |
| 4718 | if ( empty( $service_exist ) ) { |
| 4719 | $result = []; |
| 4720 | } else { |
| 4721 | $result = $wpdb->get_row( |
| 4722 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE customer.appointmentId = ( SELECT max(id) FROM ' . $wpdb->prefix . 'amelia_appointments )', |
| 4723 | ARRAY_A |
| 4724 | ); |
| 4725 | } |
| 4726 | } else { |
| 4727 | $result = $wpdb->get_row( |
| 4728 | $wpdb->prepare( |
| 4729 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE customer.appointmentId = ( SELECT max(id) FROM ' . $wpdb->prefix . 'amelia_appointments ) AND appointments.serviceId = %d', |
| 4730 | [ $appointment_service ] |
| 4731 | ), |
| 4732 | ARRAY_A |
| 4733 | ); |
| 4734 | } |
| 4735 | |
| 4736 | if ( ! empty( $result ) ) { |
| 4737 | |
| 4738 | $payment_result = $wpdb->get_row( |
| 4739 | $wpdb->prepare( |
| 4740 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_payments WHERE customerBookingId = %d', |
| 4741 | [ $result['id'] ] |
| 4742 | ), |
| 4743 | ARRAY_A |
| 4744 | ); |
| 4745 | |
| 4746 | $customer_result = $wpdb->get_row( |
| 4747 | $wpdb->prepare( |
| 4748 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 4749 | [ $result['customerId'] ] |
| 4750 | ), |
| 4751 | ARRAY_A |
| 4752 | ); |
| 4753 | |
| 4754 | $service_result = $wpdb->get_row( |
| 4755 | $wpdb->prepare( |
| 4756 | 'SELECT name AS serviceName, description AS serviceDescription, categoryId FROM ' . $wpdb->prefix . 'amelia_services WHERE id = %d', |
| 4757 | [ $result['serviceId'] ] |
| 4758 | ), |
| 4759 | ARRAY_A |
| 4760 | ); |
| 4761 | |
| 4762 | $category_result = $wpdb->get_row( |
| 4763 | $wpdb->prepare( |
| 4764 | 'SELECT name AS categoryName FROM ' . $wpdb->prefix . 'amelia_categories WHERE id = %d', |
| 4765 | [ $service_result['categoryId'] ] |
| 4766 | ), |
| 4767 | ARRAY_A |
| 4768 | ); |
| 4769 | |
| 4770 | if ( $result['couponId'] ) { |
| 4771 | $coupon_result = $wpdb->get_row( |
| 4772 | $wpdb->prepare( |
| 4773 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 4774 | [ $result['couponId'] ] |
| 4775 | ), |
| 4776 | ARRAY_A |
| 4777 | ); |
| 4778 | } else { |
| 4779 | $coupon_result = []; |
| 4780 | } |
| 4781 | |
| 4782 | if ( ! empty( $result['customFields'] ) ) { |
| 4783 | $custom_fields = json_decode( $result['customFields'], true ); |
| 4784 | |
| 4785 | $fields_arr = []; |
| 4786 | foreach ( (array) $custom_fields as $fields ) { |
| 4787 | if ( is_array( $fields ) ) { |
| 4788 | $fields_arr[ $fields['label'] ] = $fields['value']; |
| 4789 | } |
| 4790 | } |
| 4791 | unset( $result['customFields'] ); |
| 4792 | } else { |
| 4793 | $fields_arr = []; |
| 4794 | } |
| 4795 | |
| 4796 | $context['pluggable_data'] = array_merge( $result, $fields_arr, $payment_result, $customer_result, $service_result, $category_result, $coupon_result ); |
| 4797 | $context['response_type'] = 'live'; |
| 4798 | } else { |
| 4799 | |
| 4800 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"id":"1","status":"visible","bookingStart":"2023-02-28 13:00:00","bookingEnd":"2023-02-28 14:00:00","notifyParticipants":"1","serviceId":"4","packageId":null,"providerId":"2","locationId":null,"internalNotes":"","googleCalendarEventId":null,"googleMeetUrl":null,"outlookCalendarEventId":null,"zoomMeeting":null,"lessonSpace":null,"parentId":null,"appointmentId":"1","customerId":"1","price":"15","persons":"1","couponId":null,"token":"02cf0988c6","info":"{\"firstName\":\"test\",\"lastName\":\"test\",\"phone\":\"1 (234) 789\",\"locale\":\"en_US\",\"timeZone\":\"Asia\\\/Kolkata\",\"urlParams\":null}","utcOffset":null,"aggregatedPrice":"1","packageCustomerServiceId":null,"duration":"3600","created":"2023-02-08 11:16:03","actionsCompleted":"1","Do You Know Automation?":"Yes","When Are You Coming?":"2023-04-20","Upload Something":"","Tell Us About You!":"Hey there!","customerBookingId":"103","amount":"0","dateTime":"2023-02-28 13:00:00","gateway":"onSite","gatewayTitle":"","data":"","packageCustomerId":null,"entity":"appointment","wcOrderId":null,"type":"customer","externalId":"89","firstName":"test","lastName":"test","email":"test@test.com","birthday":null,"phone":"1 (234) 789","gender":null,"note":null,"description":null,"pictureFullPath":null,"pictureThumbPath":null,"password":null,"usedTokens":null,"zoomUserId":null,"countryPhoneIso":"us","translations":"{\"defaultLanguage\":\"en_US\"}","timeZone":null,"serviceName":"demo service","serviceDescription":"","categoryId":"2","categoryName":"New Category1"}}', true ); |
| 4801 | } |
| 4802 | |
| 4803 | return $context; |
| 4804 | } |
| 4805 | |
| 4806 | /** |
| 4807 | * Get last data for trigger. |
| 4808 | * |
| 4809 | * @param array $data data. |
| 4810 | * @return array |
| 4811 | */ |
| 4812 | public function search_amelia_new_event_attendee_triggers_last_data( $data ) { |
| 4813 | global $wpdb; |
| 4814 | |
| 4815 | $context = []; |
| 4816 | |
| 4817 | $event_selected = $data['filter']['amelia_events_list']['value']; |
| 4818 | |
| 4819 | if ( -1 === $event_selected ) { |
| 4820 | $result = $wpdb->get_row( |
| 4821 | 'SELECT * |
| 4822 | FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer |
| 4823 | INNER JOIN ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods as event_period |
| 4824 | ON customer.id = event_period.customerBookingId |
| 4825 | WHERE event_period.customerBookingId = ( Select max(customerBookingId) From ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods )', |
| 4826 | ARRAY_A |
| 4827 | ); |
| 4828 | } else { |
| 4829 | $result = $wpdb->get_row( |
| 4830 | $wpdb->prepare( |
| 4831 | 'SELECT * |
| 4832 | FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer |
| 4833 | INNER JOIN ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods as event_period |
| 4834 | ON customer.id = event_period.customerBookingId |
| 4835 | WHERE event_period.customerBookingId = ( Select max(customerBookingId) From ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods ) AND eventPeriodId = %d', |
| 4836 | [ $event_selected ] |
| 4837 | ), |
| 4838 | ARRAY_A |
| 4839 | ); |
| 4840 | } |
| 4841 | |
| 4842 | if ( ! empty( $result ) ) { |
| 4843 | |
| 4844 | $event = $wpdb->get_row( |
| 4845 | $wpdb->prepare( |
| 4846 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_events WHERE id = %d', |
| 4847 | [ $result['eventPeriodId'] ] |
| 4848 | ), |
| 4849 | ARRAY_A |
| 4850 | ); |
| 4851 | |
| 4852 | $customer_result = $wpdb->get_row( |
| 4853 | $wpdb->prepare( |
| 4854 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 4855 | [ $result['customerId'] ] |
| 4856 | ), |
| 4857 | ARRAY_A |
| 4858 | ); |
| 4859 | |
| 4860 | if ( $result['couponId'] ) { |
| 4861 | $coupon_result = $wpdb->get_row( |
| 4862 | $wpdb->prepare( |
| 4863 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 4864 | [ $result['couponId'] ] |
| 4865 | ), |
| 4866 | ARRAY_A |
| 4867 | ); |
| 4868 | } else { |
| 4869 | $coupon_result = []; |
| 4870 | } |
| 4871 | |
| 4872 | if ( ! empty( $result['customFields'] ) ) { |
| 4873 | $custom_fields = json_decode( $result['customFields'], true ); |
| 4874 | |
| 4875 | $fields_arr = []; |
| 4876 | foreach ( (array) $custom_fields as $fields ) { |
| 4877 | if ( is_array( $fields ) ) { |
| 4878 | $fields_arr[ $fields['label'] ] = $fields['value']; |
| 4879 | } |
| 4880 | } |
| 4881 | unset( $result['customFields'] ); |
| 4882 | } else { |
| 4883 | $fields_arr = []; |
| 4884 | } |
| 4885 | |
| 4886 | $context['pluggable_data'] = array_merge( $result, $fields_arr, $event, $customer_result, $coupon_result ); |
| 4887 | $context['response_type'] = 'live'; |
| 4888 | } else { |
| 4889 | |
| 4890 | $context = json_decode( '{"response_type":"sample","pluggable_data":{""id":"1","appointmentId":null,"customerId":"1","status":"visible","price":"10","persons":"1","couponId":null,"token":"6485b07ce9","info":"{\"firstName\":\"test\",\"lastName\":\"test\",\"phone\":\"+213551223123\",\"locale\":\"en_US\",\"timeZone\":\"Asia\\\/Kolkata\",\"urlParams\":null}","utcOffset":null,"aggregatedPrice":"1","packageCustomerServiceId":null,"duration":null,"created":"2023-02-02 06:35:18","actionsCompleted":"1","Do You Know Automation?":"Yes","When Are You Coming?":"2023-04-20","Upload Something":"","Tell Us About You!":"Hey there!","customerBookingId":"105","eventPeriodId":"5","parentId":null,"name":"Testing Event 5","bookingOpens":null,"bookingCloses":"2023-02-09 08:00:00","bookingOpensRec":"same","bookingClosesRec":"same","ticketRangeRec":"calculate","recurringCycle":null,"recurringOrder":null,"recurringInterval":null,"recurringMonthly":null,"monthlyDate":null,"monthlyOnRepeat":null,"monthlyOnDay":null,"recurringUntil":null,"maxCapacity":"12","maxCustomCapacity":null,"maxExtraPeople":null,"locationId":null,"customLocation":"test","description":null,"color":"#1788FB","show":"1","notifyParticipants":"1","settings":"{\"payments\":{\"onSite\":true,\"payPal\":{\"enabled\":false},\"stripe\":{\"enabled\":false},\"mollie\":{\"enabled\":false},\"razorpay\":{\"enabled\":false}},\"general\":{\"minimumTimeRequirementPriorToCanceling\":null,\"redirectUrlAfterAppointment\":null},\"zoom\":{\"enabled\":false},\"lessonSpace\":{\"enabled\":false}}","zoomUserId":null,"bringingAnyone":"1","bookMultipleTimes":"1","translations":"{\"defaultLanguage\":\"en_US\"}","depositPayment":"disabled","depositPerPerson":"1","fullPayment":"0","deposit":"0","customPricing":"0","organizerId":"2","closeAfterMin":null,"closeAfterMinBookings":"0","type":"customer","externalId":"91","firstName":"test","lastName":"test","email":"test@test.com","birthday":null,"phone":"+213551223123","gender":null,"note":null,"pictureFullPath":null,"pictureThumbPath":null,"password":null,"usedTokens":null,"countryPhoneIso":"dz","timeZone":null}}', true ); |
| 4891 | } |
| 4892 | |
| 4893 | return $context; |
| 4894 | } |
| 4895 | |
| 4896 | /** |
| 4897 | * Get last data for trigger. |
| 4898 | * |
| 4899 | * @param array $data data. |
| 4900 | * @return array |
| 4901 | */ |
| 4902 | public function search_amelia_appointment_rescheduled_triggers_last_data( $data ) { |
| 4903 | global $wpdb; |
| 4904 | |
| 4905 | $context = []; |
| 4906 | |
| 4907 | $appointment_category = $data['filter']['amelia_category_list']['value']; |
| 4908 | $appointment_service = $data['filter']['amelia_service_list']['value']; |
| 4909 | |
| 4910 | if ( -1 === $appointment_service ) { |
| 4911 | // If service exists as per category selected. |
| 4912 | $service_exist = $wpdb->get_row( |
| 4913 | $wpdb->prepare( |
| 4914 | 'SELECT id, name, description FROM ' . $wpdb->prefix . 'amelia_services WHERE categoryId = %d', |
| 4915 | [ $appointment_category ] |
| 4916 | ), |
| 4917 | ARRAY_A |
| 4918 | ); |
| 4919 | |
| 4920 | if ( empty( $service_exist ) ) { |
| 4921 | $result = []; |
| 4922 | } else { |
| 4923 | $result = $wpdb->get_row( |
| 4924 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE customer.appointmentId = ( SELECT max(id) FROM ' . $wpdb->prefix . 'amelia_appointments )', |
| 4925 | ARRAY_A |
| 4926 | ); |
| 4927 | } |
| 4928 | } else { |
| 4929 | $result = $wpdb->get_row( |
| 4930 | $wpdb->prepare( |
| 4931 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE customer.appointmentId = ( SELECT max(id) FROM ' . $wpdb->prefix . 'amelia_appointments ) AND appointments.serviceId = %d', |
| 4932 | [ $appointment_service ] |
| 4933 | ), |
| 4934 | ARRAY_A |
| 4935 | ); |
| 4936 | } |
| 4937 | |
| 4938 | if ( ! empty( $result ) ) { |
| 4939 | |
| 4940 | $payment_result = $wpdb->get_row( |
| 4941 | $wpdb->prepare( |
| 4942 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_payments WHERE customerBookingId = %d', |
| 4943 | [ $result['id'] ] |
| 4944 | ), |
| 4945 | ARRAY_A |
| 4946 | ); |
| 4947 | |
| 4948 | $customer_result = $wpdb->get_row( |
| 4949 | $wpdb->prepare( |
| 4950 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 4951 | [ $result['customerId'] ] |
| 4952 | ), |
| 4953 | ARRAY_A |
| 4954 | ); |
| 4955 | |
| 4956 | $service_result = $wpdb->get_row( |
| 4957 | $wpdb->prepare( |
| 4958 | 'SELECT name AS serviceName, description AS serviceDescription, categoryId FROM ' . $wpdb->prefix . 'amelia_services WHERE id = %d', |
| 4959 | [ $result['serviceId'] ] |
| 4960 | ), |
| 4961 | ARRAY_A |
| 4962 | ); |
| 4963 | |
| 4964 | $category_result = $wpdb->get_row( |
| 4965 | $wpdb->prepare( |
| 4966 | 'SELECT name AS categoryName FROM ' . $wpdb->prefix . 'amelia_categories WHERE id = %d', |
| 4967 | [ $service_result['categoryId'] ] |
| 4968 | ), |
| 4969 | ARRAY_A |
| 4970 | ); |
| 4971 | |
| 4972 | if ( $result['couponId'] ) { |
| 4973 | $coupon_result = $wpdb->get_row( |
| 4974 | $wpdb->prepare( |
| 4975 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 4976 | [ $result['couponId'] ] |
| 4977 | ), |
| 4978 | ARRAY_A |
| 4979 | ); |
| 4980 | } else { |
| 4981 | $coupon_result = []; |
| 4982 | } |
| 4983 | |
| 4984 | if ( ! empty( $result['customFields'] ) ) { |
| 4985 | $custom_fields = json_decode( $result['customFields'], true ); |
| 4986 | |
| 4987 | $fields_arr = []; |
| 4988 | foreach ( (array) $custom_fields as $fields ) { |
| 4989 | if ( is_array( $fields ) ) { |
| 4990 | $fields_arr[ $fields['label'] ] = $fields['value']; |
| 4991 | } |
| 4992 | } |
| 4993 | unset( $result['customFields'] ); |
| 4994 | } else { |
| 4995 | $fields_arr = []; |
| 4996 | } |
| 4997 | |
| 4998 | $appointment_data['isRescheduled'] = '1'; |
| 4999 | $context['pluggable_data'] = array_merge( $result, $fields_arr, $appointment_data, $payment_result, $customer_result, $service_result, $category_result, $coupon_result ); |
| 5000 | $context['response_type'] = 'live'; |
| 5001 | } else { |
| 5002 | |
| 5003 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"id":"1","status":"visible","bookingStart":"2023-02-28 15:30:00","bookingEnd":"2023-02-28 16:30:00","notifyParticipants":"1","serviceId":"4","packageId":null,"providerId":"2","locationId":null,"internalNotes":"","googleCalendarEventId":null,"googleMeetUrl":null,"outlookCalendarEventId":null,"zoomMeeting":null,"lessonSpace":null,"parentId":null,"appointmentId":"54","customerId":"1","price":"15","persons":"1","couponId":null,"token":"02cf0988c6","info":"{\"firstName\":\"test\",\"lastName\":\"test\",\"phone\":\"1 (234) 789\",\"locale\":\"en_US\",\"timeZone\":\"Asia\\\/Kolkata\",\"urlParams\":null}","utcOffset":null,"aggregatedPrice":"1","packageCustomerServiceId":null,"duration":"3600","created":"2023-02-08 11:16:03","actionsCompleted":"1","Do You Know Automation?":"Yes","When Are You Coming?":"2023-04-20","Upload Something":"","Tell Us About You!":"Hey there!","isRescheduled":"1","customerBookingId":"103","amount":"0","dateTime":"2023-02-28 15:30:00","gateway":"onSite","gatewayTitle":"","data":"","packageCustomerId":null,"entity":"appointment","wcOrderId":null,"type":"customer","externalId":"89","firstName":"test","lastName":"test","email":"test@test.com","birthday":null,"phone":"1 (234) 789","gender":null,"note":null,"description":null,"pictureFullPath":null,"pictureThumbPath":null,"password":null,"usedTokens":null,"zoomUserId":null,"countryPhoneIso":"us","translations":"{\"defaultLanguage\":\"en_US\"}","timeZone":null,"serviceName":"demo service","serviceDescription":"","categoryId":"2","categoryName":"New Category1"}}', true ); |
| 5004 | } |
| 5005 | |
| 5006 | return $context; |
| 5007 | } |
| 5008 | |
| 5009 | |
| 5010 | /** |
| 5011 | * Get last data for trigger. |
| 5012 | * |
| 5013 | * @param array $data data. |
| 5014 | * @return array |
| 5015 | */ |
| 5016 | public function search_amelia_appointment_cancelled_triggers_last_data( $data ) { |
| 5017 | global $wpdb; |
| 5018 | |
| 5019 | $context = []; |
| 5020 | |
| 5021 | $appointment_category = $data['filter']['amelia_category_list']['value']; |
| 5022 | $appointment_service = $data['filter']['amelia_service_list']['value']; |
| 5023 | |
| 5024 | if ( -1 === $appointment_service ) { |
| 5025 | // If service exists as per category selected. |
| 5026 | $service_exist = $wpdb->get_row( |
| 5027 | $wpdb->prepare( |
| 5028 | 'SELECT id, name, description FROM ' . $wpdb->prefix . 'amelia_services WHERE categoryId = %d', |
| 5029 | [ $appointment_category ] |
| 5030 | ), |
| 5031 | ARRAY_A |
| 5032 | ); |
| 5033 | |
| 5034 | if ( empty( $service_exist ) ) { |
| 5035 | $result = []; |
| 5036 | } else { |
| 5037 | $result = $wpdb->get_row( |
| 5038 | $wpdb->prepare( |
| 5039 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE appointments.status = %s order by RAND() DESC LIMIT 1', |
| 5040 | [ 'canceled' ] |
| 5041 | ), |
| 5042 | ARRAY_A |
| 5043 | ); |
| 5044 | } |
| 5045 | } else { |
| 5046 | $result = $wpdb->get_row( |
| 5047 | $wpdb->prepare( |
| 5048 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE appointments.status = %s AND appointments.serviceId = %d order by RAND() DESC LIMIT 1', |
| 5049 | [ 'canceled', $appointment_service ] |
| 5050 | ), |
| 5051 | ARRAY_A |
| 5052 | ); |
| 5053 | } |
| 5054 | |
| 5055 | if ( ! empty( $result ) ) { |
| 5056 | |
| 5057 | $payment_result = $wpdb->get_row( |
| 5058 | $wpdb->prepare( |
| 5059 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_payments WHERE customerBookingId = %d', |
| 5060 | [ $result['id'] ] |
| 5061 | ), |
| 5062 | ARRAY_A |
| 5063 | ); |
| 5064 | |
| 5065 | $customer_result = $wpdb->get_row( |
| 5066 | $wpdb->prepare( |
| 5067 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 5068 | [ $result['customerId'] ] |
| 5069 | ), |
| 5070 | ARRAY_A |
| 5071 | ); |
| 5072 | |
| 5073 | $service_result = $wpdb->get_row( |
| 5074 | $wpdb->prepare( |
| 5075 | 'SELECT name AS serviceName, description AS serviceDescription, categoryId FROM ' . $wpdb->prefix . 'amelia_services WHERE id = %d', |
| 5076 | [ $result['serviceId'] ] |
| 5077 | ), |
| 5078 | ARRAY_A |
| 5079 | ); |
| 5080 | |
| 5081 | $category_result = $wpdb->get_row( |
| 5082 | $wpdb->prepare( |
| 5083 | 'SELECT name AS categoryName FROM ' . $wpdb->prefix . 'amelia_categories WHERE id = %d', |
| 5084 | [ $service_result['categoryId'] ] |
| 5085 | ), |
| 5086 | ARRAY_A |
| 5087 | ); |
| 5088 | |
| 5089 | if ( $result['couponId'] ) { |
| 5090 | $coupon_result = $wpdb->get_row( |
| 5091 | $wpdb->prepare( |
| 5092 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 5093 | [ $result['couponId'] ] |
| 5094 | ), |
| 5095 | ARRAY_A |
| 5096 | ); |
| 5097 | } else { |
| 5098 | $coupon_result = []; |
| 5099 | } |
| 5100 | |
| 5101 | if ( ! empty( $result['customFields'] ) ) { |
| 5102 | $custom_fields = json_decode( $result['customFields'], true ); |
| 5103 | |
| 5104 | $fields_arr = []; |
| 5105 | foreach ( (array) $custom_fields as $fields ) { |
| 5106 | if ( is_array( $fields ) ) { |
| 5107 | $fields_arr[ $fields['label'] ] = $fields['value']; |
| 5108 | } |
| 5109 | } |
| 5110 | unset( $result['customFields'] ); |
| 5111 | } else { |
| 5112 | $fields_arr = []; |
| 5113 | } |
| 5114 | |
| 5115 | $context['pluggable_data'] = array_merge( $result, $fields_arr, $payment_result, $customer_result, $service_result, $category_result, $coupon_result ); |
| 5116 | $context['response_type'] = 'live'; |
| 5117 | } else { |
| 5118 | |
| 5119 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"id":"1","status":"visible","bookingStart":"2023-02-28 15:30:00","bookingEnd":"2023-02-28 16:30:00","notifyParticipants":"1","serviceId":"4","packageId":null,"providerId":"2","locationId":null,"internalNotes":"","googleCalendarEventId":null,"googleMeetUrl":null,"outlookCalendarEventId":null,"zoomMeeting":null,"lessonSpace":null,"parentId":null,"appointmentId":"54","customerId":"1","price":"15","persons":"1","couponId":null,"token":"02cf0988c6","info":"{\"firstName\":\"test\",\"lastName\":\"test\",\"phone\":\"1 (234) 789\",\"locale\":\"en_US\",\"timeZone\":\"Asia\\\/Kolkata\",\"urlParams\":null}","utcOffset":null,"aggregatedPrice":"1","packageCustomerServiceId":null,"duration":"3600","created":"2023-02-08 11:16:03","actionsCompleted":"1","Do You Know Automation?":"Yes","When Are You Coming?":"2023-04-20","Upload Something":"","Tell Us About You!":"Hey there!","customerBookingId":"103","amount":"0","dateTime":"2023-02-28 15:30:00","gateway":"onSite","gatewayTitle":"","data":"","packageCustomerId":null,"entity":"appointment","wcOrderId":null,"type":"customer","externalId":"89","firstName":"test","lastName":"test","email":"test@test.com","birthday":null,"phone":"1 (234) 789","gender":null,"note":null,"description":null,"pictureFullPath":null,"pictureThumbPath":null,"password":null,"usedTokens":null,"zoomUserId":null,"countryPhoneIso":"us","translations":"{\"defaultLanguage\":\"en_US\"}","timeZone":null,"serviceName":"demo service","serviceDescription":"","categoryId":"2","categoryName":"New Category1"}}', true ); |
| 5120 | } |
| 5121 | |
| 5122 | return $context; |
| 5123 | } |
| 5124 | |
| 5125 | /** |
| 5126 | * Get MailPoet Forms. |
| 5127 | * |
| 5128 | * @param array $data data. |
| 5129 | * |
| 5130 | * @return array |
| 5131 | */ |
| 5132 | public function search_mailpoet_forms( $data ) { |
| 5133 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 5134 | return; |
| 5135 | } |
| 5136 | |
| 5137 | global $wpdb; |
| 5138 | |
| 5139 | $page = $data['page']; |
| 5140 | $limit = Utilities::get_search_page_limit(); |
| 5141 | $offset = $limit * ( $page - 1 ); |
| 5142 | |
| 5143 | $forms = $wpdb->get_results( |
| 5144 | $wpdb->prepare( |
| 5145 | 'SELECT SQL_CALC_FOUND_ROWS * FROM ' . $wpdb->prefix . 'mailpoet_forms WHERE `deleted_at` IS NULL AND `status` = %s ORDER BY id LIMIT %d OFFSET %d', |
| 5146 | [ 'enabled', $limit, $offset ] |
| 5147 | ) |
| 5148 | ); |
| 5149 | |
| 5150 | $form_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 5151 | |
| 5152 | $options = []; |
| 5153 | |
| 5154 | if ( ! empty( $forms ) ) { |
| 5155 | if ( is_array( $forms ) ) { |
| 5156 | foreach ( $forms as $form ) { |
| 5157 | $options[] = [ |
| 5158 | 'label' => $form->name, |
| 5159 | 'value' => $form->id, |
| 5160 | ]; |
| 5161 | } |
| 5162 | } |
| 5163 | } |
| 5164 | |
| 5165 | return [ |
| 5166 | 'options' => $options, |
| 5167 | 'hasMore' => $form_count > $limit && $form_count > $offset, |
| 5168 | ]; |
| 5169 | |
| 5170 | } |
| 5171 | |
| 5172 | /** |
| 5173 | * Get MailPoet List. |
| 5174 | * |
| 5175 | * @param array $data data. |
| 5176 | * |
| 5177 | * @return array |
| 5178 | */ |
| 5179 | public function search_mailpoet_list( $data ) { |
| 5180 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 5181 | return; |
| 5182 | } |
| 5183 | |
| 5184 | $mailpoet = \MailPoet\API\API::MP( 'v1' ); |
| 5185 | $lists = $mailpoet->getLists(); |
| 5186 | |
| 5187 | $options = []; |
| 5188 | |
| 5189 | if ( ! empty( $lists ) ) { |
| 5190 | if ( is_array( $lists ) ) { |
| 5191 | foreach ( $lists as $list ) { |
| 5192 | $options[] = [ |
| 5193 | 'label' => $list['name'], |
| 5194 | 'value' => $list['id'], |
| 5195 | ]; |
| 5196 | } |
| 5197 | } |
| 5198 | } |
| 5199 | |
| 5200 | return [ |
| 5201 | 'options' => $options, |
| 5202 | 'hasMore' => false, |
| 5203 | ]; |
| 5204 | } |
| 5205 | |
| 5206 | /** |
| 5207 | * Get MailPoet Subscriber Status. |
| 5208 | * |
| 5209 | * @param array $data data. |
| 5210 | * |
| 5211 | * @return array |
| 5212 | */ |
| 5213 | public function search_mailpoet_subscriber_status( $data ) { |
| 5214 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 5215 | return; |
| 5216 | } |
| 5217 | |
| 5218 | $subscriber_status = [ |
| 5219 | 'subscribed' => 'Subscribed', |
| 5220 | 'unconfirmed' => 'Unconfirmed', |
| 5221 | 'unsubscribed' => 'Unsubscribed', |
| 5222 | 'inactive' => 'Inactive', |
| 5223 | 'bounced' => 'Bounced', |
| 5224 | ]; |
| 5225 | |
| 5226 | $options = []; |
| 5227 | foreach ( $subscriber_status as $key => $status ) { |
| 5228 | $options[] = [ |
| 5229 | 'label' => $status, |
| 5230 | 'value' => $key, |
| 5231 | ]; |
| 5232 | } |
| 5233 | |
| 5234 | return [ |
| 5235 | 'options' => $options, |
| 5236 | 'hasMore' => false, |
| 5237 | ]; |
| 5238 | } |
| 5239 | |
| 5240 | /** |
| 5241 | * Get MailPoet Subscribers. |
| 5242 | * |
| 5243 | * @param array $data data. |
| 5244 | * |
| 5245 | * @return array |
| 5246 | */ |
| 5247 | public function search_mailpoet_subscribers( $data ) { |
| 5248 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 5249 | return; |
| 5250 | } |
| 5251 | |
| 5252 | global $wpdb; |
| 5253 | |
| 5254 | $page = $data['page']; |
| 5255 | $limit = Utilities::get_search_page_limit(); |
| 5256 | $offset = $limit * ( $page - 1 ); |
| 5257 | |
| 5258 | $subscribers = $wpdb->get_results( |
| 5259 | $wpdb->prepare( |
| 5260 | 'SELECT SQL_CALC_FOUND_ROWS id,email FROM ' . $wpdb->prefix . 'mailpoet_subscribers ORDER BY id DESC LIMIT %d OFFSET %d', |
| 5261 | [ $limit, $offset ] |
| 5262 | ) |
| 5263 | ); |
| 5264 | |
| 5265 | $subscribers_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 5266 | |
| 5267 | $options = []; |
| 5268 | |
| 5269 | if ( ! empty( $subscribers ) ) { |
| 5270 | if ( is_array( $subscribers ) ) { |
| 5271 | foreach ( $subscribers as $subscriber ) { |
| 5272 | $options[] = [ |
| 5273 | 'label' => $subscriber->email, |
| 5274 | 'value' => $subscriber->id, |
| 5275 | ]; |
| 5276 | } |
| 5277 | } |
| 5278 | } |
| 5279 | |
| 5280 | return [ |
| 5281 | 'options' => $options, |
| 5282 | 'hasMore' => $subscribers_count > $limit && $subscribers_count > $offset, |
| 5283 | ]; |
| 5284 | } |
| 5285 | |
| 5286 | /** |
| 5287 | * Get ConvertPro Forms. |
| 5288 | * |
| 5289 | * @param array $data data. |
| 5290 | * |
| 5291 | * @return array |
| 5292 | */ |
| 5293 | public function search_convertpro_form_list( $data ) { |
| 5294 | if ( ! class_exists( '\Cp_V2_Loader' ) ) { |
| 5295 | return; |
| 5296 | } |
| 5297 | |
| 5298 | $cp_popups_inst = CP_V2_Popups::get_instance(); |
| 5299 | $popups = $cp_popups_inst->get_all(); |
| 5300 | |
| 5301 | $form_count = count( $popups ); |
| 5302 | |
| 5303 | $page = $data['page']; |
| 5304 | $limit = Utilities::get_search_page_limit(); |
| 5305 | $offset = $limit * ( $page - 1 ); |
| 5306 | |
| 5307 | $options = []; |
| 5308 | |
| 5309 | if ( ! empty( $popups ) ) { |
| 5310 | if ( is_array( $popups ) ) { |
| 5311 | foreach ( $popups as $form ) { |
| 5312 | $options[] = [ |
| 5313 | 'label' => $form->post_title, |
| 5314 | 'value' => $form->ID, |
| 5315 | ]; |
| 5316 | } |
| 5317 | } |
| 5318 | } |
| 5319 | |
| 5320 | return [ |
| 5321 | 'options' => $options, |
| 5322 | 'hasMore' => $form_count > $limit && $form_count > $offset, |
| 5323 | ]; |
| 5324 | |
| 5325 | } |
| 5326 | |
| 5327 | /** |
| 5328 | * Get ProjectHuddle Websites. |
| 5329 | * |
| 5330 | * @param array $data data. |
| 5331 | * |
| 5332 | * @return array |
| 5333 | */ |
| 5334 | public function search_project_huddle_websites( $data ) { |
| 5335 | |
| 5336 | $sites = new WP_Query( |
| 5337 | [ |
| 5338 | 'post_type' => 'ph-website', |
| 5339 | 'posts_per_page' => - 1, |
| 5340 | 'fields' => 'ids', |
| 5341 | ] |
| 5342 | ); |
| 5343 | |
| 5344 | $site_ids = (array) $sites->posts; |
| 5345 | |
| 5346 | $options = []; |
| 5347 | if ( ! empty( $site_ids ) ) { |
| 5348 | if ( is_array( $site_ids ) ) { |
| 5349 | foreach ( $site_ids as $site_id ) { |
| 5350 | $options[] = [ |
| 5351 | 'label' => get_the_title( $site_id ), |
| 5352 | 'value' => $site_id, |
| 5353 | ]; |
| 5354 | } |
| 5355 | } |
| 5356 | } |
| 5357 | return [ |
| 5358 | 'options' => $options, |
| 5359 | 'hasMore' => false, |
| 5360 | ]; |
| 5361 | |
| 5362 | } |
| 5363 | |
| 5364 | /** |
| 5365 | * Get last data for trigger. |
| 5366 | * |
| 5367 | * @param array $data data. |
| 5368 | * @return mixed |
| 5369 | */ |
| 5370 | public function search_project_huddle_comment_triggers_last_data( $data ) { |
| 5371 | global $wpdb; |
| 5372 | |
| 5373 | $context = []; |
| 5374 | |
| 5375 | if ( -1 !== $data['dynamic'] ) { |
| 5376 | $threads = get_posts( |
| 5377 | [ |
| 5378 | 'post_type' => 'phw_comment_loc', |
| 5379 | 'posts_per_page' => 1, |
| 5380 | 'meta_value' => $data['dynamic'], |
| 5381 | 'meta_key' => 'project_id', |
| 5382 | 'orderby' => 'asc', |
| 5383 | ] |
| 5384 | ); |
| 5385 | } else { |
| 5386 | $threads = []; |
| 5387 | } |
| 5388 | |
| 5389 | if ( ! empty( $threads ) ) { |
| 5390 | $comment_result = $wpdb->get_row( |
| 5391 | $wpdb->prepare( |
| 5392 | 'SELECT ' . $wpdb->prefix . 'comments.comment_ID |
| 5393 | FROM ' . $wpdb->prefix . 'comments |
| 5394 | WHERE ( ( comment_approved = "0" OR comment_approved = "1" ) ) AND comment_type IN ("ph_comment") AND comment_post_ID = %d |
| 5395 | ORDER BY ' . $wpdb->prefix . 'comments.comment_date_gmt DESC |
| 5396 | LIMIT 0,1', |
| 5397 | $threads[0]->ID |
| 5398 | ), |
| 5399 | ARRAY_A |
| 5400 | ); |
| 5401 | |
| 5402 | if ( ! empty( $comment_result ) ) { |
| 5403 | $comment_id = get_comment( $comment_result['comment_ID'], ARRAY_A ); |
| 5404 | $comments['comment_ID'] = isset( $comment_id['comment_ID'] ) ? $comment_id['comment_ID'] : ''; |
| 5405 | $comments['comment_post_ID'] = isset( $comment_id['comment_post_ID'] ) ? $comment_id['comment_post_ID'] : ''; |
| 5406 | |
| 5407 | $comments['comment_author'] = isset( $comment_id['comment_author'] ) ? $comment_id['comment_author'] : ''; |
| 5408 | |
| 5409 | $comments['comment_author_email'] = isset( $comment_id['comment_author_email'] ) ? $comment_id['comment_author_email'] : ''; |
| 5410 | |
| 5411 | $comments['comment_date'] = isset( $comment_id['comment_date'] ) ? $comment_id['comment_date'] : ''; |
| 5412 | |
| 5413 | $comments['comment_content'] = isset( $comment_id['comment_content'] ) ? $comment_id['comment_content'] : ''; |
| 5414 | |
| 5415 | $comments['comment_type'] = isset( $comment_id['comment_type'] ) ? $comment_id['comment_type'] : ''; |
| 5416 | |
| 5417 | $context['pluggable_data'] = $comments; |
| 5418 | $context['response_type'] = 'live'; |
| 5419 | } else { |
| 5420 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"comment_ID":"1","comment_post_ID":"1","comment_author":"test","comment_author_email":"test@test.com","comment_date":"2023-03-27 13:44:26","comment_content":"<p>Leave comment<\/p>","comment_type":"ph_comment"}}', true ); |
| 5421 | } |
| 5422 | } else { |
| 5423 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"comment_ID":"1","comment_post_ID":"1","comment_author":"test","comment_author_email":"test@test.com","comment_date":"2023-03-27 13:44:26","comment_content":"<p>Leave comment<\/p>","comment_type":"ph_comment"}}', true ); |
| 5424 | } |
| 5425 | |
| 5426 | return $context; |
| 5427 | } |
| 5428 | |
| 5429 | /** |
| 5430 | * Get last data for trigger. |
| 5431 | * |
| 5432 | * @param array $data data. |
| 5433 | * @return mixed |
| 5434 | */ |
| 5435 | public function search_project_huddle_resolved_comment_triggers_last_data( $data ) { |
| 5436 | global $wpdb; |
| 5437 | |
| 5438 | $context = []; |
| 5439 | |
| 5440 | $get_comments = $wpdb->get_row( |
| 5441 | 'SELECT ' . $wpdb->prefix . 'comments.comment_ID, ' . $wpdb->prefix . 'comments.comment_content |
| 5442 | FROM ' . $wpdb->prefix . 'comments |
| 5443 | WHERE ( ( comment_approved = "0" OR comment_approved = "1" ) ) AND comment_type IN ("ph_status") AND comment_content = "Resolved" |
| 5444 | ORDER BY ' . $wpdb->prefix . 'comments.comment_date_gmt DESC |
| 5445 | LIMIT 0,1' |
| 5446 | ); |
| 5447 | |
| 5448 | if ( ! empty( $get_comments ) ) { |
| 5449 | $comment_id = get_comment( $get_comments->comment_ID, ARRAY_A ); |
| 5450 | $comment_result = $wpdb->get_row( |
| 5451 | $wpdb->prepare( |
| 5452 | 'SELECT ' . $wpdb->prefix . 'comments.comment_ID |
| 5453 | FROM ' . $wpdb->prefix . 'comments |
| 5454 | WHERE ( ( comment_approved = "0" OR comment_approved = "1" ) ) AND comment_type IN ("ph_comment") AND comment_post_ID = %d |
| 5455 | ORDER BY ' . $wpdb->prefix . 'comments.comment_date_gmt DESC |
| 5456 | LIMIT 0,1', |
| 5457 | isset( $comment_id['comment_post_ID'] ) ? $comment_id['comment_post_ID'] : '' |
| 5458 | ), |
| 5459 | ARRAY_A |
| 5460 | ); |
| 5461 | |
| 5462 | $actual_comment = get_comment( $comment_result['comment_ID'], ARRAY_A ); |
| 5463 | $comments['comment_ID'] = isset( $actual_comment['comment_ID'] ) ? $actual_comment['comment_ID'] : ''; |
| 5464 | $comments['comment_post_ID'] = isset( $actual_comment['comment_post_ID'] ) ? $actual_comment['comment_post_ID'] : ''; |
| 5465 | $comments['comment_author'] = isset( $actual_comment['comment_author'] ) ? $actual_comment['comment_author'] : ''; |
| 5466 | $comments['comment_author_email'] = isset( $actual_comment['comment_author_email'] ) ? $actual_comment['comment_author_email'] : ''; |
| 5467 | $comments['comment_date'] = isset( $actual_comment['comment_date'] ) ? $actual_comment['comment_date'] : ''; |
| 5468 | $comments['comment_content'] = isset( $actual_comment['comment_content'] ) ? $actual_comment['comment_content'] : ''; |
| 5469 | $comments['comment_type'] = isset( $actual_comment['comment_type'] ) ? $actual_comment['comment_type'] : ''; |
| 5470 | $comments['comment_status'] = $get_comments->comment_content; |
| 5471 | $context['pluggable_data'] = $comments; |
| 5472 | $context['response_type'] = 'live'; |
| 5473 | } else { |
| 5474 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"comment_ID":"1","comment_post_ID":"1","comment_author":"test","comment_author_email":"test@test.com","comment_date":"2023-03-27 13:44:26","comment_content":"<p>Leave comment<\/p>","comment_type":"ph_comment","comment_status":"Resolved"}}', true ); |
| 5475 | } |
| 5476 | |
| 5477 | return $context; |
| 5478 | } |
| 5479 | |
| 5480 | /** |
| 5481 | * Get MasterStudy LMS Courses. |
| 5482 | * |
| 5483 | * @param array $data data. |
| 5484 | * |
| 5485 | * @return array |
| 5486 | */ |
| 5487 | public function search_ms_lms_courses( $data ) { |
| 5488 | |
| 5489 | $page = $data['page']; |
| 5490 | $limit = Utilities::get_search_page_limit(); |
| 5491 | $offset = $limit * ( $page - 1 ); |
| 5492 | |
| 5493 | $args = [ |
| 5494 | 'post_type' => 'stm-courses', |
| 5495 | 'posts_per_page' => $limit, |
| 5496 | 'offset' => $offset, |
| 5497 | 'orderby' => 'title', |
| 5498 | 'order' => 'ASC', |
| 5499 | 'post_status' => 'publish', |
| 5500 | ]; |
| 5501 | |
| 5502 | $courses = get_posts( $args ); |
| 5503 | |
| 5504 | $course_count = count( $courses ); |
| 5505 | |
| 5506 | $options = []; |
| 5507 | if ( ! empty( $courses ) ) { |
| 5508 | if ( is_array( $courses ) ) { |
| 5509 | foreach ( $courses as $course ) { |
| 5510 | $options[] = [ |
| 5511 | 'label' => $course->post_title, |
| 5512 | 'value' => $course->ID, |
| 5513 | ]; |
| 5514 | } |
| 5515 | } |
| 5516 | } |
| 5517 | return [ |
| 5518 | 'options' => $options, |
| 5519 | 'hasMore' => $course_count > $limit && $course_count > $offset, |
| 5520 | ]; |
| 5521 | |
| 5522 | } |
| 5523 | |
| 5524 | /** |
| 5525 | * Get MasterStudy LMS Lessons. |
| 5526 | * |
| 5527 | * @param array $data data. |
| 5528 | * |
| 5529 | * @return array |
| 5530 | */ |
| 5531 | public function search_ms_lms_lessons( $data ) { |
| 5532 | |
| 5533 | $page = $data['page']; |
| 5534 | $limit = Utilities::get_search_page_limit(); |
| 5535 | $offset = $limit * ( $page - 1 ); |
| 5536 | |
| 5537 | $args = [ |
| 5538 | 'post_type' => 'stm-lessons', |
| 5539 | 'posts_per_page' => $limit, |
| 5540 | 'offset' => $offset, |
| 5541 | 'orderby' => 'title', |
| 5542 | 'order' => 'ASC', |
| 5543 | 'post_status' => 'publish', |
| 5544 | ]; |
| 5545 | |
| 5546 | $lessons = get_posts( $args ); |
| 5547 | |
| 5548 | $lessons_count = count( $lessons ); |
| 5549 | |
| 5550 | $options = []; |
| 5551 | if ( ! empty( $lessons ) ) { |
| 5552 | if ( is_array( $lessons ) ) { |
| 5553 | foreach ( $lessons as $lesson ) { |
| 5554 | $options[] = [ |
| 5555 | 'label' => $lesson->post_title, |
| 5556 | 'value' => $lesson->ID, |
| 5557 | ]; |
| 5558 | } |
| 5559 | } |
| 5560 | } |
| 5561 | return [ |
| 5562 | 'options' => $options, |
| 5563 | 'hasMore' => $lessons_count > $limit && $lessons_count > $offset, |
| 5564 | ]; |
| 5565 | |
| 5566 | } |
| 5567 | |
| 5568 | /** |
| 5569 | * Search MasterStudy LMS data. |
| 5570 | * |
| 5571 | * @param array $data data. |
| 5572 | * @return array|void |
| 5573 | */ |
| 5574 | public function search_ms_lms_last_data( $data ) { |
| 5575 | global $wpdb; |
| 5576 | $post_type = $data['post_type']; |
| 5577 | $trigger = $data['search_term']; |
| 5578 | $context = []; |
| 5579 | |
| 5580 | if ( 'stm_lms_course_completed' === $trigger ) { |
| 5581 | $post_id = $data['filter']['course']['value']; |
| 5582 | if ( -1 === $post_id ) { |
| 5583 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.progress_percent=100 AND posts.post_type=%s order by postmeta.user_course_id DESC LIMIT 1", $post_type ) ); |
| 5584 | } else { |
| 5585 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.course_id = %s AND postmeta.progress_percent=100 AND posts.post_type=%s order by postmeta.user_course_id DESC LIMIT 1", $post_id, $post_type ) ); |
| 5586 | } |
| 5587 | } elseif ( 'stm_lesson_passed' === $trigger ) { |
| 5588 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_lessons as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.lesson_id WHERE posts.post_type=%s order by postmeta.user_lesson_id DESC LIMIT 1", $post_type ) ); |
| 5589 | } elseif ( 'stm_quiz_passed' === $trigger ) { |
| 5590 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_quizzes as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.quiz_id WHERE postmeta.status='passed' AND posts.post_type=%s order by postmeta.user_quiz_id DESC LIMIT 1", $post_type ) ); |
| 5591 | } elseif ( 'stm_quiz_failed' === $trigger ) { |
| 5592 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_quizzes as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.quiz_id WHERE postmeta.status='failed' AND posts.post_type=%s order by postmeta.user_quiz_id DESC LIMIT 1", $post_type ) ); |
| 5593 | } elseif ( 'stm_lms_user_enroll_course' === $trigger ) { |
| 5594 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.status='enrolled' AND posts.post_type=%s order by postmeta.user_course_id DESC LIMIT 1", $post_type ) ); |
| 5595 | } |
| 5596 | |
| 5597 | if ( ! empty( $result ) ) { |
| 5598 | |
| 5599 | switch ( $trigger ) { |
| 5600 | case 'stm_lms_course_completed': |
| 5601 | $result_course_id = $result[0]->course_id; |
| 5602 | $result_user_id = $result[0]->user_id; |
| 5603 | $course = get_the_title( $result_course_id ); |
| 5604 | $course_link = get_the_permalink( $result_course_id ); |
| 5605 | $featured_image = get_the_post_thumbnail_url( $result_course_id ); |
| 5606 | |
| 5607 | $data = [ |
| 5608 | 'course_id' => $result_course_id, |
| 5609 | 'course_title' => $course, |
| 5610 | 'course_link' => $course_link, |
| 5611 | 'course_featured_image' => $featured_image, |
| 5612 | 'course_progress' => $result[0]->progress_percent, |
| 5613 | ]; |
| 5614 | $context_data = array_merge( |
| 5615 | WordPress::get_user_context( $result_user_id ), |
| 5616 | $data |
| 5617 | ); |
| 5618 | break; |
| 5619 | case 'stm_lesson_passed': |
| 5620 | $result_lesson_id = $result[0]->lesson_id; |
| 5621 | $result_user_id = $result[0]->user_id; |
| 5622 | $lesson = get_the_title( $result_lesson_id ); |
| 5623 | $lesson_link = get_the_permalink( $result_lesson_id ); |
| 5624 | |
| 5625 | $data = [ |
| 5626 | 'lesson_id' => $result_lesson_id, |
| 5627 | 'lesson_title' => $lesson, |
| 5628 | 'lesson_link' => $lesson_link, |
| 5629 | ]; |
| 5630 | $context_data = array_merge( |
| 5631 | WordPress::get_user_context( $result_user_id ), |
| 5632 | $data |
| 5633 | ); |
| 5634 | break; |
| 5635 | case 'stm_quiz_passed': |
| 5636 | $result_quiz_id = $result[0]->quiz_id; |
| 5637 | $result_user_id = $result[0]->user_id; |
| 5638 | $quiz_title = get_the_title( $result_quiz_id ); |
| 5639 | $quiz_link = get_the_permalink( $result_quiz_id ); |
| 5640 | |
| 5641 | $data = [ |
| 5642 | 'quiz_id' => $result_quiz_id, |
| 5643 | 'quiz_title' => $quiz_title, |
| 5644 | 'quiz_link' => $quiz_link, |
| 5645 | 'quiz_score' => $result[0]->progress, |
| 5646 | 'result' => 'passed', |
| 5647 | ]; |
| 5648 | $context_data = array_merge( |
| 5649 | WordPress::get_user_context( $result_user_id ), |
| 5650 | $data |
| 5651 | ); |
| 5652 | break; |
| 5653 | case 'stm_quiz_failed': |
| 5654 | $result_quiz_id = $result[0]->quiz_id; |
| 5655 | $result_user_id = $result[0]->user_id; |
| 5656 | $quiz_title = get_the_title( $result_quiz_id ); |
| 5657 | $quiz_link = get_the_permalink( $result_quiz_id ); |
| 5658 | |
| 5659 | $data = [ |
| 5660 | 'quiz_id' => $result_quiz_id, |
| 5661 | 'quiz_title' => $quiz_title, |
| 5662 | 'quiz_link' => $quiz_link, |
| 5663 | 'quiz_score' => $result[0]->progress, |
| 5664 | 'result' => 'failed', |
| 5665 | ]; |
| 5666 | $context_data = array_merge( |
| 5667 | WordPress::get_user_context( $result_user_id ), |
| 5668 | $data |
| 5669 | ); |
| 5670 | break; |
| 5671 | case 'stm_lms_user_enroll_course': |
| 5672 | $result_course_id = $result[0]->course_id; |
| 5673 | $result_user_id = $result[0]->user_id; |
| 5674 | |
| 5675 | $course = get_the_title( $result_course_id ); |
| 5676 | $course_link = get_the_permalink( $result_course_id ); |
| 5677 | $featured_image = get_the_post_thumbnail_url( $result_course_id ); |
| 5678 | |
| 5679 | $data = [ |
| 5680 | 'course_id' => $result_course_id, |
| 5681 | 'course_title' => $course, |
| 5682 | 'course_link' => $course_link, |
| 5683 | 'course_featured_image' => $featured_image, |
| 5684 | ]; |
| 5685 | $context_data = array_merge( |
| 5686 | WordPress::get_user_context( $result_user_id ), |
| 5687 | $data |
| 5688 | ); |
| 5689 | break; |
| 5690 | default: |
| 5691 | return; |
| 5692 | } |
| 5693 | $context['pluggable_data'] = $context_data; |
| 5694 | $context['response_type'] = 'live'; |
| 5695 | } |
| 5696 | |
| 5697 | return $context; |
| 5698 | |
| 5699 | } |
| 5700 | |
| 5701 | |
| 5702 | /** |
| 5703 | * Get last data for trigger. |
| 5704 | * |
| 5705 | * @param array $data data. |
| 5706 | * @return array |
| 5707 | */ |
| 5708 | public function search_fluent_support_triggers_last_data( $data ) { |
| 5709 | $context = []; |
| 5710 | $context['response_type'] = 'sample'; |
| 5711 | |
| 5712 | $ticket_data = [ |
| 5713 | 'id' => '1', |
| 5714 | 'customer_id' => '2', |
| 5715 | 'agent_id' => '3', |
| 5716 | 'product_id' => '5', |
| 5717 | 'product_source' => 'local', |
| 5718 | 'privacy' => 'private', |
| 5719 | 'priority' => 'normal', |
| 5720 | 'client_priority' => 'medium', |
| 5721 | 'status' => 'active', |
| 5722 | 'title' => 'Sample Ticket Title', |
| 5723 | 'slug' => 'sample-ticket-title', |
| 5724 | 'hash' => 'f8a8cfb946', |
| 5725 | 'content_hash' => 'd65500d62621be8b493c22b1d888052c', |
| 5726 | 'content' => '<p>Sample content.</p>', |
| 5727 | 'last_customer_response' => '2023-04-27 07:30:46', |
| 5728 | 'waiting_since' => '2023-04-27 07:30:46', |
| 5729 | 'response_count' => '2', |
| 5730 | 'total_close_time' => '7042', |
| 5731 | 'resolved at' => '2023-04-27 09:28:08', |
| 5732 | 'closed_by' => '1', |
| 5733 | 'created_at' => '2023-04-27 07:30:46', |
| 5734 | 'updated_at' => '2023-04-27 10:28:08', |
| 5735 | 'mailbox_id' => '1', |
| 5736 | 'mailbox_name' => 'SureTriggers', |
| 5737 | 'mailbox_slug' => 'suretriggers', |
| 5738 | 'mailbox_box_type' => 'web', |
| 5739 | 'mailbox email' => 'john_doe@sample.com', |
| 5740 | 'mailbox_settings_admin_email_address' => 'john_doe@sample.com', |
| 5741 | 'mailbox_created_by' => '1', |
| 5742 | 'mailbox_is_default' => 'yes', |
| 5743 | 'mailbox_created_at' => '2023-04-26 06:29:01', |
| 5744 | 'mailbox_updated_at' => '2023-04-26 06:29:01', |
| 5745 | ]; |
| 5746 | |
| 5747 | $customer_data = [ |
| 5748 | 'id' => '1', |
| 5749 | 'first_name' => 'John', |
| 5750 | 'last_name' => 'Doe', |
| 5751 | 'email' => 'john_doe@sample.com', |
| 5752 | 'person_type' => 'agent', |
| 5753 | 'status' => 'active', |
| 5754 | 'hash' => '3b2b5f0432561cb81b1302b8a16b93a0', |
| 5755 | 'user_id' => '1', |
| 5756 | 'created_at' => '2023-04-27 07:30:46', |
| 5757 | 'updated_at' => '2023-04-27 10:28:08', |
| 5758 | 'full_name' => 'John Doe', |
| 5759 | 'photo' => 'https://www.gravatar.com/avatar/c2b06ae950033b392998ada50767b50e?s=128', |
| 5760 | ]; |
| 5761 | |
| 5762 | $reply_data = [ |
| 5763 | 'ticket_id' => '1', |
| 5764 | 'conversation_type' => 'response', |
| 5765 | 'content' => '<p>Sample content.</p>', |
| 5766 | 'source' => 'web', |
| 5767 | 'content_hash' => '2cc0e35d8fb92a0675d67999b073b3a4', |
| 5768 | 'created_at' => '2023-04-27 07:30:46', |
| 5769 | 'updated_at' => '2023-04-27 10:28:08', |
| 5770 | 'id' => '1', |
| 5771 | 'person_id' => '2', |
| 5772 | 'person_first_name' => 'John', |
| 5773 | 'person_last_name' => 'Doe', |
| 5774 | 'person_email' => 'john_doe@sample.com', |
| 5775 | 'person_person_type' => 'agent', |
| 5776 | 'person_status' => 'active', |
| 5777 | 'person_hash' => '3b2b5f0432561cb81b1302b8a16b93a0', |
| 5778 | 'person_user_id' => '1', |
| 5779 | 'person_created_at' => '2023-04-27 07:30:46', |
| 5780 | 'person_updated_at' => '2023-04-27 10:28:08', |
| 5781 | 'person_full_name' => 'John Doe', |
| 5782 | 'person_photo' => 'https://www.gravatar.com/avatar/c2b06ae950033b392998ada50767b50e?s=128', |
| 5783 | ]; |
| 5784 | |
| 5785 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 5786 | |
| 5787 | if ( in_array( $term, [ 'response_added_by_agent', 'response_added_by_customer' ], true ) ) { |
| 5788 | $context['pluggable_data'] = array_merge( |
| 5789 | [ |
| 5790 | 'reply' => $reply_data, |
| 5791 | 'ticket' => $ticket_data, |
| 5792 | 'customer' => $customer_data, |
| 5793 | ] |
| 5794 | ); |
| 5795 | } else { |
| 5796 | $context['pluggable_data'] = array_merge( |
| 5797 | [ |
| 5798 | 'ticket' => $ticket_data, |
| 5799 | 'customer' => $customer_data, |
| 5800 | ] |
| 5801 | ); |
| 5802 | } |
| 5803 | |
| 5804 | return $context; |
| 5805 | } |
| 5806 | |
| 5807 | /** |
| 5808 | * Prepare Ultimate Member user_roles. |
| 5809 | * |
| 5810 | * @param array $data data. |
| 5811 | * |
| 5812 | * @return array |
| 5813 | */ |
| 5814 | public function search_um_user_roles( $data ) { |
| 5815 | if ( function_exists( 'get_editable_roles' ) ) { |
| 5816 | $roles = get_editable_roles(); |
| 5817 | } else { |
| 5818 | $roles = wp_roles()->roles; |
| 5819 | $roles = apply_filters( 'editable_roles', $roles ); |
| 5820 | } |
| 5821 | |
| 5822 | $options = []; |
| 5823 | foreach ( $roles as $role => $details ) { |
| 5824 | |
| 5825 | $options[] = [ |
| 5826 | 'label' => $details['name'], |
| 5827 | 'value' => $role, |
| 5828 | ]; |
| 5829 | |
| 5830 | } |
| 5831 | |
| 5832 | return [ |
| 5833 | 'options' => $options, |
| 5834 | 'hasMore' => false, |
| 5835 | ]; |
| 5836 | } |
| 5837 | |
| 5838 | /** |
| 5839 | * Prepare Ultimate Member forms_list. |
| 5840 | * |
| 5841 | * @param array $data data. |
| 5842 | * |
| 5843 | * @return array |
| 5844 | */ |
| 5845 | public function search_um_forms_list( $data ) { |
| 5846 | |
| 5847 | $page = $data['page']; |
| 5848 | $limit = Utilities::get_search_page_limit(); |
| 5849 | $offset = $limit * ( $page - 1 ); |
| 5850 | |
| 5851 | $args = [ |
| 5852 | 'posts_per_page' => $limit, |
| 5853 | 'offset' => $offset, |
| 5854 | 'orderby' => 'title', |
| 5855 | 'order' => 'ASC', |
| 5856 | 'post_type' => 'um_form', |
| 5857 | 'post_status' => 'publish', |
| 5858 | 'fields' => 'ids', |
| 5859 | ]; |
| 5860 | |
| 5861 | $forms_list = get_posts( $args ); |
| 5862 | |
| 5863 | $forms_list_count = count( $forms_list ); |
| 5864 | |
| 5865 | $options = []; |
| 5866 | if ( ! empty( $forms_list ) ) { |
| 5867 | foreach ( $forms_list as $form ) { |
| 5868 | $options[] = [ |
| 5869 | 'label' => get_the_title( $form ), |
| 5870 | 'value' => $form, |
| 5871 | ]; |
| 5872 | } |
| 5873 | } |
| 5874 | |
| 5875 | return [ |
| 5876 | 'options' => $options, |
| 5877 | 'hasMore' => $forms_list_count > $limit && $forms_list_count > $offset, |
| 5878 | ]; |
| 5879 | } |
| 5880 | |
| 5881 | /** |
| 5882 | * Get last data for Ultimate Member Login trigger. |
| 5883 | * |
| 5884 | * @param array $data data. |
| 5885 | * @return mixed |
| 5886 | */ |
| 5887 | public function search_ultimate_member_user_logsin( $data ) { |
| 5888 | $context = []; |
| 5889 | $args = [ |
| 5890 | 'orderby' => 'meta_value', |
| 5891 | 'meta_key' => '_um_last_login', |
| 5892 | 'order' => 'DESC', |
| 5893 | 'number' => 1, |
| 5894 | ]; |
| 5895 | $users = get_users( $args ); |
| 5896 | |
| 5897 | if ( ! empty( $users ) ) { |
| 5898 | $user = $users[0]; |
| 5899 | $pluggable_data = WordPress::get_user_context( $user->ID ); |
| 5900 | $context['pluggable_data'] = $pluggable_data; |
| 5901 | $context['response_type'] = 'live'; |
| 5902 | } else { |
| 5903 | $role = 'subscriber'; |
| 5904 | $context['pluggable_data'] = [ |
| 5905 | 'wp_user_id' => 1, |
| 5906 | 'user_login' => 'test', |
| 5907 | 'display_name' => 'Test User', |
| 5908 | 'user_firstname' => 'Test', |
| 5909 | 'user_lastname' => 'User', |
| 5910 | 'user_email' => 'testuser@gmail.com', |
| 5911 | 'user_role' => [ $role ], |
| 5912 | ]; |
| 5913 | $context['response_type'] = 'sample'; |
| 5914 | } |
| 5915 | return $context; |
| 5916 | } |
| 5917 | |
| 5918 | /** |
| 5919 | * Get last data for Ultimate Member Register trigger. |
| 5920 | * |
| 5921 | * @param array $data data. |
| 5922 | * @return mixed |
| 5923 | */ |
| 5924 | public function search_ultimate_member_user_registers( $data ) { |
| 5925 | $context = []; |
| 5926 | $args = [ |
| 5927 | 'orderby' => 'meta_value', |
| 5928 | 'meta_key' => 'um_user_profile_url_slug_user_login', |
| 5929 | 'order' => 'DESC', |
| 5930 | 'number' => 1, |
| 5931 | ]; |
| 5932 | $users = get_users( $args ); |
| 5933 | |
| 5934 | if ( ! empty( $users ) ) { |
| 5935 | $user = $users[0]; |
| 5936 | $pluggable_data = WordPress::get_user_context( $user->ID ); |
| 5937 | $context['pluggable_data'] = $pluggable_data; |
| 5938 | $context['response_type'] = 'live'; |
| 5939 | } else { |
| 5940 | $role = 'subscriber'; |
| 5941 | $context['pluggable_data'] = [ |
| 5942 | 'wp_user_id' => 1, |
| 5943 | 'user_login' => 'test', |
| 5944 | 'display_name' => 'Test User', |
| 5945 | 'user_firstname' => 'Test', |
| 5946 | 'user_lastname' => 'User', |
| 5947 | 'user_email' => 'testuser@gmail.com', |
| 5948 | 'user_role' => [ $role ], |
| 5949 | ]; |
| 5950 | $context['response_type'] = 'sample'; |
| 5951 | } |
| 5952 | return $context; |
| 5953 | } |
| 5954 | |
| 5955 | /** |
| 5956 | * Get last data for Ultimate Member Register trigger. |
| 5957 | * |
| 5958 | * @param array $data data. |
| 5959 | * @return mixed |
| 5960 | */ |
| 5961 | public function search_ultimate_member_user_inactive( $data ) { |
| 5962 | $context = []; |
| 5963 | $args = [ |
| 5964 | 'orderby' => 'user_id', |
| 5965 | 'meta_key' => 'account_status', |
| 5966 | 'meta_value' => 'inactive', |
| 5967 | 'order' => 'ASC', |
| 5968 | 'number' => 1, |
| 5969 | ]; |
| 5970 | $users = get_users( $args ); |
| 5971 | |
| 5972 | if ( ! empty( $users ) ) { |
| 5973 | $user = $users[0]; |
| 5974 | $pluggable_data = []; |
| 5975 | $pluggable_data[] = WordPress::get_user_context( $user->ID ); |
| 5976 | $pluggable_data['user_account_status'] = 'inactive'; |
| 5977 | $context['pluggable_data'] = $pluggable_data; |
| 5978 | $context['response_type'] = 'live'; |
| 5979 | } else { |
| 5980 | $role = 'subscriber'; |
| 5981 | $context['pluggable_data'] = [ |
| 5982 | 'wp_user_id' => 1, |
| 5983 | 'user_login' => 'test', |
| 5984 | 'display_name' => 'Test User', |
| 5985 | 'user_firstname' => 'Test', |
| 5986 | 'user_lastname' => 'User', |
| 5987 | 'user_email' => 'testuser@gmail.com', |
| 5988 | 'user_role' => [ $role ], |
| 5989 | 'user_account_status' => 'inactive', |
| 5990 | ]; |
| 5991 | $context['response_type'] = 'sample'; |
| 5992 | } |
| 5993 | return $context; |
| 5994 | } |
| 5995 | |
| 5996 | /** |
| 5997 | * Get last data for Ultimate Member Change Role trigger. |
| 5998 | * |
| 5999 | * @param array $data data. |
| 6000 | * @return mixed |
| 6001 | */ |
| 6002 | public function search_ultimate_member_user_role_change( $data ) { |
| 6003 | $context = []; |
| 6004 | |
| 6005 | $role = $data['filter']['role']['value']; |
| 6006 | |
| 6007 | $args = [ |
| 6008 | 'number' => 1, |
| 6009 | 'role' => $role, |
| 6010 | ]; |
| 6011 | $users = get_users( $args ); |
| 6012 | shuffle( $users ); |
| 6013 | if ( ! empty( $users ) ) { |
| 6014 | $user = $users[0]; |
| 6015 | $pluggable_data = WordPress::get_user_context( $user->ID ); |
| 6016 | $context['pluggable_data'] = $pluggable_data; |
| 6017 | $context['response_type'] = 'live'; |
| 6018 | } else { |
| 6019 | $role = isset( $args['role'] ) ? $args['role'] : 'subscriber'; |
| 6020 | $context['pluggable_data'] = [ |
| 6021 | 'wp_user_id' => 1, |
| 6022 | 'user_login' => 'test', |
| 6023 | 'display_name' => 'Test User', |
| 6024 | 'user_firstname' => 'Test', |
| 6025 | 'user_lastname' => 'User', |
| 6026 | 'user_email' => 'testuser@gmail.com', |
| 6027 | 'user_role' => [ $role ], |
| 6028 | 'user_account_status' => 'inactive', |
| 6029 | ]; |
| 6030 | $context['response_type'] = 'sample'; |
| 6031 | } |
| 6032 | return $context; |
| 6033 | } |
| 6034 | |
| 6035 | /** |
| 6036 | * Get JetEngine WP Posttypes. |
| 6037 | * |
| 6038 | * @param array $data data. |
| 6039 | * |
| 6040 | * @return array |
| 6041 | */ |
| 6042 | public function search_je_posttype_list( $data ) { |
| 6043 | |
| 6044 | $post_types = get_post_types( [ 'public' => true ], 'object' ); |
| 6045 | $post_types = apply_filters( 'suretriggers_post_types', $post_types ); |
| 6046 | if ( isset( $post_types['attachment'] ) ) { |
| 6047 | unset( $post_types['attachment'] ); |
| 6048 | } |
| 6049 | |
| 6050 | $options = []; |
| 6051 | foreach ( $post_types as $post_type => $details ) { |
| 6052 | $options[] = [ |
| 6053 | 'label' => $details->label, |
| 6054 | 'value' => $post_type, |
| 6055 | ]; |
| 6056 | } |
| 6057 | |
| 6058 | return [ |
| 6059 | 'options' => $options, |
| 6060 | 'hasMore' => false, |
| 6061 | ]; |
| 6062 | } |
| 6063 | |
| 6064 | /** |
| 6065 | * Get JetEngine WP fields. |
| 6066 | * |
| 6067 | * @param array $data data. |
| 6068 | * |
| 6069 | * @return array |
| 6070 | */ |
| 6071 | public function search_je_field_list( $data ) { |
| 6072 | |
| 6073 | $post_type = $data['dynamic']; |
| 6074 | |
| 6075 | $metaboxes = (array) get_option( 'jet_engine_meta_boxes', [] ); |
| 6076 | |
| 6077 | $post_fields = array_filter( |
| 6078 | $metaboxes, |
| 6079 | function( $metabox ) { |
| 6080 | /** |
| 6081 | * |
| 6082 | * Ignore line |
| 6083 | * |
| 6084 | * @phpstan-ignore-next-line |
| 6085 | */ |
| 6086 | return 'post' === $metabox['args']['object_type']; |
| 6087 | } |
| 6088 | ); |
| 6089 | |
| 6090 | $post_fields_count = count( $post_fields ); |
| 6091 | |
| 6092 | $options = []; |
| 6093 | if ( ! empty( $post_fields ) ) { |
| 6094 | if ( is_array( $post_fields ) ) { |
| 6095 | foreach ( $post_fields as $post_field ) { |
| 6096 | if ( in_array( $post_type, $post_field['args']['allowed_post_type'], true ) ) { |
| 6097 | foreach ( $post_field['meta_fields'] as $meta_field ) { |
| 6098 | $options[] = [ |
| 6099 | 'label' => $meta_field['title'], |
| 6100 | 'value' => $meta_field['name'], |
| 6101 | ]; |
| 6102 | } |
| 6103 | } |
| 6104 | } |
| 6105 | } |
| 6106 | } |
| 6107 | return [ |
| 6108 | 'options' => $options, |
| 6109 | 'hasMore' => false, |
| 6110 | ]; |
| 6111 | } |
| 6112 | |
| 6113 | /** |
| 6114 | * Search Last Updated Field Data. |
| 6115 | * |
| 6116 | * @param array $data data. |
| 6117 | * @return array |
| 6118 | */ |
| 6119 | public function search_jet_engine_field_data( $data ) { |
| 6120 | global $wpdb; |
| 6121 | |
| 6122 | $context = []; |
| 6123 | |
| 6124 | $field = (int) ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); |
| 6125 | |
| 6126 | $post_type = $data['filter']['wp_post_type']['value']; |
| 6127 | |
| 6128 | if ( -1 === $field ) { |
| 6129 | $metaboxes = (array) get_option( 'jet_engine_meta_boxes', [] ); |
| 6130 | |
| 6131 | $post_fields = array_filter( |
| 6132 | $metaboxes, |
| 6133 | function( $metabox ) { |
| 6134 | /** |
| 6135 | * |
| 6136 | * Ignore line |
| 6137 | * |
| 6138 | * @phpstan-ignore-next-line |
| 6139 | */ |
| 6140 | return 'post' === $metabox['args']['object_type']; |
| 6141 | } |
| 6142 | ); |
| 6143 | |
| 6144 | $options = []; |
| 6145 | if ( ! empty( $post_fields ) ) { |
| 6146 | if ( is_array( $post_fields ) ) { |
| 6147 | foreach ( $post_fields as $post_field ) { |
| 6148 | if ( in_array( $post_type, $post_field['args']['allowed_post_type'], true ) ) { |
| 6149 | foreach ( $post_field['meta_fields'] as $meta_field ) { |
| 6150 | $options[] = $meta_field['name']; |
| 6151 | } |
| 6152 | } |
| 6153 | } |
| 6154 | } |
| 6155 | } |
| 6156 | $random_key = array_rand( $options ); |
| 6157 | $random_value = $options[ $random_key ]; |
| 6158 | $string = '%' . $random_value . '%'; |
| 6159 | } else { |
| 6160 | $string = '%' . $data['filter']['field_id']['value'] . '%'; |
| 6161 | } |
| 6162 | |
| 6163 | $result = $wpdb->get_results( |
| 6164 | $wpdb->prepare( |
| 6165 | 'SELECT post_id FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key LIKE %s', |
| 6166 | [ $string ] |
| 6167 | ), |
| 6168 | ARRAY_A |
| 6169 | ); |
| 6170 | |
| 6171 | $ids = []; |
| 6172 | |
| 6173 | if ( ! empty( $result ) ) { |
| 6174 | foreach ( $result as $val ) { |
| 6175 | $ids[] = $val['post_id']; |
| 6176 | } |
| 6177 | } |
| 6178 | |
| 6179 | $lastupdated_args = [ |
| 6180 | 'post_type' => $post_type, |
| 6181 | 'orderby' => 'modified', |
| 6182 | 'post__in' => $ids, |
| 6183 | 'posts_per_page' => 1, |
| 6184 | ]; |
| 6185 | $lastupdated_loop = get_posts( $lastupdated_args ); |
| 6186 | |
| 6187 | $response = []; |
| 6188 | if ( ! empty( $result ) ) { |
| 6189 | $context['post'] = $lastupdated_loop[0]; |
| 6190 | |
| 6191 | $meta_value = get_post_meta( $lastupdated_loop[0]->ID, sprintf( '%s', $data['filter']['field_id']['value'] ), true ); |
| 6192 | $meta_key = sprintf( '%s', $data['filter']['field_id']['value'] ); |
| 6193 | |
| 6194 | $context[ $meta_key ] = $meta_value; |
| 6195 | |
| 6196 | $response['pluggable_data'] = $context; |
| 6197 | $response['response_type'] = 'live'; |
| 6198 | } else { |
| 6199 | $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:\/\/suretriggerswp.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 ); |
| 6200 | } |
| 6201 | |
| 6202 | return $response; |
| 6203 | |
| 6204 | } |
| 6205 | |
| 6206 | /** |
| 6207 | * Get Formidable Forms. |
| 6208 | * |
| 6209 | * @param array $data data. |
| 6210 | * |
| 6211 | * @return array|void |
| 6212 | */ |
| 6213 | public function search_formidable_form_list( $data ) { |
| 6214 | if ( ! class_exists( 'FrmForm' ) ) { |
| 6215 | return; |
| 6216 | } |
| 6217 | |
| 6218 | $query = [ |
| 6219 | [ |
| 6220 | 'or' => 1, |
| 6221 | 'parent_form_id' => null, |
| 6222 | 'parent_form_id <' => 1, |
| 6223 | ], |
| 6224 | ]; |
| 6225 | $query['is_template'] = 0; |
| 6226 | $query['status !'] = 'trash'; |
| 6227 | $forms_list = FrmForm::getAll( $query, '', ' 0, 10' ); |
| 6228 | |
| 6229 | $options = []; |
| 6230 | |
| 6231 | if ( ! empty( $forms_list ) ) { |
| 6232 | if ( is_array( $forms_list ) ) { |
| 6233 | foreach ( $forms_list as $form ) { |
| 6234 | $options[] = [ |
| 6235 | 'label' => $form->name, |
| 6236 | 'value' => $form->id, |
| 6237 | ]; |
| 6238 | } |
| 6239 | } |
| 6240 | } |
| 6241 | |
| 6242 | return [ |
| 6243 | 'options' => $options, |
| 6244 | 'hasMore' => false, |
| 6245 | ]; |
| 6246 | } |
| 6247 | |
| 6248 | /** |
| 6249 | * Get JetFormBuilder Form List. |
| 6250 | * |
| 6251 | * @param array $data data. |
| 6252 | * |
| 6253 | * @return array|void |
| 6254 | */ |
| 6255 | public function search_jetform_list( $data ) { |
| 6256 | if ( ! class_exists( '\Jet_Form_Builder\Classes\Tools' ) ) { |
| 6257 | return; |
| 6258 | } |
| 6259 | |
| 6260 | $forms = \Jet_Form_Builder\Classes\Tools::get_forms_list_for_js(); |
| 6261 | |
| 6262 | $options = []; |
| 6263 | foreach ( $forms as $form ) { |
| 6264 | |
| 6265 | if ( ! empty( $form['value'] ) ) { |
| 6266 | $options[] = [ |
| 6267 | 'label' => esc_html( $form['label'] ), |
| 6268 | 'value' => esc_attr( $form['value'] ), |
| 6269 | ]; |
| 6270 | } |
| 6271 | } |
| 6272 | |
| 6273 | return [ |
| 6274 | 'options' => $options, |
| 6275 | 'hasMore' => false, |
| 6276 | ]; |
| 6277 | } |
| 6278 | |
| 6279 | /** |
| 6280 | * Get Forminator Form List. |
| 6281 | * |
| 6282 | * @param array $data data. |
| 6283 | * |
| 6284 | * @return array|void |
| 6285 | */ |
| 6286 | public function search_forminator_form_list( $data ) { |
| 6287 | if ( ! class_exists( 'Forminator_API' ) ) { |
| 6288 | return; |
| 6289 | } |
| 6290 | |
| 6291 | $forms = Forminator_API::get_forms( null, 1, 10 ); |
| 6292 | |
| 6293 | $options = []; |
| 6294 | foreach ( $forms as $form ) { |
| 6295 | $options[] = [ |
| 6296 | 'label' => isset( $form->settings ) && isset( $form->settings['form_name'] ) ? $form->settings['form_name'] : $form->name, |
| 6297 | 'value' => $form->id, |
| 6298 | ]; |
| 6299 | } |
| 6300 | |
| 6301 | return [ |
| 6302 | 'options' => $options, |
| 6303 | 'hasMore' => false, |
| 6304 | ]; |
| 6305 | } |
| 6306 | |
| 6307 | |
| 6308 | /** |
| 6309 | * Get BbPress topics list. |
| 6310 | * |
| 6311 | * @param array $data data. |
| 6312 | * |
| 6313 | * @return array|void |
| 6314 | */ |
| 6315 | public function search_bbp_topic_list( $data ) { |
| 6316 | $page = $data['page']; |
| 6317 | $forum_id = $data['dynamic']; |
| 6318 | $limit = Utilities::get_search_page_limit(); |
| 6319 | $offset = $limit * ( $page - 1 ); |
| 6320 | $args = [ |
| 6321 | 'post_type' => 'topic', |
| 6322 | 'offset' => $offset, |
| 6323 | 'meta_query' => [ |
| 6324 | [ |
| 6325 | 'key' => '_bbp_forum_id', |
| 6326 | 'value' => $forum_id, |
| 6327 | 'compare' => '==', |
| 6328 | ], |
| 6329 | ], |
| 6330 | ]; |
| 6331 | |
| 6332 | $topics = get_posts( $args ); |
| 6333 | $topics_count = count( $topics ); |
| 6334 | |
| 6335 | $options = []; |
| 6336 | if ( ! empty( $topics ) ) { |
| 6337 | if ( is_array( $topics ) ) { |
| 6338 | foreach ( $topics as $topic ) { |
| 6339 | $options[] = [ |
| 6340 | 'label' => $topic->post_title, |
| 6341 | 'value' => $topic->ID, |
| 6342 | ]; |
| 6343 | } |
| 6344 | } |
| 6345 | } |
| 6346 | return [ |
| 6347 | 'options' => $options, |
| 6348 | 'hasMore' => $topics_count > $limit && $topics_count > $offset, |
| 6349 | ]; |
| 6350 | } |
| 6351 | |
| 6352 | |
| 6353 | /** |
| 6354 | * Search Last Updated Field Data. |
| 6355 | * |
| 6356 | * @param array $data data. |
| 6357 | * @return array |
| 6358 | */ |
| 6359 | public function search_bbp_last_data( $data ) { |
| 6360 | global $wpdb; |
| 6361 | |
| 6362 | $post_type = $data['post_type']; |
| 6363 | $trigger = $data['search_term']; |
| 6364 | $context = []; |
| 6365 | |
| 6366 | if ( 'topic' === $post_type ) { |
| 6367 | $post_id = $data['filter']['forum']['value']; |
| 6368 | if ( -1 === $post_id ) { |
| 6369 | $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" ); |
| 6370 | |
| 6371 | } else { |
| 6372 | $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 ) ); |
| 6373 | |
| 6374 | } |
| 6375 | } elseif ( 'reply' === $post_type ) { |
| 6376 | $post_id = $data['filter']['topic']['value']; |
| 6377 | |
| 6378 | if ( -1 === $post_id ) { |
| 6379 | $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" ); |
| 6380 | |
| 6381 | } else { |
| 6382 | $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 ) ); |
| 6383 | } |
| 6384 | } |
| 6385 | |
| 6386 | |
| 6387 | $response = []; |
| 6388 | if ( ! empty( $result ) ) { |
| 6389 | if ( 'bbpress_topic_created' === $trigger ) { |
| 6390 | $topic_id = $result[0]->post_id; |
| 6391 | $forum_id = $result[0]->meta_value; |
| 6392 | $topic = get_the_title( $topic_id ); |
| 6393 | $topic_link = get_the_permalink( $topic_id ); |
| 6394 | $topic_description = get_the_content( $topic_id ); |
| 6395 | $topic_status = get_post_status( $topic_id ); |
| 6396 | |
| 6397 | $forum = get_the_title( $forum_id ); |
| 6398 | $forum_link = get_the_permalink( $forum_id ); |
| 6399 | $forum_description = get_the_content( $forum_id ); |
| 6400 | $forum_status = get_post_status( $forum_id ); |
| 6401 | |
| 6402 | $forum = [ |
| 6403 | 'forum' => $forum_id, |
| 6404 | 'forum_title' => $forum, |
| 6405 | 'forum_link' => $forum_link, |
| 6406 | 'forum_description' => $forum_description, |
| 6407 | 'forum_status' => $forum_status, |
| 6408 | ]; |
| 6409 | |
| 6410 | $topic = [ |
| 6411 | 'topic_title' => $topic, |
| 6412 | 'topic_link' => $topic_link, |
| 6413 | 'topic_description' => $topic_description, |
| 6414 | 'topic_status' => $topic_status, |
| 6415 | ]; |
| 6416 | |
| 6417 | $user_id = $result[0]->post_author; |
| 6418 | $context = array_merge( |
| 6419 | WordPress::get_user_context( $user_id ), |
| 6420 | $forum, |
| 6421 | $topic |
| 6422 | ); |
| 6423 | |
| 6424 | $response['pluggable_data'] = $context; |
| 6425 | $response['response_type'] = 'live'; |
| 6426 | } else { |
| 6427 | $reply_id = $result[0]->post_id; |
| 6428 | $topic_id = $result[0]->meta_value; |
| 6429 | $forum_id = get_post_meta( $topic_id, '_bbp_forum_id', true ); |
| 6430 | $forum_id = intval( '"' . $forum_id . '"' ); |
| 6431 | $reply = get_the_title( $reply_id ); |
| 6432 | $reply_link = get_the_permalink( $reply_id ); |
| 6433 | $reply_description = get_the_content( $reply_id ); |
| 6434 | $reply_status = get_post_status( $reply_id ); |
| 6435 | |
| 6436 | |
| 6437 | $topic = get_the_title( $topic_id ); |
| 6438 | $topic_link = get_the_permalink( $topic_id ); |
| 6439 | $topic_description = get_the_content( $topic_id ); |
| 6440 | $topic_status = get_post_status( $topic_id ); |
| 6441 | |
| 6442 | $forum = get_the_title( $forum_id ); |
| 6443 | $forum_link = get_the_permalink( $forum_id ); |
| 6444 | $forum_description = get_the_content( null, false, $forum_id ); |
| 6445 | $forum_status = get_post_status( $forum_id ); |
| 6446 | |
| 6447 | $forum = [ |
| 6448 | 'forum' => $forum_id, |
| 6449 | 'forum_title' => $forum, |
| 6450 | 'forum_link' => $forum_link, |
| 6451 | 'forum_description' => $forum_description, |
| 6452 | 'forum_status' => $forum_status, |
| 6453 | ]; |
| 6454 | |
| 6455 | $topic = [ |
| 6456 | 'topic_title' => $topic, |
| 6457 | 'topic_link' => $topic_link, |
| 6458 | 'topic_description' => $topic_description, |
| 6459 | 'topic_status' => $topic_status, |
| 6460 | ]; |
| 6461 | |
| 6462 | $reply = [ |
| 6463 | 'reply_title' => $reply, |
| 6464 | 'reply_link' => $reply_link, |
| 6465 | 'reply_description' => $reply_description, |
| 6466 | 'reply_status' => $reply_status, |
| 6467 | ]; |
| 6468 | $user_id = $result[0]->post_author; |
| 6469 | $context = array_merge( |
| 6470 | WordPress::get_user_context( $user_id ), |
| 6471 | $forum, |
| 6472 | $topic, |
| 6473 | $reply |
| 6474 | ); |
| 6475 | |
| 6476 | $response['pluggable_data'] = $context; |
| 6477 | $response['response_type'] = 'live'; |
| 6478 | } |
| 6479 | } |
| 6480 | |
| 6481 | return $response; |
| 6482 | } |
| 6483 | |
| 6484 | /** |
| 6485 | * Search Last Updated Field Data. |
| 6486 | * |
| 6487 | * @param array $data data. |
| 6488 | * @return array|void |
| 6489 | */ |
| 6490 | public function search_happyform_list( $data ) { |
| 6491 | if ( ! function_exists( 'happyforms_get_form_controller' ) ) { |
| 6492 | return; |
| 6493 | } |
| 6494 | |
| 6495 | $form_controller = happyforms_get_form_controller(); |
| 6496 | |
| 6497 | $forms = $form_controller->do_get(); |
| 6498 | $options = []; |
| 6499 | if ( ! empty( $forms ) ) { |
| 6500 | foreach ( $forms as $form ) { |
| 6501 | $options[] = [ |
| 6502 | 'label' => $form['post_title'], |
| 6503 | 'value' => $form['ID'], |
| 6504 | ]; |
| 6505 | } |
| 6506 | } |
| 6507 | |
| 6508 | return [ |
| 6509 | 'options' => $options, |
| 6510 | 'hasMore' => false, |
| 6511 | ]; |
| 6512 | } |
| 6513 | |
| 6514 | /** |
| 6515 | * Get Memberpress Course List. |
| 6516 | * |
| 6517 | * @param array $data data. |
| 6518 | * |
| 6519 | * @return array|void |
| 6520 | */ |
| 6521 | public function search_mpc_lessons_list( $data ) { |
| 6522 | if ( ! class_exists( '\memberpress\courses\models\Lesson' ) ) { |
| 6523 | return; |
| 6524 | } |
| 6525 | global $wpdb; |
| 6526 | $options = []; |
| 6527 | $course_id = $data['dynamic']; |
| 6528 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mpcs_sections WHERE course_id =%s", $course_id ) ); |
| 6529 | $sections = []; |
| 6530 | foreach ( $result as $rec ) { |
| 6531 | $sections[] = [ |
| 6532 | 'id' => $rec->id, |
| 6533 | 'title' => $rec->title, |
| 6534 | ]; |
| 6535 | } |
| 6536 | if ( is_array( $sections ) && count( $sections ) > 0 ) { |
| 6537 | foreach ( $sections as $section ) { |
| 6538 | $post_types_string = \memberpress\courses\models\Lesson::lesson_cpts(); |
| 6539 | $post_types_string = implode( "','", $post_types_string ); |
| 6540 | |
| 6541 | $query = $wpdb->prepare( |
| 6542 | "SELECT * FROM {$wpdb->posts} AS p |
| 6543 | JOIN {$wpdb->postmeta} AS pm |
| 6544 | ON p.ID = pm.post_id |
| 6545 | AND pm.meta_key = %s |
| 6546 | AND pm.meta_value = %s |
| 6547 | JOIN {$wpdb->postmeta} AS pm_order |
| 6548 | ON p.ID = pm_order.post_id |
| 6549 | AND pm_order.meta_key = %s |
| 6550 | WHERE p.post_type in ( %s ) AND p.post_status <> 'trash' |
| 6551 | ORDER BY pm_order.meta_value * 1", |
| 6552 | models\Lesson::$section_id_str, |
| 6553 | $section['id'], |
| 6554 | models\Lesson::$lesson_order_str, |
| 6555 | stripcslashes( $post_types_string ) |
| 6556 | ); |
| 6557 | |
| 6558 | $db_lessons = $wpdb->get_results( stripcslashes( $query ) ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 6559 | foreach ( $db_lessons as $lesson ) { |
| 6560 | $options[] = [ |
| 6561 | 'label' => $section['title'] . '->' . $lesson->post_title, |
| 6562 | 'value' => $lesson->ID, |
| 6563 | ]; |
| 6564 | } |
| 6565 | } |
| 6566 | } |
| 6567 | return [ |
| 6568 | 'options' => $options, |
| 6569 | 'hasMore' => false, |
| 6570 | ]; |
| 6571 | } |
| 6572 | |
| 6573 | /** |
| 6574 | * Get Memberpress Course List. |
| 6575 | * |
| 6576 | * @param array $data data. |
| 6577 | * |
| 6578 | * @return array|void |
| 6579 | */ |
| 6580 | public function search_gp_rank_type_list( $data ) { |
| 6581 | global $wpdb; |
| 6582 | |
| 6583 | $posts = $wpdb->get_results( |
| 6584 | "SELECT ID, post_name, post_title, post_type |
| 6585 | FROM $wpdb->posts |
| 6586 | WHERE post_type LIKE 'rank-type' AND post_status = 'publish' ORDER BY post_title ASC" |
| 6587 | ); |
| 6588 | |
| 6589 | $posts_count = count( $posts ); |
| 6590 | |
| 6591 | $options = []; |
| 6592 | if ( $posts ) { |
| 6593 | foreach ( $posts as $post ) { |
| 6594 | $options[] = [ |
| 6595 | 'label' => $post->post_title, |
| 6596 | 'value' => $post->post_name, |
| 6597 | ]; |
| 6598 | } |
| 6599 | } |
| 6600 | |
| 6601 | return [ |
| 6602 | 'options' => $options, |
| 6603 | 'hasMore' => false, |
| 6604 | ]; |
| 6605 | } |
| 6606 | |
| 6607 | /** |
| 6608 | * Get MPC last data. |
| 6609 | * |
| 6610 | * @param array $data data. |
| 6611 | * |
| 6612 | * @return array |
| 6613 | */ |
| 6614 | public function search_mpc_last_data( $data ) { |
| 6615 | global $wpdb; |
| 6616 | $trigger = $data['search_term']; |
| 6617 | $course_data = []; |
| 6618 | $lesson_data = []; |
| 6619 | $context = []; |
| 6620 | |
| 6621 | if ( 'mpc_course_completed' === $trigger ) { |
| 6622 | $course_id = (int) ( isset( $data['filter']['course']['value'] ) ? $data['filter']['course]']['value'] : '-1' ); |
| 6623 | if ( $course_id > 0 ) { |
| 6624 | |
| 6625 | $course = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE ID= %s ORDER BY id DESC LIMIT 1", $course_id ) ); |
| 6626 | } else { |
| 6627 | $course = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}posts where post_type = 'mpcs-course' ORDER BY id DESC LIMIT 1" ); |
| 6628 | } |
| 6629 | |
| 6630 | if ( ! empty( $course ) ) { |
| 6631 | $course_data = [ |
| 6632 | 'course_id' => $course->ID, |
| 6633 | 'course_title' => get_the_title( $course_id ), |
| 6634 | 'course_url' => get_permalink( $course_id ), |
| 6635 | 'course_featured_image_id' => get_post_meta( $course_id, '_thumbnail_id', true ), |
| 6636 | 'course_featured_image_url' => get_the_post_thumbnail_url( $course_id ), |
| 6637 | ]; |
| 6638 | } |
| 6639 | $user_progress = $wpdb->get_row( $wpdb->prepare( "SELECT user_id FROM {$wpdb->prefix}mpcs_user_progress WHERE course_id=%s", $course_id ) ); |
| 6640 | if ( ! empty( $user_progress ) ) { |
| 6641 | $context['response_type'] = 'live'; |
| 6642 | $context['pluggable_data'] = array_merge( WordPress::get_user_context( $user_progress->user_id ), $course_data, $lesson_data ); |
| 6643 | } else { |
| 6644 | $sample_data = '{"pluggable_data":{"wp_user_id":1,"user_login":"suretriggers","display_name":"suretriggers","user_firstname":"suretriggers","user_lastname":"suretriggers","user_email":"hello@suretriggers.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} |
| 6645 | ,"response_type":"sample"} '; |
| 6646 | $context = json_decode( $sample_data, true ); |
| 6647 | } |
| 6648 | } elseif ( 'mpc_lesson_completed' === $trigger ) { |
| 6649 | $lesson_id = (int) ( isset( $data['filter']['lesson']['value'] ) ? $data['filter']['lesson']['value'] : '-1' ); |
| 6650 | $course_id = (int) $data['filter']['course']['value']; |
| 6651 | if ( $lesson_id > 0 ) { |
| 6652 | |
| 6653 | $lesson = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE ID= %s ORDER BY id DESC LIMIT 1", $lesson_id ) ); |
| 6654 | } else { |
| 6655 | $lesson = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}posts where post_type = 'mpcs-lesson' ORDER BY id DESC LIMIT 1" ); |
| 6656 | } |
| 6657 | |
| 6658 | if ( ! empty( $lesson ) ) { |
| 6659 | $lesson_data = [ |
| 6660 | 'lesson_id' => $lesson->ID, |
| 6661 | 'lesson_title' => get_the_title( $lesson_id ), |
| 6662 | 'lesson_url' => get_permalink( $lesson_id ), |
| 6663 | 'lesson_featured_image_id' => get_post_meta( $lesson_id, '_thumbnail_id', true ), |
| 6664 | 'lesson_featured_image_url' => get_the_post_thumbnail_url( $lesson_id ), |
| 6665 | ]; |
| 6666 | |
| 6667 | $lesson_section_id = get_post_meta( $lesson->ID, '_mpcs_lesson_section_id', true ); |
| 6668 | |
| 6669 | $section = $wpdb->get_row( $wpdb->prepare( "SELECT course_id FROM {$wpdb->prefix}mpcs_sections WHERE ID= %s", $lesson_section_id ) ); |
| 6670 | |
| 6671 | $course_data = [ |
| 6672 | 'course_id' => $course_id, |
| 6673 | 'course_title' => get_the_title( $course_id ), |
| 6674 | 'course_url' => get_permalink( $course_id ), |
| 6675 | 'course_featured_image_id' => get_post_meta( $course_id, '_thumbnail_id', true ), |
| 6676 | 'course_featured_image_url' => get_the_post_thumbnail_url( $section->course_id ), |
| 6677 | ]; |
| 6678 | } |
| 6679 | |
| 6680 | $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 ) ); |
| 6681 | if ( ! empty( $user_progress ) ) { |
| 6682 | $context['response_type'] = 'live'; |
| 6683 | $context['pluggable_data'] = array_merge( WordPress::get_user_context( $user_progress->user_id ), $course_data, $lesson_data ); |
| 6684 | } else { |
| 6685 | $sample_data = '{"pluggable_data":{"wp_user_id":1,"user_login":"suretriggers","display_name":"suretriggers","user_firstname":"suretriggers","user_lastname":"dev","user_email":"hello@suretriggers.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"}'; |
| 6686 | $context = json_decode( $sample_data, true ); |
| 6687 | } |
| 6688 | } |
| 6689 | |
| 6690 | |
| 6691 | return $context; |
| 6692 | } |
| 6693 | |
| 6694 | /** Get GamiPress Rank List. |
| 6695 | * |
| 6696 | * @param array $data data. |
| 6697 | * |
| 6698 | * @return array|void |
| 6699 | */ |
| 6700 | public function search_gp_rank_list( $data ) { |
| 6701 | global $wpdb; |
| 6702 | |
| 6703 | $page = $data['page']; |
| 6704 | $limit = Utilities::get_search_page_limit(); |
| 6705 | $offset = $limit * ( $page - 1 ); |
| 6706 | |
| 6707 | $args = [ |
| 6708 | 'post_type' => $data['dynamic']['rank_type'], |
| 6709 | 'posts_per_page' => $limit, |
| 6710 | 'offset' => $offset, |
| 6711 | 'orderby' => 'title', |
| 6712 | 'order' => 'ASC', |
| 6713 | 'post_status' => 'publish', |
| 6714 | ]; |
| 6715 | |
| 6716 | $rank_type = get_posts( $args ); |
| 6717 | $rank_type_count = count( $rank_type ); |
| 6718 | |
| 6719 | $options = []; |
| 6720 | if ( $rank_type ) { |
| 6721 | foreach ( $rank_type as $rank ) { |
| 6722 | $options[] = [ |
| 6723 | 'label' => $rank->post_title, |
| 6724 | 'value' => $rank->ID, |
| 6725 | ]; |
| 6726 | } |
| 6727 | } |
| 6728 | |
| 6729 | return [ |
| 6730 | 'options' => $options, |
| 6731 | 'hasMore' => $rank_type_count > $limit && $rank_type_count > $offset, |
| 6732 | ]; |
| 6733 | } |
| 6734 | |
| 6735 | /** |
| 6736 | * Get GamiPress PointType List. |
| 6737 | * |
| 6738 | * @param array $data data. |
| 6739 | * |
| 6740 | * @return array|void |
| 6741 | */ |
| 6742 | public function search_gp_point_type_list( $data ) { |
| 6743 | global $wpdb; |
| 6744 | |
| 6745 | $page = $data['page']; |
| 6746 | $limit = Utilities::get_search_page_limit(); |
| 6747 | $offset = $limit * ( $page - 1 ); |
| 6748 | |
| 6749 | $args = [ |
| 6750 | 'post_type' => 'points-type', |
| 6751 | 'posts_per_page' => $limit, |
| 6752 | 'offset' => $offset, |
| 6753 | 'orderby' => 'title', |
| 6754 | 'order' => 'ASC', |
| 6755 | 'post_status' => 'publish', |
| 6756 | ]; |
| 6757 | |
| 6758 | $point_type = get_posts( $args ); |
| 6759 | $point_type_count = count( $point_type ); |
| 6760 | |
| 6761 | $options = []; |
| 6762 | if ( $point_type ) { |
| 6763 | foreach ( $point_type as $point ) { |
| 6764 | $options[] = [ |
| 6765 | 'label' => $point->post_title, |
| 6766 | 'value' => $point->ID, |
| 6767 | ]; |
| 6768 | } |
| 6769 | } |
| 6770 | |
| 6771 | return [ |
| 6772 | 'options' => $options, |
| 6773 | 'hasMore' => $point_type_count > $limit && $point_type_count > $offset, |
| 6774 | ]; |
| 6775 | } |
| 6776 | |
| 6777 | /** |
| 6778 | * Get GamiPress AchievementType List. |
| 6779 | * |
| 6780 | * @param array $data data. |
| 6781 | * |
| 6782 | * @return array|void |
| 6783 | */ |
| 6784 | public function search_gp_achivement_type_list( $data ) { |
| 6785 | global $wpdb; |
| 6786 | |
| 6787 | $posts = $wpdb->get_results( |
| 6788 | "SELECT ID, post_name, post_title, post_type |
| 6789 | FROM $wpdb->posts |
| 6790 | WHERE post_type LIKE 'achievement-type' AND post_status = 'publish' ORDER BY post_title ASC" |
| 6791 | ); |
| 6792 | |
| 6793 | $posts_count = count( $posts ); |
| 6794 | |
| 6795 | $options = []; |
| 6796 | if ( $posts ) { |
| 6797 | foreach ( $posts as $post ) { |
| 6798 | $options[] = [ |
| 6799 | 'label' => $post->post_title, |
| 6800 | 'value' => $post->post_name, |
| 6801 | ]; |
| 6802 | } |
| 6803 | } |
| 6804 | |
| 6805 | $options[] = [ |
| 6806 | 'label' => 'Points awards', |
| 6807 | 'value' => 'points-award', |
| 6808 | ]; |
| 6809 | $options[] = [ |
| 6810 | 'label' => 'Step', |
| 6811 | 'value' => 'step', |
| 6812 | ]; |
| 6813 | $options[] = [ |
| 6814 | 'label' => 'Rank requirement', |
| 6815 | 'value' => 'rank-requirement', |
| 6816 | ]; |
| 6817 | |
| 6818 | return [ |
| 6819 | 'options' => $options, |
| 6820 | 'hasMore' => false, |
| 6821 | ]; |
| 6822 | } |
| 6823 | |
| 6824 | /** |
| 6825 | * Get GamiPress Award List. |
| 6826 | * |
| 6827 | * @param array $data data. |
| 6828 | * |
| 6829 | * @return array|void |
| 6830 | */ |
| 6831 | public function search_gp_award_list( $data ) { |
| 6832 | global $wpdb; |
| 6833 | |
| 6834 | $page = $data['page']; |
| 6835 | $limit = Utilities::get_search_page_limit(); |
| 6836 | $offset = $limit * ( $page - 1 ); |
| 6837 | |
| 6838 | $args = [ |
| 6839 | 'post_type' => $data['dynamic']['achivement_type'], |
| 6840 | 'posts_per_page' => $limit, |
| 6841 | 'offset' => $offset, |
| 6842 | 'orderby' => 'title', |
| 6843 | 'order' => 'ASC', |
| 6844 | 'post_status' => 'publish', |
| 6845 | ]; |
| 6846 | |
| 6847 | $award_type = get_posts( $args ); |
| 6848 | $award_type_count = count( $award_type ); |
| 6849 | |
| 6850 | $options = []; |
| 6851 | if ( $award_type ) { |
| 6852 | foreach ( $award_type as $award ) { |
| 6853 | $options[] = [ |
| 6854 | 'label' => $award->post_title, |
| 6855 | 'value' => $award->ID, |
| 6856 | ]; |
| 6857 | } |
| 6858 | } |
| 6859 | |
| 6860 | return [ |
| 6861 | 'options' => $options, |
| 6862 | 'hasMore' => $award_type_count > $limit && $award_type_count > $offset, |
| 6863 | ]; |
| 6864 | } |
| 6865 | |
| 6866 | /** |
| 6867 | * Get Woocommerce Subscription Product List. |
| 6868 | * |
| 6869 | * @param array $data data. |
| 6870 | * |
| 6871 | * @return array|void |
| 6872 | */ |
| 6873 | public function search_wc_subscription_product_list( $data ) { |
| 6874 | global $wpdb; |
| 6875 | |
| 6876 | $subscriptions = $wpdb->get_results( |
| 6877 | $wpdb->prepare( |
| 6878 | "SELECT posts.ID, posts.post_title FROM $wpdb->posts as posts |
| 6879 | LEFT JOIN $wpdb->term_relationships as rel ON (posts.ID = rel.object_id) |
| 6880 | WHERE rel.term_taxonomy_id IN (SELECT term_id FROM $wpdb->terms WHERE slug IN ('subscription','variable-subscription')) |
| 6881 | AND posts.post_type = %s |
| 6882 | AND posts.post_status = %s |
| 6883 | UNION ALL |
| 6884 | SELECT ID, post_title FROM $wpdb->posts |
| 6885 | WHERE post_type = %s |
| 6886 | AND post_status = %s |
| 6887 | ORDER BY post_title", |
| 6888 | 'product', |
| 6889 | 'publish', |
| 6890 | 'shop_subscription', |
| 6891 | 'publish' |
| 6892 | ) |
| 6893 | ); |
| 6894 | |
| 6895 | $options = []; |
| 6896 | if ( $subscriptions ) { |
| 6897 | foreach ( $subscriptions as $post ) { |
| 6898 | $options[] = [ |
| 6899 | 'label' => $post->post_title, |
| 6900 | 'value' => $post->ID, |
| 6901 | ]; |
| 6902 | } |
| 6903 | } |
| 6904 | |
| 6905 | return [ |
| 6906 | 'options' => $options, |
| 6907 | 'hasMore' => false, |
| 6908 | ]; |
| 6909 | } |
| 6910 | |
| 6911 | /** |
| 6912 | * Get Woocommerce Subscriptions Variation list. |
| 6913 | * |
| 6914 | * @param array $data data. |
| 6915 | * |
| 6916 | * @return array|void |
| 6917 | */ |
| 6918 | public function search_wc_variable_subscription_list( $data ) { |
| 6919 | global $wpdb; |
| 6920 | |
| 6921 | $page = $data['page']; |
| 6922 | $limit = Utilities::get_search_page_limit(); |
| 6923 | $offset = $limit * ( $page - 1 ); |
| 6924 | |
| 6925 | if ( ! function_exists( 'wc_get_products' ) ) { |
| 6926 | return; |
| 6927 | } |
| 6928 | $subscription_products = wc_get_products( |
| 6929 | [ |
| 6930 | 'type' => [ 'variable-subscription' ], |
| 6931 | 'posts_per_page' => $limit, |
| 6932 | 'offset' => $offset, |
| 6933 | 'orderby' => 'date', |
| 6934 | 'order' => 'DESC', |
| 6935 | ] |
| 6936 | ); |
| 6937 | |
| 6938 | $subscription_products_count = count( (array) $subscription_products ); |
| 6939 | |
| 6940 | $options = []; |
| 6941 | if ( $subscription_products ) { |
| 6942 | foreach ( (array) $subscription_products as $product ) { |
| 6943 | $options[] = [ |
| 6944 | 'label' => $product->get_title(), |
| 6945 | 'value' => $product->get_id(), |
| 6946 | ]; |
| 6947 | } |
| 6948 | } |
| 6949 | |
| 6950 | return [ |
| 6951 | 'options' => $options, |
| 6952 | 'hasMore' => $subscription_products_count > $limit && $subscription_products_count > $offset, |
| 6953 | ]; |
| 6954 | } |
| 6955 | |
| 6956 | /** |
| 6957 | * Get Woocommerce Variation list. |
| 6958 | * |
| 6959 | * @param array $data data. |
| 6960 | * |
| 6961 | * @return array|void |
| 6962 | */ |
| 6963 | public function search_wc_variation_list( $data ) { |
| 6964 | global $wpdb; |
| 6965 | |
| 6966 | $page = $data['page']; |
| 6967 | $limit = Utilities::get_search_page_limit(); |
| 6968 | $offset = $limit * ( $page - 1 ); |
| 6969 | |
| 6970 | $args = [ |
| 6971 | 'post_type' => 'product_variation', |
| 6972 | 'post_parent' => $data['dynamic']['variable_subscription'], |
| 6973 | 'posts_per_page' => $limit, |
| 6974 | 'offset' => $offset, |
| 6975 | 'orderby' => 'ID', |
| 6976 | 'order' => 'ASC', |
| 6977 | 'post_status' => 'publish', |
| 6978 | ]; |
| 6979 | |
| 6980 | $variation = get_posts( $args ); |
| 6981 | $variation_count = count( $variation ); |
| 6982 | |
| 6983 | $options = []; |
| 6984 | if ( $variation ) { |
| 6985 | foreach ( $variation as $product ) { |
| 6986 | $options[] = [ |
| 6987 | 'label' => ! empty( $product->post_excerpt ) ? $product->post_excerpt : $product->post_title, |
| 6988 | 'value' => $product->ID, |
| 6989 | ]; |
| 6990 | } |
| 6991 | } |
| 6992 | |
| 6993 | return [ |
| 6994 | 'options' => $options, |
| 6995 | 'hasMore' => $variation_count > $limit && $variation_count > $offset, |
| 6996 | ]; |
| 6997 | } |
| 6998 | |
| 6999 | /** |
| 7000 | * Get Membership List. |
| 7001 | * |
| 7002 | * @param array $data data. |
| 7003 | * |
| 7004 | * @return array |
| 7005 | */ |
| 7006 | public function search_membership_list( $data ) { |
| 7007 | global $wpdb; |
| 7008 | |
| 7009 | $levels = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}pmpro_membership_levels ORDER BY id ASC" ); |
| 7010 | $options = []; |
| 7011 | if ( $levels ) { |
| 7012 | foreach ( $levels as $level ) { |
| 7013 | $options[] = [ |
| 7014 | 'label' => $level->name, |
| 7015 | 'value' => $level->id, |
| 7016 | ]; |
| 7017 | } |
| 7018 | } |
| 7019 | |
| 7020 | return [ |
| 7021 | 'options' => $options, |
| 7022 | 'hasMore' => false, |
| 7023 | ]; |
| 7024 | } |
| 7025 | |
| 7026 | /** |
| 7027 | |
| 7028 | * Get EventsManager last data. |
| 7029 | * |
| 7030 | * @param array $data data. |
| 7031 | * |
| 7032 | * @return array |
| 7033 | */ |
| 7034 | public function search_events_manager_data( $data ) { |
| 7035 | global $wpdb; |
| 7036 | $trigger = $data['search_term']; |
| 7037 | $context = []; |
| 7038 | |
| 7039 | $post_id = (int) ( isset( $data['filter']['post_id']['value'] ) ? $data['filter']['post_id']['value'] : '-1' ); |
| 7040 | if ( 'em_user_register_in_event' === $trigger ) { |
| 7041 | if ( $post_id > 0 ) { |
| 7042 | $event_id_id = get_post_meta( $post_id, '_event_id', true ); |
| 7043 | $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 ) ); |
| 7044 | } else { |
| 7045 | $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" ); |
| 7046 | |
| 7047 | } |
| 7048 | |
| 7049 | if ( ! empty( $all_bookings ) ) { |
| 7050 | $user_id = $all_bookings->person_id; |
| 7051 | $location = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_locations as b WHERE b.location_id = %s", $all_bookings->location_id ) ); |
| 7052 | $context['pluggable_data'] = array_merge( |
| 7053 | WordPress::get_user_context( $user_id ), |
| 7054 | json_decode( wp_json_encode( $all_bookings ), true ) |
| 7055 | ); |
| 7056 | if ( ! empty( $location ) ) { |
| 7057 | $context['pluggable_data'] = array_merge( $context['pluggable_data'], json_decode( wp_json_encode( $location ), true ) ); |
| 7058 | } |
| 7059 | |
| 7060 | $context['response_type'] = 'live'; |
| 7061 | } |
| 7062 | } elseif ( 'em_user_unregister_from_event' === $trigger ) { |
| 7063 | |
| 7064 | if ( $post_id > 0 ) { |
| 7065 | $event_id_id = get_post_meta( $post_id, '_event_id', true ); |
| 7066 | $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 ) ); |
| 7067 | } else { |
| 7068 | $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" ); |
| 7069 | |
| 7070 | } |
| 7071 | |
| 7072 | if ( ! empty( $all_bookings ) ) { |
| 7073 | $user_id = $all_bookings->person_id; |
| 7074 | $context['pluggable_data'] = array_merge( |
| 7075 | WordPress::get_user_context( $user_id ), |
| 7076 | json_decode( wp_json_encode( $all_bookings ), true ) |
| 7077 | ); |
| 7078 | $context['response_type'] = 'live'; |
| 7079 | } |
| 7080 | } elseif ( 'em_user_booking_approved' === $trigger ) { |
| 7081 | |
| 7082 | if ( $post_id > 0 ) { |
| 7083 | $event_id_id = get_post_meta( $post_id, '_event_id', true ); |
| 7084 | $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 ) ); |
| 7085 | } else { |
| 7086 | $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" ); |
| 7087 | |
| 7088 | } |
| 7089 | |
| 7090 | if ( ! empty( $all_bookings ) ) { |
| 7091 | $user_id = $all_bookings->person_id; |
| 7092 | $location = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_locations as b WHERE b.location_id = %s", $all_bookings->location_id ) ); |
| 7093 | $context['pluggable_data'] = array_merge( |
| 7094 | WordPress::get_user_context( $user_id ), |
| 7095 | json_decode( wp_json_encode( $all_bookings ), true ) |
| 7096 | ); |
| 7097 | if ( ! empty( $location ) ) { |
| 7098 | $context['pluggable_data'] = array_merge( $context['pluggable_data'], json_decode( wp_json_encode( $location ), true ) ); |
| 7099 | } |
| 7100 | |
| 7101 | $context['response_type'] = 'live'; |
| 7102 | |
| 7103 | } |
| 7104 | } |
| 7105 | return $context; |
| 7106 | } |
| 7107 | |
| 7108 | /** |
| 7109 | |
| 7110 | * Get learnpress last data. |
| 7111 | * |
| 7112 | * @param array $data data. |
| 7113 | * |
| 7114 | * @return array |
| 7115 | */ |
| 7116 | public function search_learnpress_lms_last_data( $data ) { |
| 7117 | global $wpdb; |
| 7118 | $trigger = $data['search_term']; |
| 7119 | $course_data = []; |
| 7120 | $lesson_data = []; |
| 7121 | $context = []; |
| 7122 | |
| 7123 | |
| 7124 | if ( 'learnpress_course_completed' === $trigger ) { |
| 7125 | $course_id = (int) ( isset( $data['filter']['course']['value'] ) ? $data['filter']['course']['value'] : '-1' ); |
| 7126 | if ( $course_id > 0 ) { |
| 7127 | |
| 7128 | $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 ) ); |
| 7129 | } else { |
| 7130 | |
| 7131 | $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" ); |
| 7132 | } |
| 7133 | |
| 7134 | if ( ! empty( $course ) ) { |
| 7135 | $course_data = array_merge( WordPress::get_user_context( $course->user_id ), LearnPress::get_lpc_course_context( $course->item_id ) ); |
| 7136 | $context['response_type'] = 'live'; |
| 7137 | $context['pluggable_data'] = $course_data; |
| 7138 | } |
| 7139 | } elseif ( 'learnpress_lesson_completed' === $trigger ) { |
| 7140 | $lesson_id = (int) ( isset( $data['filter']['lesson']['value'] ) ? $data['filter']['lesson']['value'] : '-1' ); |
| 7141 | if ( $lesson_id > 0 ) { |
| 7142 | |
| 7143 | $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 ) ); |
| 7144 | } else { |
| 7145 | |
| 7146 | $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" ); |
| 7147 | } |
| 7148 | |
| 7149 | if ( ! empty( $lesson ) ) { |
| 7150 | $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 ) ); |
| 7151 | $context['response_type'] = 'live'; |
| 7152 | $context['pluggable_data'] = $lesson_data; |
| 7153 | } |
| 7154 | } elseif ( 'learnpress_user_enrolled_in_course' === $trigger ) { |
| 7155 | $course_id = (int) ( isset( $data['filter']['course']['value'] ) ? $data['filter']['course']['value'] : '-1' ); |
| 7156 | if ( $course_id > 0 ) { |
| 7157 | |
| 7158 | $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 ) ); |
| 7159 | } else { |
| 7160 | |
| 7161 | $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" ); |
| 7162 | } |
| 7163 | |
| 7164 | if ( ! empty( $course ) ) { |
| 7165 | $course_data = array_merge( WordPress::get_user_context( $course->user_id ), LearnPress::get_lpc_course_context( $course->item_id ) ); |
| 7166 | $context['response_type'] = 'live'; |
| 7167 | $context['pluggable_data'] = $course_data; |
| 7168 | |
| 7169 | } |
| 7170 | } |
| 7171 | |
| 7172 | return $context; |
| 7173 | } |
| 7174 | |
| 7175 | /** |
| 7176 | * Get Woocommerce Memberships Plan List. |
| 7177 | * |
| 7178 | * @param array $data data. |
| 7179 | * |
| 7180 | * @return array|void |
| 7181 | */ |
| 7182 | public function search_wc_membership_plan_list( $data ) { |
| 7183 | global $wpdb; |
| 7184 | |
| 7185 | $page = $data['page']; |
| 7186 | $limit = Utilities::get_search_page_limit(); |
| 7187 | $offset = $limit * ( $page - 1 ); |
| 7188 | |
| 7189 | $args = [ |
| 7190 | 'post_type' => 'wc_membership_plan', |
| 7191 | 'posts_per_page' => $limit, |
| 7192 | 'offset' => $offset, |
| 7193 | 'orderby' => 'title', |
| 7194 | 'order' => 'ASC', |
| 7195 | 'post_status' => 'publish', |
| 7196 | 'fields' => 'ids', |
| 7197 | ]; |
| 7198 | $loop = new WP_Query( $args ); |
| 7199 | |
| 7200 | $plans = (array) $loop->posts; |
| 7201 | $plans_count = count( $plans ); |
| 7202 | |
| 7203 | $options = []; |
| 7204 | if ( ! empty( $plans ) ) { |
| 7205 | if ( is_array( $plans ) ) { |
| 7206 | foreach ( $plans as $plan_id ) { |
| 7207 | $options[] = [ |
| 7208 | 'label' => get_the_title( $plan_id ), |
| 7209 | 'value' => $plan_id, |
| 7210 | ]; |
| 7211 | } |
| 7212 | } |
| 7213 | } |
| 7214 | |
| 7215 | return [ |
| 7216 | 'options' => $options, |
| 7217 | 'hasMore' => $plans_count > $limit && $plans_count > $offset, |
| 7218 | ]; |
| 7219 | } |
| 7220 | |
| 7221 | /** |
| 7222 | * Get BuddyPress Private group. |
| 7223 | * |
| 7224 | * @param array $data data. |
| 7225 | * |
| 7226 | * @return array|void |
| 7227 | */ |
| 7228 | public function search_bp_private_group_list( $data ) { |
| 7229 | global $wpdb; |
| 7230 | |
| 7231 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups WHERE status = 'private'" ); |
| 7232 | |
| 7233 | $options = []; |
| 7234 | if ( $groups ) { |
| 7235 | foreach ( $groups as $group ) { |
| 7236 | $options[] = [ |
| 7237 | 'label' => $group->name, |
| 7238 | 'value' => $group->id, |
| 7239 | ]; |
| 7240 | } |
| 7241 | } |
| 7242 | |
| 7243 | return [ |
| 7244 | 'options' => $options, |
| 7245 | 'hasMore' => false, |
| 7246 | ]; |
| 7247 | } |
| 7248 | |
| 7249 | /** |
| 7250 | * Get BuddyPress Public group. |
| 7251 | * |
| 7252 | * @param array $data data. |
| 7253 | * |
| 7254 | * @return array|void |
| 7255 | */ |
| 7256 | public function search_bp_public_group_list( $data ) { |
| 7257 | global $wpdb; |
| 7258 | |
| 7259 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups WHERE status = 'public'" ); |
| 7260 | |
| 7261 | $options = []; |
| 7262 | if ( $groups ) { |
| 7263 | foreach ( $groups as $group ) { |
| 7264 | $options[] = [ |
| 7265 | 'label' => $group->name, |
| 7266 | 'value' => $group->id, |
| 7267 | ]; |
| 7268 | } |
| 7269 | } |
| 7270 | |
| 7271 | return [ |
| 7272 | 'options' => $options, |
| 7273 | 'hasMore' => false, |
| 7274 | ]; |
| 7275 | } |
| 7276 | |
| 7277 | /** |
| 7278 | * Get BuddyPress group. |
| 7279 | * |
| 7280 | * @param array $data data. |
| 7281 | * |
| 7282 | * @return array|void |
| 7283 | */ |
| 7284 | public function search_bp_group_list( $data ) { |
| 7285 | global $wpdb; |
| 7286 | |
| 7287 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups" ); |
| 7288 | |
| 7289 | $options = []; |
| 7290 | if ( $groups ) { |
| 7291 | foreach ( $groups as $group ) { |
| 7292 | $options[] = [ |
| 7293 | 'label' => $group->name, |
| 7294 | 'value' => $group->id, |
| 7295 | ]; |
| 7296 | } |
| 7297 | } |
| 7298 | |
| 7299 | return [ |
| 7300 | 'options' => $options, |
| 7301 | 'hasMore' => false, |
| 7302 | ]; |
| 7303 | } |
| 7304 | |
| 7305 | /** |
| 7306 | * Get BuddyPress field. |
| 7307 | * |
| 7308 | * @param array $data data. |
| 7309 | * |
| 7310 | * @return array|void |
| 7311 | */ |
| 7312 | public function search_bp_field_list( $data ) { |
| 7313 | global $wpdb; |
| 7314 | |
| 7315 | $base_group_id = 1; |
| 7316 | if ( function_exists( 'bp_xprofile_base_group_id' ) ) { |
| 7317 | $base_group_id = bp_xprofile_base_group_id(); |
| 7318 | } |
| 7319 | |
| 7320 | $xprofile_fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}bp_xprofile_fields parent_id = 0 AND group_id = %d ORDER BY field_order ASC", $base_group_id ) ); |
| 7321 | |
| 7322 | $options = []; |
| 7323 | if ( ! empty( $xprofile_fields ) ) { |
| 7324 | foreach ( $xprofile_fields as $xprofile_field ) { |
| 7325 | $options[] = [ |
| 7326 | 'label' => $xprofile_field->name, |
| 7327 | 'value' => $xprofile_field->id, |
| 7328 | ]; |
| 7329 | } |
| 7330 | } |
| 7331 | |
| 7332 | return [ |
| 7333 | 'options' => $options, |
| 7334 | 'hasMore' => false, |
| 7335 | ]; |
| 7336 | } |
| 7337 | |
| 7338 | /** |
| 7339 | * Get BuddyPress member type. |
| 7340 | * |
| 7341 | * @param array $data data. |
| 7342 | * |
| 7343 | * @return array|void |
| 7344 | */ |
| 7345 | public function search_bp_member_type_list( $data ) { |
| 7346 | $options = []; |
| 7347 | if ( function_exists( 'bp_get_member_types' ) ) { |
| 7348 | $types = bp_get_member_types( [] ); |
| 7349 | if ( $types ) { |
| 7350 | foreach ( $types as $key => $type ) { |
| 7351 | $options[] = [ |
| 7352 | 'label' => $type, |
| 7353 | 'value' => $key, |
| 7354 | ]; |
| 7355 | } |
| 7356 | } |
| 7357 | } |
| 7358 | |
| 7359 | return [ |
| 7360 | 'options' => $options, |
| 7361 | 'hasMore' => false, |
| 7362 | ]; |
| 7363 | } |
| 7364 | |
| 7365 | |
| 7366 | } |
| 7367 | |
| 7368 | GlobalSearchController::get_instance(); |
| 7369 |