public static function instance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Esempio n. 2
0
 function prepare_items()
 {
     $cf7_storage = cf7_storage::instance();
     $per_page = $this->get_items_per_page('cf7_entries_per_page');
     $this->is_trash = isset($_REQUEST['post_status']) && $_REQUEST['post_status'] == 'trash';
     $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
     $query_args = $cf7_storage->get_query_args();
     $query_args['posts_per_page'] = $per_page;
     $query_args['offset'] = ($this->get_pagenum() - 1) * $per_page;
     $query = new WP_Query($query_args);
     $this->items = $query->posts;
     $this->set_pagination_args(array('total_items' => $query->found_posts, 'total_pages' => ceil($query->found_posts / $per_page), 'per_page' => $per_page));
 }
Esempio n. 3
0
 function admin_actions_process()
 {
     global $wpdb;
     // Enqueue our admin style and scripts
     wp_enqueue_style('cf7s-style', plugins_url('assets/css/cf7s-admin.css', __FILE__));
     wp_enqueue_script('cf7s-js', plugins_url('assets/js/cf7s-admin.js', __FILE__), array('jquery'), null, true);
     if (!isset($_REQUEST['action']) || empty($_REQUEST['action'])) {
         return;
     }
     // Make sure this is a valid admin request
     check_admin_referer('bulk-posts');
     $action = $_REQUEST['action'];
     if (isset($_REQUEST['export-entries'])) {
         // Parse request to select posts for export
         $query_args = $this->get_query_args();
         // Export ALL entries
         $query_args['posts_per_page'] = -1;
         $cf7_storage = cf7_storage::instance();
         $cf7_storage->export_entries($query_args);
     }
     if (isset($_REQUEST['delete_all'])) {
         $action = 'delete';
     }
     $action_whitelist = array('export', 'trash', 'delete', 'untrash');
     if (!in_array($action, $action_whitelist)) {
         return;
     }
     $sendback = remove_query_arg(array('export-entries', 'export', 'trashed', 'untrashed', 'deleted', 'delete_all', 'locked', 'ids', 'action', 'action2', 'post_id', '_wp_http_referer', '_wpnonce'));
     $post_ids = array();
     // Collect the post IDs we need to act on
     if ('delete' == $action && !isset($_REQUEST['post_id'])) {
         // Get all posts in trash
         $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s", self::$post_type, 'trash'));
     } elseif (isset($_REQUEST['ids']) && !empty($_REQUEST['ids'])) {
         $post_ids = explode(',', $_REQUEST['ids']);
     } elseif (isset($_REQUEST['post_id']) && !empty($_REQUEST['post_id'])) {
         $post_ids = array((int) $_REQUEST['post_id']);
     } elseif (isset($_REQUEST['post']) && !empty($_REQUEST['post'])) {
         $post_ids = array_map('intval', $_REQUEST['post']);
     }
     // No posts have been selected, bail out
     if (empty($post_ids)) {
         wp_redirect($sendback);
         exit;
     }
     switch ($action) {
         case 'export':
             // Parse request to select posts for export
             $query_args = $this->get_query_args();
             // Export ALL entries
             $query_args['posts_per_page'] = -1;
             $query_args['post__in'] = $post_ids;
             $cf7_storage = cf7_storage::instance();
             $cf7_storage->export_entries($query_args);
             break;
         case 'trash':
             foreach ($post_ids as $post_id) {
                 if (!current_user_can('delete_post', $post_id)) {
                     wp_die(__('You are not allowed to move this item to Trash.', 'cf7-storage'));
                 }
                 if (!wp_trash_post($post_id)) {
                     wp_die(__('Error moving an item to Trash.', 'cf7-storage'));
                 }
                 $sendback = add_query_arg(array('trashed' => true), $sendback);
             }
             break;
         case 'untrash':
             foreach ($post_ids as $post_id) {
                 if (!current_user_can('delete_post', $post_id)) {
                     wp_die(__('You are not allowed to restore this item from Trash.', 'cf7-storage'));
                 }
                 if (!wp_untrash_post($post_id)) {
                     wp_die(__('Error in restoring an item from Trash.', 'cf7-storage'));
                 }
             }
             $sendback = add_query_arg('untrashed', true, $sendback);
             break;
         case 'delete':
             foreach ($post_ids as $post_id) {
                 if (!current_user_can('delete_post', $post_id)) {
                     wp_die(__('You are not allowed to delete this entry.', 'cf7-storage'));
                 }
                 if (!wp_delete_post($post_id, true)) {
                     wp_die(__('Error in deleting an entry.', 'cf7-storage'));
                 }
             }
             $sendback = add_query_arg(array('deleted' => true), $sendback);
             break;
     }
     wp_redirect($sendback);
     exit;
 }