Server IP : 172.67.157.199 / Your IP : 3.142.245.40 [ Web Server : Apache System : Linux b70eb322-3aee-0c53-7c82-0db91281f2c6.secureserver.net 6.1.90-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 2 12:09:22 EDT 2024 x86_64 User : root ( 0) PHP Version : 8.0.30.2 Disable Function : NONE Domains : 0 Domains MySQL : ON | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/wp-content/plugins/gravityforms/includes/embed-form/endpoints/ |
Upload File : |
<?php namespace Gravity_Forms\Gravity_Forms\Embed_Form\Endpoints; /** * AJAX Endpoint for getting posts based on search params. * * @since 2.6 * * @package Gravity_Forms\Gravity_Forms\Embed_Form\Endpoints */ class GF_Embed_Endpoint_Get_Posts { // Strings const ACTION_NAME = 'gf_embed_query_posts'; // Parameters const PARAM_OFFSET = 'offset'; const PARAM_COUNT = 'count'; const PARAM_STATUS = 'status'; const PARAM_SEARCH = 'search'; const PARAM_POST_TYPE = 'post_type'; // Defaults const DEFAULT_OFFSET = 0; const DEFAULT_COUNT = 10; const DEFAULT_STATUS = 'publish'; const DEFAULT_SEARCH = ''; const DEFAULT_POST_TYPE = 'post'; /** * Handle the AJAX request. * * @since 2.6 * * @return void */ public function handle() { check_ajax_referer( self::ACTION_NAME ); $offset = rgpost( self::PARAM_OFFSET ) ? rgpost( self::PARAM_OFFSET ) : self::DEFAULT_OFFSET; $count = rgpost( self::PARAM_COUNT ) ? rgpost( self::PARAM_COUNT ) : self::DEFAULT_COUNT; $status = rgpost( self::PARAM_STATUS ) ? rgpost( self::PARAM_STATUS ) : self::DEFAULT_STATUS; $search = rgpost( self::PARAM_SEARCH ) ? rgpost( self::PARAM_SEARCH ) : self::DEFAULT_SEARCH; $post_type = rgpost( self::PARAM_POST_TYPE ) ? rgpost( self::PARAM_POST_TYPE ) : self::DEFAULT_POST_TYPE; $args = array( 'post_type' => $post_type, 'post_status' => $status, 'posts_per_page' => $count, 'offset' => $offset, 's' => $search, ); $query = new \WP_Query( $args ); $posts = $query->get_posts(); array_walk( $posts, function ( &$post ) { $post = array( 'value' => $post->ID, 'label' => $post->post_title, ); } ); wp_send_json_success( $posts ); } }