PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.2
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.2
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 5.6.2 All 33 releases
automatorwp / integrations / mail-mint / includes / ajax-functions.php

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

59 lines 1.5 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\Mail_Mint\Ajax_Functions
6 * @author AutomatorWP <[email protected]>
7 * @since 1.0.0
8 */
9
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) ) exit;
12
13 /**
14 * Return Mail Mint tags as a JSON list for Select2 fields
15 *
16 * @since 1.0.0
17 */
18 function automatorwp_mail_mint_ajax_get_tags() {
19 // Security check
20 check_ajax_referer( 'automatorwp_admin', 'nonce' );
21
22 // Permissions check
23 if( ! current_user_can( automatorwp_get_manager_capability() ) ) {
24 wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'automatorwp' ) );
25 }
26
27 global $wpdb;
28
29 // Pull back the search string
30 $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( sanitize_text_field( $_REQUEST['q'] ) ) : '';
31
32 $tags = automatorwp_mail_mint_get_tags();
33
34 $results = array();
35
36 // Parse tags results to match select2 results
37 foreach ( $tags as $tag ) {
38
39 if( ! empty( $search ) ) {
40 if( strpos( strtolower( $tag['name'] ), strtolower( $search ) ) === false ) {
41 continue;
42 }
43 }
44
45 $results[] = array(
46 'id' => $tag['id'],
47 'text' => $tag['name']
48 );
49 }
50
51 // Prepend option none
52 $results = automatorwp_ajax_parse_extra_options( $results );
53
54 // Return our results
55 wp_send_json_success( $results );
56 die;
57 }
58 add_action( 'wp_ajax_automatorwp_mail_mint_get_tags', 'automatorwp_mail_mint_ajax_get_tags' );
59