PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
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 / mailerpress / includes / ajax-functions.php

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

58 lines 1.6 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\MailerPress\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 MailerPress tags as a JSON list for Select2 fields
15 *
16 * @since 1.0.0
17 */
18 function automatorwp_mailerpress_ajax_get_tags() {
19 // Security check, forces to die if not security passed
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 global $wpdb;
27
28 // Pull back the search string
29 $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( sanitize_text_field( $_REQUEST['q'] ) ) : '';
30
31 $tags = automatorwp_mailerpress_get_tags();
32
33 $results = array();
34
35 // Parse tags results to match select2 results
36 foreach ( $tags as $tag ) {
37
38 if( ! empty( $search ) ) {
39 if( strpos( strtolower( $tag['name'] ), strtolower( $search ) ) === false ) {
40 continue;
41 }
42 }
43
44 $results[] = array(
45 'id' => $tag['id'],
46 'text' => $tag['name']
47 );
48 }
49
50 // Prepend option none
51 $results = automatorwp_ajax_parse_extra_options( $results );
52
53 // Return our results
54 wp_send_json_success( $results );
55 die;
56 }
57 add_action( 'wp_ajax_automatorwp_mailerpress_get_tags', 'automatorwp_mailerpress_ajax_get_tags' );
58