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/bookingcalendar/includes/functions.php +93 -0 7.9.9.2 → 8.0.5 View file →
@@ -1,0 +1,93 @@
1 +<?php
2 +/**
3 + * Functions
4 + *
5 + * @package GamiPress\BookingCalendar\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_bookingcalendar_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( 'booking', $_REQUEST['post_type'] ) ) {
30 +
31 + // Pull back the search string
32 + $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( sanitize_text_field( $_REQUEST['q'] ) ) : '';
33 + $results = array();
34 +
35 + if( gamipress_is_network_wide_active() ) {
36 +
37 + // Look for results on all sites on a multisite install
38 + foreach( gamipress_get_network_site_ids() as $site_id ) {
39 +
40 + // Switch to site
41 + switch_to_blog( $site_id );
42 +
43 + // Get the current site name to append it to results
44 + $site_name = get_bloginfo( 'name' );
45 +
46 + if( class_exists( 'Booking_Calendar' ) ) {
47 +
48 + // Get the bookings
49 + $site_bookings = $wpdb->get_results( $wpdb->prepare(
50 + "SELECT booking_id, sort_date FROM {$wpdb->prefix}booking WHERE booking_id LIKE %s",
51 + "%%{$search}%%"
52 + ) );
53 +
54 + foreach ( $site_bookings as $booking ) {
55 +
56 + // Results should meet same structure like posts
57 + $results[] = array(
58 + 'ID' => $booking->booking_id,
59 + 'post_title' => 'Booking ' . $booking->booking_id . ': ' . $booking->sort_date,
60 + 'site_id' => $site_id,
61 + 'site_name' => $site_name,
62 + );
63 + }
64 + }
65 +
66 + // Restore current site
67 + restore_current_blog();
68 +
69 + }
70 +
71 + }else {
72 + // Get the bookings
73 + $site_bookings = $wpdb->get_results( $wpdb->prepare(
74 + "SELECT booking_id, sort_date FROM {$wpdb->prefix}booking WHERE booking_id LIKE %s",
75 + "%%{$search}%%"
76 + ) );
77 +
78 + foreach( $site_bookings as $booking ) {
79 + $results[] = array(
80 + 'id' => $booking->booking_id,
81 + 'text' => 'Booking ' . $booking->booking_id . ': ' . $booking->sort_date,
82 + );
83 + }
84 +
85 + }
86 +
87 + // Return our results
88 + wp_send_json_success( $results );
89 + die;
90 + }
91 +
92 +}
93 +add_action( 'wp_ajax_gamipress_get_posts', 'gamipress_bookingcalendar_ajax_get_posts', 5 );