public static function handle_ajax_search()
 {
     check_ajax_referer('psu_search');
     $args = array('post_type' => array());
     if (!empty($_GET['post_type'])) {
         $unsanitized_post_types = array_map('sanitize_key', explode(',', $_GET['post_type']));
         foreach ($unsanitized_post_types as $post_type) {
             if (($post_type_obj = get_post_type_object($post_type)) && current_user_can($post_type_obj->cap->read)) {
                 $args['post_type'][] = $post_type;
             }
         }
     }
     if (count($args['post_type']) < 1) {
         die('-1');
     }
     if (!empty($_GET['paged'])) {
         $args['paged'] = absint($_GET['paged']);
     }
     if (!empty($_GET['s'])) {
         $args['s'] = $_GET['s'];
     }
     if (!empty($_GET['order'])) {
         $args['order'] = $_GET['order'];
     }
     if (!empty($_GET['orderby'])) {
         $args['orderby'] = $_GET['orderby'];
     }
     if (!empty($_GET['post_status']) && (in_array($_GET['post_status'], array_keys(get_post_statuses())) || $_GET['post_status'] === 'inherit' || $_GET['post_status'] == 'any')) {
         $args['post_status'] = $_GET['post_status'];
     }
     if (!empty($_GET['include'])) {
         $args['post__in'] = array_filter(array_map('intval', explode(',', $_GET['include'])));
     }
     if (!empty($_GET['exclude'])) {
         $selected = array_map('intval', explode(',', $_GET['exclude']));
     } else {
         $selected = array();
     }
     $name = 'foobar';
     if (!empty($_GET['name'])) {
         $_name = sanitize_text_field($_GET['name']);
         if ($_name) {
             $name = $_name;
         }
     }
     $psu_box = new Post_Selection_Box($name, array('post_type' => $args['post_type'], 'selected' => $selected));
     $response = new stdClass();
     $response->rows = $psu_box->render_results($args);
     die(json_encode($response));
 }
Пример #2
0
function post_selection_ui($name, $args)
{
    $select_box = new Post_Selection_Box($name, $args);
    return $select_box->render();
}