/**
  * Adds new metaboxes.
  * @since 1.0.0
  */
 public function special_metaboxes()
 {
     $post_id = Request::input('post', Request::input('post_ID', 0));
     if ($post_id == get_option('devt_page_downloads', -1)) {
         add_meta_box('devt_section_editor', __('Head section', 'LucyVegas'), [&$this, 'metabox_section_head'], 'page');
     }
 }
 /**
  * Displayes json for search results.
  * @since 1.0
  */
 public function json()
 {
     $data = [];
     try {
         // Search args
         $args = apply_filters('addon_typeahead_query', ['posts_per_page' => Request::input('posts_per_page', get_option('addon_typeahead_limit', 5)), 'post_type' => Request::input('post_type', 'post'), 'post_status' => Request::input('post_status', 'publish'), 's' => Request::input('s', '')]);
         // Results
         $data = Cache::remember('addon_typeahead_res_' . $args['posts_per_page'] . '_' . urlencode($args['s']), 15, function () use(&$args) {
             $query = new WP_Query($args);
             $data = [];
             while ($query->have_posts()) {
                 $query->the_post();
                 $data[] = apply_filters('addon_typeahead_post', get_post(null, OBJECT));
             }
             return $data;
         });
         // Filter results
         $data = Cache::remember('addon_typeahead_filteredres_' . $args['posts_per_page'] . '_' . urlencode($args['s']), 15, function () use(&$data, &$args) {
             return apply_filters('addon_typeahead_data', $data, $args);
         });
     } catch (\Exception $e) {
         Log::error($e);
         $data = [];
     }
     // Render JSON
     header('Content-Type: application/json');
     if (get_option('addon_typeahead_crossdomain', false)) {
         header('Access-Control-Allow-Origin: *');
     }
     echo json_encode($data);
     die;
 }
 /**
  * Displayes queried POSTS in JSON format.
  * @since 1.0
  */
 public function json()
 {
     $filter = ['post_type' => Request::input('type', 'post'), 'post_status' => Request::input('status', 'publish'), 'posts_per_page' => Request::input('limit', 16)];
     // Check for additional filter options
     // Categories
     $input = Request::input('categories', false);
     if ($input) {
         $filter['category_name'] = $input;
     }
     // Tags
     $input = Request::input('tags', false);
     if ($input) {
         $filter['tag'] = $input;
     }
     // Tags
     $input = Request::input('search', false);
     if ($input) {
         $filter['s'] = $input;
     }
     // Query
     $query = new WP_Query($filter);
     $posts = array();
     while ($query->have_posts()) {
         $query->the_post();
         $model = new Post();
         $posts[] = $model->from_post(get_post())->to_array();
     }
     // Display
     header('Content-Type: application/json');
     echo json_encode($posts);
     die;
 }
 /**
  * Save page.
  * @since 1.0.0
  *
  * @param int $post_id Post id.
  */
 public function save($post_id)
 {
     // Is valid save ?
     $nonce = Request::input('metabox_section_nonce', '', true);
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || empty($nonce) || !wp_verify_nonce($nonce, 'metabox_section')) {
         return;
     }
     foreach (Request::input('sections', []) as $section) {
         update_post_meta($post_id, $section, Request::input($section));
     }
 }
 /**
  * Save page.
  * @since 1.0.0
  *
  * @param int $post_id Post id.
  */
 public function save($post_id)
 {
     // Is valid save ?
     $nonce = Request::input('metabox_addon_nonce', '', true);
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || empty($nonce) || !wp_verify_nonce($nonce, 'metabox_addon')) {
         return;
     }
     $addon = Addon::find($post_id);
     $addon->description = Request::input('description');
     $addon->composer = Request::input('composer');
     $addon->bower = Request::input('bower');
     $addon->url = Request::input('url');
     $addon->download_url = Request::input('download_url');
     $addon->version = Request::input('version');
     $addon->supported_version = Request::input('supported_version');
     $addon->github_username = Request::input('github_username');
     $addon->github_repo = Request::input('github_repo');
     $addon->save();
 }
 /**
  * Requests user information.
  * @since 1.0
  *
  * @param object $user By reference user.
  * @param object $user By reference errors.
  */
 protected function request(&$user, &$errors)
 {
     $errors = new WP_Error();
     $value = Request::input('user_login');
     if (empty($value)) {
         $errors->add('empty_user_login', 'Field <strong>Username or Email</strong> cannot be empty.');
     } else {
         if (preg_match('/\\@/', $value)) {
             if (!is_email($value)) {
                 $errors->add('invalid_email', 'Field <strong>Email</strong> is invalid.');
             } else {
                 if (email_exists($value)) {
                     $user = get_user_by('email', $value);
                 } else {
                     $errors->add('email_unknown', 'Unknown <strong>Email</strong>.');
                 }
             }
         } else {
             if (username_exists($value)) {
                 $user = get_user_by('login', $value);
             } else {
                 $errors->add('username_unknown', 'Unknown <strong>Username</strong>.');
             }
         }
     }
     if (empty($user)) {
         return;
     }
     // Last actions and validations
     do_action('lostpassword_post');
     do_action('retrieve_password', $user->user_login);
     if (!apply_filters('allow_password_reset', true, $user->ID)) {
         $errors->add('no_password_reset', 'Password reset is not allowed for this user.');
     }
 }
 /**
  * Generates user based on request input.
  * @since 1.0
  *
  * @return array
  */
 protected function generate_userdata()
 {
     $userdata = ['user_login' => sanitize_user(Request::input('user_login')), 'user_email' => Request::input('user_email'), 'user_pass' => Request::input('user_pass'), 'user_url' => Request::input('user_url', ''), 'first_name' => Request::input('first_name', ''), 'last_name' => Request::input('last_name', ''), 'display_name' => Request::input('display_name', Request::input('user_login')), 'repeat_pass' => Request::input('repeat_pass')];
     return apply_filters('addon_loginpage_signup_userdata', $userdata);
 }
 /**
  * Returns redirect to url.
  * @since 1.0
  *
  * @return string
  */
 public static function get_redirect_to()
 {
     // At query string
     $redirect_to = Request::input('redirect_to', home_url('/'));
     // At SESSION
     if (isset($_SESSION['redirect_me_back'])) {
         $redirect_to = $_SESSION['redirect_me_back'];
     }
     // Apply filters
     return apply_filters('addon_loginpage_redirect_to', $redirect_to);
 }
 /**
  * Performs login operation.
  * @since 1.0
  */
 protected function do_login()
 {
     // Redirect to.
     $redirect_to = LoginPage::get_redirect_to();
     // Cookie authentication
     if ($this->cookie_authenticate()) {
         wp_safe_redirect(LoginPage::get_redirect_to());
     } else {
         wp_enqueue_script('addon-loginpage');
         return $this->view->get('addons.loginpage.login', ['token' => LoginPage::generate_token(), 'action' => admin_url('admin-ajax.php?action=addon_login'), 'redirect_to' => Request::input('redirect_to')]);
     }
 }
Esempio n. 10
0
 /**
  * Save post hook.
  * @since 1.0.0
  *
  * @param int $post_id Post id.
  */
 public function save_post($post_id)
 {
     switch (Request::input('post_type')) {
         case 'page':
             $this->mvc->call('PageController@save', $post_id);
             break;
         case 'addon':
             $this->mvc->call('AddonController@save', $post_id);
             break;
     }
 }