| 1 |
<?php |
| 2 |
/** |
| 3 |
* Elementor Integration Help. |
| 4 |
* |
| 5 |
* @package Sight |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Sight_Elementor; |
| 9 |
|
| 10 |
/** |
| 11 |
* Elementor Control Point |
| 12 |
* |
| 13 |
* @since 1.0.0 |
| 14 |
*/ |
| 15 |
class Sight_Elementor_Helper { |
| 16 |
|
| 17 |
/** |
| 18 |
* Initialize |
| 19 |
*/ |
| 20 |
public function __construct() { |
| 21 |
add_action( 'wp_ajax_handler_custom_posts', array( $this, 'handler_custom_posts' ) ); |
| 22 |
add_action( 'wp_ajax_nopriv_handler_custom_posts', array( $this, 'handler_custom_posts' ) ); |
| 23 |
add_action( 'wp_ajax_handler_post_title', array( $this, 'handler_post_title' ) ); |
| 24 |
add_action( 'wp_ajax_nopriv_handler_post_title', array( $this, 'handler_post_title' ) ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Get custom posts. |
| 29 |
*/ |
| 30 |
public function handler_custom_posts() { |
| 31 |
|
| 32 |
$posts = array(); |
| 33 |
|
| 34 |
$more = false; |
| 35 |
|
| 36 |
$search_results = new \WP_Query( |
| 37 |
array( |
| 38 |
'post_status' => 'publish', |
| 39 |
'post_type' => 'post', |
| 40 |
'ignore_sticky_posts' => 1, |
| 41 |
's' => sanitize_text_field( $_REQUEST['q'] ), |
| 42 |
'paged' => sanitize_text_field( $_REQUEST['paged'] ), |
| 43 |
'posts_per_page' => sanitize_text_field( $_REQUEST['posts_per_page'] ), |
| 44 |
) |
| 45 |
); |
| 46 |
|
| 47 |
if ( $search_results->have_posts() ) { |
| 48 |
while ( $search_results->have_posts() ) { |
| 49 |
$search_results->the_post(); |
| 50 |
|
| 51 |
$posts[] = array( |
| 52 |
'id' => get_the_ID(), |
| 53 |
'text' => get_the_title(), |
| 54 |
); |
| 55 |
|
| 56 |
$more = true; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
wp_send_json( array( |
| 61 |
'results' => $posts, |
| 62 |
'more' => $more, |
| 63 |
) ); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Get post title. |
| 68 |
*/ |
| 69 |
public function handler_post_title() { |
| 70 |
$post_id = sanitize_text_field( $_REQUEST['post_id'] ); |
| 71 |
|
| 72 |
if ( $post_id ) { |
| 73 |
echo esc_html( get_the_title( $post_id ) ); |
| 74 |
} |
| 75 |
|
| 76 |
die(); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
new Sight_Elementor_Helper(); |
| 81 |
|