← All changes
|
integrations/formidable-forms/includes/functions.php
+48
-0
7.8.8
→
8.0.5
View file →
| @@ -1,0 +1,48 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Functions | |
| 4 | + * | |
| 5 | + * @package GamiPress\Formidable_Forms\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_frm_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 | + if( isset( $_REQUEST['post_type'] ) && in_array( 'formidable_form', $_REQUEST['post_type'] ) ) { | |
| 28 | + $results = array(); | |
| 29 | + | |
| 30 | + $forms = FrmForm::getAll(); | |
| 31 | + | |
| 32 | + foreach ( $forms as $form ) { | |
| 33 | + | |
| 34 | + // Results should meet same structure like posts | |
| 35 | + $results[] = array( | |
| 36 | + 'ID' => $form->id, | |
| 37 | + 'post_title' => $form->name, | |
| 38 | + ); | |
| 39 | + | |
| 40 | + } | |
| 41 | + | |
| 42 | + // Return our results | |
| 43 | + wp_send_json_success( $results ); | |
| 44 | + die; | |
| 45 | + } | |
| 46 | + | |
| 47 | +} | |
| 48 | +add_action( 'wp_ajax_gamipress_get_posts', 'gamipress_frm_ajax_get_posts', 5 ); | |