| @@ -1,31 +1,31 @@ | ||
| 1 | -<?php | |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - exit; // Exit if accessed directly | |
| 4 | -} | |
| 5 | - | |
| 6 | -global $current_user,$wpdb,$wppmfunction; | |
| 7 | -if (!($current_user->ID && $current_user->has_cap('manage_options') || ($current_user->ID && $current_user->has_cap('wppm_admin')))) { | |
| 8 | - exit; | |
| 9 | -} | |
| 10 | -if ( check_ajax_referer( 'wppm_search_wp_pages', '_ajax_nonce', false ) != 1 ) { | |
| 11 | - wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 12 | -} | |
| 13 | - | |
| 14 | -$term = isset( $_GET['q'] ) ? sanitize_text_field( wp_unslash( $_GET['q'] ) ) : ''; | |
| 15 | - | |
| 16 | -$args = array( | |
| 17 | - 'post_type' => 'page', | |
| 18 | - 'post_status' => 'publish', | |
| 19 | - 'orderby' => array( 'title' => 'ASC' ), | |
| 20 | - 'search_wpsc_title' => $term, | |
| 21 | -); | |
| 22 | -$query = new WP_Query( $args ); | |
| 23 | - | |
| 24 | -$response = array(); | |
| 25 | -foreach ( $query->posts as $page ) { | |
| 26 | - $response[] = array( | |
| 27 | - 'id' => $page->ID, | |
| 28 | - 'title' => $page->post_title, | |
| 29 | - ); | |
| 30 | -} | |
| 1 | +<?php | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; // Exit if accessed directly | |
| 4 | +} | |
| 5 | + | |
| 6 | +global $current_user,$wpdb,$wppmfunction; | |
| 7 | +if (!($current_user->ID && $current_user->has_cap('manage_options') || ($current_user->ID && $current_user->has_cap('wppm_admin')))) { | |
| 8 | + exit; | |
| 9 | +} | |
| 10 | +if ( check_ajax_referer( 'wppm_search_wp_pages', '_ajax_nonce', false ) != 1 ) { | |
| 11 | + wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 12 | +} | |
| 13 | + | |
| 14 | +$term = isset( $_GET['q'] ) ? sanitize_text_field( wp_unslash( $_GET['q'] ) ) : ''; | |
| 15 | + | |
| 16 | +$args = array( | |
| 17 | + 'post_type' => 'page', | |
| 18 | + 'post_status' => 'publish', | |
| 19 | + 'orderby' => array( 'title' => 'ASC' ), | |
| 20 | + 'search_wpsc_title' => $term, | |
| 21 | +); | |
| 22 | +$query = new WP_Query( $args ); | |
| 23 | + | |
| 24 | +$response = array(); | |
| 25 | +foreach ( $query->posts as $page ) { | |
| 26 | + $response[] = array( | |
| 27 | + 'id' => $page->ID, | |
| 28 | + 'title' => $page->post_title, | |
| 29 | + ); | |
| 30 | +} | |
| 31 | 31 | wp_send_json( $response ); |