| @@ -1,0 +1,81 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Ajax Functions | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\FluentCRM\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 contents | |
| 13 | + * | |
| 14 | + * @since 1.0.0 | |
| 15 | + */ | |
| 16 | +function automatorwp_fluentcrm_ajax_get_tags() { | |
| 17 | + // Security check | |
| 18 | + check_ajax_referer( 'automatorwp_admin', 'nonce' ); | |
| 19 | + | |
| 20 | + // Permissions check | |
| 21 | + if( ! current_user_can( automatorwp_get_manager_capability() ) ) { | |
| 22 | + wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'automatorwp' ) ); | |
| 23 | + } | |
| 24 | + | |
| 25 | + global $wpdb; | |
| 26 | + | |
| 27 | + // Pull back the search string | |
| 28 | + $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( $_REQUEST['q'] ) : ''; | |
| 29 | + | |
| 30 | + $results = $wpdb->get_results( $wpdb->prepare( | |
| 31 | + "SELECT t.id AS id, t.title AS text | |
| 32 | + FROM {$wpdb->prefix}fc_tags AS t | |
| 33 | + WHERE t.title LIKE %s", | |
| 34 | + "%%{$search}%%" | |
| 35 | + ) ); | |
| 36 | + | |
| 37 | + // Prepend option none | |
| 38 | + $results = automatorwp_ajax_get_ajax_results_option_none( $results ); | |
| 39 | + | |
| 40 | + // Return our results | |
| 41 | + wp_send_json_success( $results ); | |
| 42 | + die; | |
| 43 | + | |
| 44 | +} | |
| 45 | +add_action( 'wp_ajax_automatorwp_fluentcrm_get_tags', 'automatorwp_fluentcrm_ajax_get_tags' ); | |
| 46 | + | |
| 47 | +/** | |
| 48 | + * Ajax function for selecting contents | |
| 49 | + * | |
| 50 | + * @since 1.0.0 | |
| 51 | + */ | |
| 52 | +function automatorwp_fluentcrm_ajax_get_lists() { | |
| 53 | + // Security check | |
| 54 | + check_ajax_referer( 'automatorwp_admin', 'nonce' ); | |
| 55 | + | |
| 56 | + // Permissions check | |
| 57 | + if( ! current_user_can( automatorwp_get_manager_capability() ) ) { | |
| 58 | + wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'automatorwp' ) ); | |
| 59 | + } | |
| 60 | + | |
| 61 | + global $wpdb; | |
| 62 | + | |
| 63 | + // Pull back the search string | |
| 64 | + $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( $_REQUEST['q'] ) : ''; | |
| 65 | + | |
| 66 | + $results = $wpdb->get_results( $wpdb->prepare( | |
| 67 | + "SELECT t.id AS id, t.title AS text | |
| 68 | + FROM {$wpdb->prefix}fc_lists AS t | |
| 69 | + WHERE t.title LIKE %s", | |
| 70 | + "%%{$search}%%" | |
| 71 | + ) ); | |
| 72 | + | |
| 73 | + // Prepend option none | |
| 74 | + $results = automatorwp_ajax_get_ajax_results_option_none( $results ); | |
| 75 | + | |
| 76 | + // Return our results | |
| 77 | + wp_send_json_success( $results ); | |
| 78 | + die; | |
| 79 | + | |
| 80 | +} | |
| 81 | +add_action( 'wp_ajax_automatorwp_fluentcrm_get_lists', 'automatorwp_fluentcrm_ajax_get_lists' ); | |