/**
  * Example of builder initialization
  */
 public function register_builder()
 {
     $this->_builder = new Builder(Functions::get_key(), ['title' => __('Builder'), 'active_callback' => function () {
         return is_home() || is_front_page();
     }]);
     $this->_builder->set_widgets(['Post', ['Video', 'Text'], 'Post', 'Video', 'Post', 'Post', ['Video', 'Text']]);
 }
Esempio n. 2
0
 /**
  * AJAX action for searching posts by category and title/content
  */
 public function action_customize_control_post_search()
 {
     check_ajax_referer();
     if (current_user_can(Builder::get_capability())) {
         wp_send_json_success(wp_list_pluck((new \WP_Query(['post_type' => !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : 'post', 'cat' => !empty($_GET['category']) ? absint($_GET['category']) : 0, 'paged' => !empty($_GET['page']) ? absint($_GET['page']) : 1, 's' => !empty($_GET['s']) && String::length($s = sanitize_text_field($_GET['s'])) > static::MIN_CHARACTERS_NUMBER ? $s : '', 'update_post_meta_cache' => false, 'post__not_in' => array_values(Posts::get_ids())]))->get_posts(), 'post_title', 'ID'));
     }
     wp_send_json_error(__('You are not allowed to do it.'));
 }