PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 8.0.6
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v8.0.6
8.0.6 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 All 48 releases
← All changes | integrations/paid-memberships-pro/includes/functions.php +75 -0 7.9.3 → 8.0.6 View file →
@@ -1,0 +1,75 @@
1 +<?php
2 +/**
3 + * Functions
4 + *
5 + * @package GamiPress\Paid_Memberships_Pro\Functions
6 + * @since 1.0.0
7 + */
8 +
9 +// Exit if accessed directly
10 +if( !defined( 'ABSPATH' ) ) exit;
11 +
12 +/**
13 + * Overrides GamiPress AJAX Helper for selecting posts
14 + *
15 + * @since 1.0.0
16 + */
17 +function gamipress_paid_memberships_pro_ajax_get_posts() {
18 +
19 + // Security check, forces to die if not security passed
20 + check_ajax_referer( 'gamipress_admin', 'nonce' );
21 +
22 + // Check if user can manage GamiPress
23 + if( ! current_user_can( gamipress_get_manager_capability() ) ) {
24 + wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'gamipress' ) );
25 + }
26 +
27 + global $wpdb;
28 +
29 + if( isset( $_REQUEST['post_type'] ) && in_array( 'pmpro_membership', $_REQUEST['post_type'] ) ) {
30 +
31 + $results = array();
32 +
33 + // Pull back the search string
34 + $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( sanitize_text_field( $_REQUEST['q'] ) ) : '';
35 +
36 + // Get the memberships
37 + $memberships = $wpdb->get_results( $wpdb->prepare(
38 + "SELECT m.id, m.name
39 + FROM {$wpdb->pmpro_membership_levels} AS m
40 + WHERE m.name LIKE %s",
41 + "%%{$search}%%"
42 + ) );
43 +
44 + foreach ( $memberships as $membership ) {
45 +
46 + // Results should meet same structure like posts
47 + $results[] = array(
48 + 'ID' => $membership->id,
49 + 'post_title' => $membership->name,
50 + );
51 +
52 + }
53 +
54 + // Return our results
55 + wp_send_json_success( $results );
56 + die;
57 +
58 + }
59 +
60 +}
61 +add_action( 'wp_ajax_gamipress_get_posts', 'gamipress_paid_memberships_pro_ajax_get_posts', 5 );
62 +
63 +// Get the membership title
64 +function gamipress_paid_memberships_pro_get_membership_title( $membership_id ) {
65 +
66 + if( absint( $membership_id ) === 0 ) return '';
67 +
68 + global $wpdb;
69 +
70 + return $wpdb->get_var( $wpdb->prepare(
71 + "SELECT m.name FROM {$wpdb->pmpro_membership_levels} AS m WHERE m.id = %d",
72 + $membership_id
73 + ) );
74 +
75 +}