# gamipress/7.9.8/integrations/groundhogg/includes/functions.php

GamiPress – Gamification plugin to reward points, badges &amp; ranks in WordPress, now with AI, version 7.9.8. 69 lines.

- Page: https://pluginprobe.com/plugins/gamipress/7.9.8/code/integrations/groundhogg/includes/functions.php
- Raw: https://pluginprobe.com/plugins/gamipress/7.9.8/raw/integrations/groundhogg/includes/functions.php
- Modified: 2026-07-13T13:39:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/gamipress/7.9.8/code/integrations/groundhogg/includes/functions.php#L10-L20`.

```php
<?php
/**
 * Functions
 *
 * @package GamiPress\Groundhogg\Functions
 * @since 1.0.0
 */

// Exit if accessed directly
if( !defined( 'ABSPATH' ) ) exit;

/**
 * Overrides GamiPress AJAX Helper for selecting posts
 *
 * @since 1.0.0
 */
function gamipress_groundhogg_ajax_get_posts() {

    // Security check, forces to die if not security passed
    check_ajax_referer( 'gamipress_admin', 'nonce' );

    // Check if user can manage GamiPress
    if( ! current_user_can( gamipress_get_manager_capability() ) ) {
        wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'gamipress' ) );
    }

    global $wpdb;

    if( isset( $_REQUEST['post_type'] ) && in_array( 'groundhogg_tags', $_REQUEST['post_type'] ) ) {

        $results = array();

        // Pull back the search string
        $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( sanitize_text_field( $_REQUEST['q'] ) ) : '';

        // Get the tags
        $tags = Groundhogg\Plugin::$instance->dbs->get_db( 'tags' )->search( $search );

        foreach ( $tags as $tag ) {

            // Results should meet same structure like posts
            $results[] = array(
                'ID' => $tag->tag_id,
                'post_title' => $tag->tag_name,
            );

        }

        // Return our results
        wp_send_json_success( $results );
        die;

    }

}
add_action( 'wp_ajax_gamipress_get_posts', 'gamipress_groundhogg_ajax_get_posts', 5 );

// Get the tag title
function gamipress_groundhogg_get_tag_title( $tag_id ) {

    if( absint( $tag_id ) === 0 ) {
        return '';
    }

    $tag = Groundhogg\Plugin::$instance->dbs->get_db( 'tags' )->get( $tag_id );

    return ( $tag ? $tag->tag_name : '' );

}
```
