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

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

70 lines 1.8 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\BuddyPress\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 groups
13 *
14 * @since 1.0.0
15 */
16 function automatorwp_buddypress_ajax_get_groups() {
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 $results = array();
28
29 // Pull back the search string
30 $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( $_REQUEST['q'] ) : '';
31 $page = isset( $_REQUEST['page'] ) ? absint( $_REQUEST['page'] ) : 1;
32
33 if( bp_is_active( 'groups' ) ) {
34
35 // Get the groups
36 $groups = groups_get_groups( array(
37 'search_terms' => $search,
38 'show_hidden' => true,
39 'per_page' => 20,
40 'page' => $page
41 ) );
42
43 if( isset( $groups['groups'] ) && ! empty( $groups['groups'] ) ) {
44 foreach ( $groups['groups'] as $group ) {
45
46 // Results should meet Select2 structure
47 $results[] = array(
48 'id' => $group->id,
49 'text' => $group->name,
50 );
51
52 }
53 }
54
55 }
56
57 // Prepend option none
58 $results = automatorwp_ajax_get_ajax_results_option_none( $results );
59
60 $response = array(
61 'results' => $results,
62 'more_results' => count( $results ),
63 );
64
65 // Return our results
66 wp_send_json_success( $response );
67 die;
68
69 }
70 add_action( 'wp_ajax_automatorwp_buddypress_get_groups', 'automatorwp_buddypress_ajax_get_groups' );