PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 7.9.8
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v7.9.8
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 7.8.7 All 46 releases
gamipress / integrations / groundhogg / includes / functions.php

functions.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 7.9.8, at integrations/groundhogg/includes/functions.php

69 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions
4 *
5 * @package GamiPress\Groundhogg\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_groundhogg_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( 'groundhogg_tags', $_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 tags
37 $tags = Groundhogg\Plugin::$instance->dbs->get_db( 'tags' )->search( $search );
38
39 foreach ( $tags as $tag ) {
40
41 // Results should meet same structure like posts
42 $results[] = array(
43 'ID' => $tag->tag_id,
44 'post_title' => $tag->tag_name,
45 );
46
47 }
48
49 // Return our results
50 wp_send_json_success( $results );
51 die;
52
53 }
54
55 }
56 add_action( 'wp_ajax_gamipress_get_posts', 'gamipress_groundhogg_ajax_get_posts', 5 );
57
58 // Get the tag title
59 function gamipress_groundhogg_get_tag_title( $tag_id ) {
60
61 if( absint( $tag_id ) === 0 ) {
62 return '';
63 }
64
65 $tag = Groundhogg\Plugin::$instance->dbs->get_db( 'tags' )->get( $tag_id );
66
67 return ( $tag ? $tag->tag_name : '' );
68
69 }