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 / fluentcommunity / includes / ajax-functions.php

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

98 lines 2.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\FluentCommunity\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 spaces
13 *
14 * @since 1.0.0
15 */
16 function automatorwp_fluentcommunity_ajax_get_spaces() {
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 = array();
31
32 // Get the spaces
33 $spaces = automatorwp_fluentcommunity_get_spaces();
34
35 foreach( $spaces as $space ) {
36 $results[] = array(
37 'id' => $space['id'],
38 'text' => $space['title'],
39 );
40 }
41
42 // Prepend option none
43 $results = automatorwp_ajax_get_ajax_results_option_none( $results );
44
45 // Return our results
46 wp_send_json_success( $results );
47 die;
48
49 }
50 add_action( 'wp_ajax_automatorwp_fluentcommunity_get_spaces', 'automatorwp_fluentcommunity_ajax_get_spaces', 5 );
51
52 /**
53 * Ajax function for selecting courses
54 *
55 * @since 1.0.0
56 */
57 function automatorwp_fluentcommunity_ajax_get_courses() {
58 // Security check
59 check_ajax_referer( 'automatorwp_admin', 'nonce' );
60
61 // Permissions check
62 if( ! current_user_can( automatorwp_get_manager_capability() ) ) {
63 wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'automatorwp' ) );
64 }
65
66 global $wpdb;
67
68 // Pull back the search string
69 $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( $_REQUEST['q'] ) : '';
70
71 $results = array();
72
73 // Get the courses
74 $courses = automatorwp_fluentcommunity_get_courses();
75
76 foreach( $courses as $course ) {
77
78 if( ! empty( $search ) ) {
79 if( strpos( strtolower( $course['title'] ), strtolower( $search ) ) === false ) {
80 continue;
81 }
82 }
83
84 $results[] = array(
85 'id' => $course['id'],
86 'text' => $course['title'],
87 );
88 }
89
90 // Prepend option none
91 $results = automatorwp_ajax_get_ajax_results_option_none( $results );
92
93 // Return our results
94 wp_send_json_success( $results );
95 die;
96
97 }
98 add_action( 'wp_ajax_automatorwp_fluentcommunity_get_courses', 'automatorwp_fluentcommunity_ajax_get_courses', 5 );