PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 8.0.5
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v8.0.5
8.0.5 8.0.4 8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 All 47 releases
← All changes | integrations/buddyboss/includes/community/includes/functions.php +225 -0 7.8.9 → 8.0.5 View file →
@@ -1,0 +1,225 @@
1 +<?php
2 +/**
3 + * Functions
4 + *
5 + * @package GamiPress\BuddyPress\Functions
6 + * @since 1.0.0
7 + */
8 +
9 +// Exit if accessed directly
10 +if( !defined( 'ABSPATH' ) ) exit;
11 +
12 +/**
13 + * Compatibility function to check if a BuddyPress module is active
14 + *
15 + * @since 1.2.0
16 + *
17 + * @param string $component The component name.
18 + *
19 + * @return bool
20 + */
21 +function gamipress_bp_is_active( $component = '' ) {
22 +
23 + if( function_exists( 'bp_is_active' ) ) {
24 + return bp_is_active( $component );
25 + }
26 +
27 + return true;
28 +
29 +}
30 +
31 +/**
32 + * Overrides GamiPress AJAX Helper for selecting posts
33 + *
34 + * @since 1.0.0
35 + */
36 +function gamipress_bp_ajax_get_posts() {
37 +
38 + // Security check, forces to die if not security passed
39 + check_ajax_referer( 'gamipress_admin', 'nonce' );
40 +
41 + // Check if user can manage GamiPress
42 + if( ! current_user_can( gamipress_get_manager_capability() ) ) {
43 + wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'gamipress' ) );
44 + }
45 +
46 + global $wpdb;
47 +
48 + if( isset( $_REQUEST['post_type'] ) && in_array( 'bp_groups', $_REQUEST['post_type'] ) ) {
49 +
50 + $results = array();
51 +
52 + // Pull back the search string
53 + $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( $_REQUEST['q'] ) : false;
54 +
55 + $bp_groups = groups_get_groups( array(
56 + 'search_terms' => $search,
57 + 'show_hidden' => true,
58 + 'per_page' => 300
59 + ) );
60 +
61 + if ( ! empty( $bp_groups ) ) {
62 + foreach ( $bp_groups['groups'] as $group ) {
63 + // Results should meet same structure like posts
64 + $results[] = array(
65 + 'ID' => $group->id,
66 + 'post_title' => $group->name,
67 + );
68 + }
69 + }
70 +
71 + // Return our results
72 + wp_send_json_success( $results );
73 + die;
74 + } elseif ( isset( $_REQUEST['post_type'] ) && in_array( 'bp_fields', $_REQUEST['post_type'] ) ) {
75 + $results = array();
76 +
77 + // Pull back the search string
78 + $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( $_REQUEST['q'] ) : '';
79 + $page = isset( $_REQUEST['page'] ) ? absint( $_REQUEST['page'] ) : 1;
80 + $limit = 20;
81 + $offset = $limit * ( $page - 1 );
82 + $prefix = gamipress_bp_get_table_prefix();
83 +
84 + if( ! empty( $search ) ) {
85 + $profile_fields = $wpdb->get_results( $wpdb->prepare(
86 + "SELECT *
87 + FROM {$prefix}bp_xprofile_fields
88 + WHERE name LIKE %s
89 + ORDER BY field_order ASC
90 + LIMIT {$offset}, {$limit}",
91 + "%%{$search}%%"
92 + ) );
93 +
94 + $count = absint( $wpdb->get_var( $wpdb->prepare(
95 + "SELECT COUNT(*) FROM {$prefix}bp_xprofile_fields WHERE name LIKE %s",
96 + "%%{$search}%%"
97 + ) ) );
98 +
99 + } else {
100 + $profile_fields = $wpdb->get_results( $wpdb->prepare(
101 + "SELECT *
102 + FROM {$prefix}bp_xprofile_fields
103 + ORDER BY field_order ASC
104 + LIMIT {$offset}, {$limit}"
105 + ) );
106 +
107 + $count = absint( $wpdb->get_var( $wpdb->prepare(
108 + "SELECT COUNT(*) FROM {$prefix}bp_xprofile_fields"
109 + ) ) );
110 + }
111 +
112 + if ( ! empty( $profile_fields ) ) {
113 + foreach ( $profile_fields as $profile_field ) {
114 +
115 + // Results should meet Select2 structure
116 + $results[] = array(
117 + 'ID' => $profile_field->id,
118 + 'post_title' => $profile_field->name,
119 + );
120 +
121 + }
122 +
123 + }
124 +
125 + $response = array(
126 + 'results' => $results,
127 + 'more_results' => $count > $limit && $count > $offset,
128 + );
129 +
130 + // Return our results
131 + wp_send_json_success( $response );
132 + die;
133 + } else if( isset( $_REQUEST['post_type'] ) && in_array( 'bp_reactions', $_REQUEST['post_type'] ) ) {
134 +
135 + $results = array();
136 +
137 + // Pull back the search string
138 + $search = isset( $_REQUEST['q'] ) ? sanitize_text_field( $_REQUEST['q'] ) : '';
139 + $search = $wpdb->esc_like( $search );
140 +
141 + // Get the reactions
142 + $reactions = bb_load_reaction()->bb_get_reactions( 'emotions' );
143 +
144 + foreach ( $reactions as $reaction ) {
145 +
146 + // Results should meet Select2 structure
147 + $results[] = array(
148 + 'ID' => $reaction['id'],
149 + 'post_title' => $reaction['icon_text'],
150 + );
151 +
152 + }
153 +
154 + // Return our results
155 + wp_send_json_success( $results );
156 + die;
157 + }
158 +
159 +}
160 +add_action( 'wp_ajax_gamipress_get_posts', 'gamipress_bp_ajax_get_posts', 5 );
161 +
162 +/**
163 + * Helper function to get the table prefix
164 + *
165 + * @since 1.0.0
166 + *
167 + * @return string
168 + */
169 +function gamipress_bp_get_table_prefix() {
170 +
171 + global $wpdb;
172 +
173 + if( function_exists( 'bp_core_get_table_prefix' ) ) {
174 + return bp_core_get_table_prefix();
175 + }
176 +
177 + return $wpdb->prefix;
178 +
179 +}
180 +
181 +function gamipress_bp_get_profile_field_name( $field_id ) {
182 +
183 + global $wpdb;
184 + $prefix = gamipress_bp_get_table_prefix();
185 +
186 + $name_field = $wpdb->get_var( $wpdb->prepare(
187 + "SELECT name
188 + FROM {$prefix}bp_xprofile_fields
189 + WHERE id = %d",
190 + $field_id
191 + ) );
192 +
193 + return $name_field;
194 +}
195 +
196 +/**
197 + * Get the reaction title
198 + *
199 + * @since 1.0.0
200 + *
201 + * @param int $reaction_id
202 + *
203 + * @return string|null
204 + */
205 +function gamipress_buddyboss_get_reaction_title( $reaction_id ) {
206 +
207 + // Empty title if no ID provided
208 + if( absint( $reaction_id ) === 0 ) {
209 + return '';
210 + }
211 +
212 + $reactions = array();
213 +
214 + // Get the reactions
215 + $reactions = bb_load_reaction()->bb_get_reactions( 'emotions' );
216 +
217 + foreach ( $reactions as $reaction ) {
218 + if ( absint( $reaction['id'] ) === absint( $reaction_id ) ) {
219 + return $reaction['icon_text'];
220 + }
221 + }
222 +
223 + return $reactions;
224 +
225 +}