# gamipress/7.9.8/integrations/kadence-blocks/includes/functions.php

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

- Page: https://pluginprobe.com/plugins/gamipress/7.9.8/code/integrations/kadence-blocks/includes/functions.php
- Raw: https://pluginprobe.com/plugins/gamipress/7.9.8/raw/integrations/kadence-blocks/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/kadence-blocks/includes/functions.php#L10-L20`.

```php
<?php
/**
 * Functions
 *
 * @package GamiPress\Kadence_Blocks\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_kadence_blocks_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( 'kadence_form', $_REQUEST['post_type'] ) ) {

        // Pull back the search string
        $results = array();

        $forms = gamipress_kadence_blocks_get_forms();

        foreach ( $forms as $form ) {

            // Results should meet same structure like posts
            $results[] = array(
                'ID' => $form['id'],
                'post_title' => $form['name'],
            );

        }

        // Return our results
        wp_send_json_success( $results );
        die;
    }

}
add_action( 'wp_ajax_gamipress_get_posts', 'gamipress_kadence_blocks_ajax_get_posts', 5 );

/**
 * Get all forms
 *
 * @since 1.0.0
 *
 * @return string|null
 */
function gamipress_kadence_blocks_get_forms( ) {

    global $wpdb;

    $all_forms = array();

    $forms = $wpdb->get_results( "select id,post_title,post_content from {$wpdb->posts} where post_content like '%<!-- wp:kadence/form%' and post_status = 'publish'" );
    
    foreach ($forms as $post) {
        $form_id = $post->id;
        $form_title = $post->post_title;
        $form_content = $post->post_content;
        	
        $contentArray = explode('<!--', $form_content);
        $content = [];
        
        foreach ($contentArray as $key => $value) {
        	if (str_contains($value, ' wp:kadence/form')) {
        	    $temp = str_replace(' wp:kadence/form', '', $value);
        	    $temp1 = explode('-->', $temp, 2);
        	    $content[] = json_decode($temp1[0]);
        	}
        }
        	
        if (is_array($content)) {
        	foreach ($content as $form) {
        	    $parent_id = $form->postID;
        	    $unique_id = $form->uniqueID;
        	    $all_forms[] = array(
                    'id' => $unique_id,
                    'name' => $form_title . '_' . $unique_id,     
                );
        	    }
        }
    }

    return $all_forms;

}

/**
 * Get the form title
 *
 * @since 1.0.0
 *
 * @param int $form_id
 *
 * @return string|null
 */
function gamipress_kadence_blocks_get_form_title( $form_id ) {

    // Empty title if no ID provided
    if( empty( $form_id ) ) {
        return '';
    }

    $complete_form_id = explode( '_', $form_id );
    $post_title = get_the_title( $complete_form_id[0] );

    return $post_title . '_' . $form_id;

}
```
