PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 5.8.5
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v5.8.5
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
automatorwp / integrations / jetpack-crm / includes / ajax-functions.php

ajax-functions.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 5.8.5, at integrations/jetpack-crm/includes/ajax-functions.php

108 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Ajax Functions
4 *
5 * @package AutomatorWP\Integrations\Jetpack_CRM\Includes\Ajax_Functions
6 * @since 1.0.0
7 */
8 // Exit if accessed directly
9 if( !defined( 'ABSPATH' ) ) exit;
10
11 /**
12 * Ajax function for selecting contact tags
13 *
14 * @since 1.0.0
15 */
16
17 function automatorwp_jetpack_crm_ajax_get_contact_tags() {
18 // Security check
19 check_ajax_referer( 'automatorwp_admin', 'nonce' );
20
21 // Permissions check
22 if( ! current_user_can( automatorwp_get_manager_capability() ) ) {
23 wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'automatorwp' ) );
24 }
25
26 // Predefined jetpack crm type
27 $type_id = ZBS_TYPE_CONTACT;
28
29 // Pull back the search string
30 $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( sanitize_text_field( $_REQUEST['q'] ) ) : '';
31
32 $tags = automatorwp_jetpack_crm_get_tags( $type_id );
33
34 // Parse tag results to match select2 results
35 foreach ( $tags as $tag ) {
36
37 if( ! empty( $search ) ) {
38 if( strpos( strtolower( $tag['name'] ), strtolower( $search ) ) === false ) {
39 continue;
40 }
41 }
42
43 $results[] = array(
44 'id' => $tag['id'],
45 'text' => $tag['name']
46 );
47 }
48
49 // Prepend option none
50 $results = automatorwp_ajax_parse_extra_options( $results );
51
52 // Return our results
53 wp_send_json_success( $results );
54 die;
55
56 }
57 add_action( 'wp_ajax_automatorwp_jetpack_crm_get_contact_tags', 'automatorwp_jetpack_crm_ajax_get_contact_tags' );
58
59 /**
60 * Ajax function for selecting company tags
61 *
62 * @since 1.0.0
63 */
64
65 function automatorwp_jetpack_crm_ajax_get_company_tags() {
66 // Security check
67 check_ajax_referer( 'automatorwp_admin', 'nonce' );
68
69 // Permissions check
70 if( ! current_user_can( automatorwp_get_manager_capability() ) ) {
71 wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'automatorwp' ) );
72 }
73
74 // Predefined jetpack crm type
75 $type_id = ZBS_TYPE_COMPANY;
76
77 // Pull back the search string
78 $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( sanitize_text_field( $_REQUEST['q'] ) ) : '';
79
80 $tags = automatorwp_jetpack_crm_get_tags( $type_id );
81
82 // Parse tag results to match select2 results
83 foreach ( $tags as $tag ) {
84
85 if( ! empty( $search ) ) {
86 if( strpos( strtolower( $tag['name'] ), strtolower( $search ) ) === false ) {
87 continue;
88 }
89 }
90
91 $results[] = array(
92 'id' => $tag['id'],
93 'text' => $tag['name']
94 );
95 }
96
97 // Prepend option none
98 $results = automatorwp_ajax_parse_extra_options( $results );
99
100 // Return our results
101 wp_send_json_success( $results );
102 die;
103
104 }
105 add_action( 'wp_ajax_automatorwp_jetpack_crm_get_company_tags', 'automatorwp_jetpack_crm_ajax_get_company_tags' );
106
107
108