Esempio n. 1
1
 /**
  * Generic function to test the forum counts on a trashed/untrashed topic
  */
 public function test_bbp_forum_trashed_untrashed_topic_counts()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create_many(3, array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $r1 = $this->factory->reply->create_many(2, array('post_parent' => $t[1], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t[1])));
     $r2 = $this->factory->reply->create_many(2, array('post_parent' => $t[2], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t[2])));
     $count = bbp_update_forum_topic_count($f);
     $this->assertSame(3, $count);
     $count = bbp_update_forum_topic_count_hidden($f);
     $this->assertSame(0, $count);
     $count = bbp_update_forum_reply_count($f);
     $this->assertSame(4, $count);
     // ToDo: Update this to use bbp_trash_topic().
     wp_trash_post($t[2]);
     $count = bbp_get_forum_topic_count($f, true, true);
     $this->assertSame(2, $count);
     $count = bbp_get_forum_topic_count_hidden($f, true, true);
     $this->assertSame(1, $count);
     $count = bbp_get_forum_reply_count($f, true, true);
     $this->assertSame(2, $count);
     // ToDo: Update this to use bbp_untrash_topic().
     wp_untrash_post($t[2]);
     $count = bbp_get_forum_topic_count($f, true, true);
     $this->assertSame(3, $count);
     $count = bbp_get_forum_topic_count_hidden($f, true, true);
     $this->assertSame(0, $count);
     $count = bbp_get_forum_reply_count($f, true, true);
     $this->assertSame(4, $count);
 }
 /**
  * Restores all the children events of an event post from the trash to their previous state.
  * @param $post_id
  */
 public function untrash_all($post_id)
 {
     $children = $this->get_ids($post_id, array('post_status' => 'trash'));
     foreach ($children as $child_id) {
         wp_untrash_post($child_id);
     }
 }
 public function untrash_translation($trans_id)
 {
     if (WPML_WordPress_Actions::is_bulk_untrash($trans_id)) {
         // Do nothing as the translation is part of the bulk untrash.
     } else {
         wp_untrash_post($trans_id);
     }
 }
 function restore_all_ticket_types()
 {
     $args = array('post_type' => 'tc_tickets', 'post_status' => 'trash');
     $ticket_types = get_posts($args);
     foreach ($ticket_types as $ticket_type) {
         wp_untrash_post($ticket_type->ID);
     }
 }
 /**
  * @ticket 11863
  */
 function test_untrashing_a_post_with_a_stored_desired_post_name_should_get_its_post_name_suffixed_if_another_post_has_taken_the_desired_post_name()
 {
     $about_page_id = self::factory()->post->create(array('post_type' => 'page', 'post_title' => 'About', 'post_status' => 'publish'));
     wp_trash_post($about_page_id);
     $another_about_page_id = self::factory()->post->create(array('post_type' => 'page', 'post_title' => 'About', 'post_status' => 'publish'));
     wp_untrash_post($about_page_id);
     $this->assertEquals('about', get_post($another_about_page_id)->post_name);
     $this->assertEquals('about-2', get_post($about_page_id)->post_name);
 }
 function restore_event($event_id)
 {
     wp_untrash_post($event_id);
     //delete event ticket types
     $args = array('post_type' => 'tc_tickets', 'meta_key' => 'event_name', 'meta_value' => $event_id);
     $ticket_types = get_posts($args);
     foreach ($ticket_types as $ticket_type) {
         wp_untrash_post($ticket_type->ID);
     }
 }
 function untrash_order($id = false)
 {
     $id = $id ? $id : $this->id;
     wp_untrash_post($id);
     //Delete associated ticket instances
     $args = array('post_type' => 'tc_tickets_instances', 'post_status' => 'trash', 'post_parent' => $id);
     $ticket_instances = get_posts($args);
     foreach ($ticket_instances as $ticket_instance) {
         wp_untrash_post($ticket_instance->ID);
     }
 }
Esempio n. 8
0
/**
 * Restore menu items when restore post type erm_menu
 *
 * @since 1.0
 * @param $post_id
 */
function erm_untrash_menu_items($post_id)
{
    if (get_post_type($post_id) != 'erm_menu') {
        return;
    }
    $menu_items = get_post_meta($post_id, '_erm_menu_items', true);
    if (empty($menu_items)) {
        return array();
    }
    $menu_items = preg_split('/,/', $menu_items);
    foreach ($menu_items as $id) {
        wp_untrash_post($id);
    }
}
 /**
  * Callback on post untrashing
  *
  * @param int $post_id ID of post being untrashed
  *
  * @return void Method does not return
  */
 public function untrashed_post($post_id)
 {
     try {
         $ai1ec_event = new Ai1ec_Event($post_id);
         if (isset($ai1ec_event->post) && !empty($ai1ec_event->recurrence_rules)) {
             // untrash child event
             global $ai1ec_events_helper;
             $children = $ai1ec_events_helper->get_child_event_objects($ai1ec_event->post_id, true);
             foreach ($children as $child) {
                 wp_untrash_post($child->post_id);
             }
         }
     } catch (Ai1ec_Event_Not_Found $exception) {
         // ignore - not an event
     }
 }
Esempio n. 10
0
 /**
  * Untrash all connected events of a production.
  *
  * Whenever a production is untrashed, make sure that all connected events are untrashed as well.
  *
  * @since 0.7
  *
  */
 function untrash_post($post_id)
 {
     $post = get_post($post_id);
     if (!empty($post) && $post->post_type == WPT_Production::post_type_name) {
         $args = array('post_type' => WPT_Event::post_type_name, 'post_status' => 'trash', 'meta_query' => array(array('key' => WPT_Production::post_type_name, 'value' => $post_id)));
         $events = get_posts($args);
         foreach ($events as $event) {
             wp_untrash_post($event->ID);
         }
     }
 }
Esempio n. 11
0
function acf_untrash_field($selector = 0)
{
    // disable filters to ensure ACF loads raw data from DB
    acf_disable_filters();
    // load the origional field gorup
    $field = acf_get_field($selector);
    // bail early if field did not load correctly
    if (empty($field)) {
        return false;
    }
    // delete field
    wp_untrash_post($field['ID']);
    // action for 3rd party customisation
    do_action('acf/untrash_field', $field);
    // return
    return true;
}
Esempio n. 12
0
/**
 * Create temporary post with motopress adapted content
 */
function motopressCECreateTemporaryPost($post_id, $content)
{
    $post = get_post($post_id);
    $post->ID = '';
    $post->post_title = 'temporary';
    $post->post_content = '<div class="motopress-content-wrapper">' . $content . '</div>';
    $post->post_status = 'trash';
    $userRole = wp_get_current_user()->roles[0];
    $optionName = 'motopress_tmp_post_id_' . $userRole;
    $id = get_option($optionName);
    if ($id) {
        if (is_null(get_post($id))) {
            $id = wp_insert_post($post, false);
            update_option($optionName, $id);
        }
    } else {
        $id = wp_insert_post($post, false);
        add_option($optionName, $id);
    }
    $post->ID = (int) $id;
    global $wpdb;
    $wpdb->delete($wpdb->posts, array('post_parent' => $post->ID, 'post_type' => 'revision'), array('%d', '%s'));
    //@todo: remove in next version
    wp_update_post($post);
    wp_untrash_post($post->ID);
    motopressCEClonePostmeta($post_id, $post->ID);
    do_action('mp_post_meta', $post->ID, $post->post_type);
    do_action('mp_theme_fix', $post_id, $post->ID, $post->post_type);
    $pageTemplate = get_post_meta($post_id, '_wp_page_template', true);
    $pageTemplate = (!$pageTemplate or empty($pageTemplate)) ? 'default' : $pageTemplate;
    update_post_meta($post->ID, '_wp_page_template', $pageTemplate);
    return $post->ID;
}
 /**
  * Default function for handling manage page post backs.
  *
  */
 public function handle_manage_page_postback()
 {
     global $wpdb;
     if (!current_user_can('edit_pages')) {
         wp_die(__('Cheatin&#8217; uh?'));
     }
     // Handle bulk actions
     if (isset($_POST['doaction']) || isset($_POST['doaction2']) || isset($_POST['delete_all']) || isset($_POST['delete_all2']) || isset($_POST['bulk_edit'])) {
         check_admin_referer('bulk-' . $this->get_content_type());
         $sendback = wp_get_referer();
         if (isset($_POST['delete_all']) || isset($_POST['delete_all2'])) {
             $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_POST['post_status']);
             $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type=%s AND post_status = %s", $this->get_content_type(), $post_status));
             $doaction = 'delete';
         } elseif (($_POST['action'] != -1 || $_POST['action2'] != -1) && isset($_POST['post'])) {
             $post_ids = array_map('intval', (array) $_POST['post']);
             $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
         } else {
             wp_redirect($sendback);
         }
         //handle case where trash isn't available yet on VIP
         if ($doaction == 'trash' && !function_exists('wp_trash_post')) {
             $doaction = 'delete';
         }
         switch ($doaction) {
             case 'trash':
                 $trashed = 0;
                 foreach ((array) $post_ids as $post_id) {
                     if (!current_user_can('delete_page', $post_id)) {
                         wp_die(__('You are not allowed to move this page to the trash.'));
                     }
                     if (!wp_trash_post($post_id)) {
                         wp_die(__('Error in moving to trash...'));
                     }
                     $trashed++;
                 }
                 $sendback = add_query_arg('trashed', $trashed, $sendback);
                 break;
             case 'untrash':
                 $untrashed = 0;
                 foreach ((array) $post_ids as $post_id) {
                     if (!current_user_can('delete_page', $post_id)) {
                         wp_die(__('You are not allowed to restore this page from the trash.'));
                     }
                     if (!wp_untrash_post($post_id)) {
                         wp_die(__('Error in restoring from trash...'));
                     }
                     $untrashed++;
                 }
                 $sendback = add_query_arg('untrashed', $untrashed, $sendback);
                 break;
             case 'delete':
                 $deleted = 0;
                 foreach ((array) $post_ids as $post_id) {
                     $post_del =& get_post($post_id);
                     if (!current_user_can('delete_page', $post_id)) {
                         wp_die(__('You are not allowed to delete this page.'));
                     }
                     if ($post_del->post_type == 'attachment') {
                         if (!wp_delete_attachment($post_id)) {
                             wp_die(__('Error in deleting...'));
                         }
                     } else {
                         if (!wp_delete_post($post_id)) {
                             wp_die(__('Error in deleting...'));
                         }
                     }
                     $deleted++;
                 }
                 $sendback = add_query_arg('deleted', $deleted, $sendback);
                 break;
             case 'edit':
                 $_POST['post_type'] = $this->get_content_type();
                 $done = bulk_edit_posts($_POST);
                 if (is_array($done)) {
                     $done['updated'] = count($done['updated']);
                     $done['skipped'] = count($done['skipped']);
                     $done['locked'] = count($done['locked']);
                     $sendback = add_query_arg($done, $sendback);
                 }
                 break;
         }
         if (isset($_POST['action'])) {
             $sendback = remove_query_arg(array('action', 'action2', 'post_parent', 'page_template', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view', 'post_type'), $sendback);
         }
         wp_redirect($sendback);
         exit;
     } elseif (isset($_POST['_wp_http_referer']) && !empty($_POST['_wp_http_referer'])) {
         wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
         exit;
     }
 }
Esempio n. 14
0
/**
 * Called before untrashing a topic
 *
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_is_topic() To check if the passed id is a topic
 * @uses do_action() Calls 'bbp_untrash_topic' with the topic id
 * @uses get_post_meta() To get the list of replies which were trashed with the
 *                        topic
 * @uses wp_untrash_post() To untrash the reply
 */
function bbp_untrash_topic($topic_id = 0)
{
    $topic_id = bbp_get_topic_id($topic_id);
    if (empty($topic_id) || !bbp_is_topic($topic_id)) {
        return false;
    }
    do_action('bbp_untrash_topic', $topic_id);
    // Get the replies that were not previously trashed
    $pre_trashed_replies = get_post_meta($topic_id, '_bbp_pre_trashed_replies', true);
    // There are replies to untrash
    if (!empty($pre_trashed_replies)) {
        // Maybe reverse the trashed replies array
        if (is_array($pre_trashed_replies)) {
            $pre_trashed_replies = array_reverse($pre_trashed_replies);
        }
        // Loop through replies
        foreach ((array) $pre_trashed_replies as $reply) {
            wp_untrash_post($reply);
        }
    }
}
Esempio n. 15
0
/**
 * Trash all topics inside a forum
 *
 * @since bbPress (r3668)
 *
 * @param int $forum_id
 * @uses bbp_get_forum_id() To validate the forum ID
 * @uses bbp_is_forum() To make sure it's a forum
 * @uses get_post_meta() To update the forum meta of trashed topics
 * @uses wp_untrash_post() To trash the post
 * @return If forum is not valid
 */
function bbp_untrash_forum_topics($forum_id = 0)
{
    // Validate forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    if (empty($forum_id)) {
        return;
    }
    // Get the topics that were not previously trashed
    $pre_trashed_topics = get_post_meta($forum_id, '_bbp_pre_trashed_topics', true);
    // There are topics to untrash
    if (!empty($pre_trashed_topics)) {
        // Maybe reverse the trashed topics array
        if (is_array($pre_trashed_topics)) {
            $pre_trashed_topics = array_reverse($pre_trashed_topics);
        }
        // Loop through topics
        foreach ((array) $pre_trashed_topics as $topic) {
            wp_untrash_post($topic);
        }
    }
}
Esempio n. 16
0
 /**
  * Process the bulk actions
  */
 public function process_bulk_action()
 {
     $ids = isset($_GET['post']) ? $_GET['post'] : false;
     $action = $this->current_action();
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     if (empty($action)) {
         return;
     }
     foreach ($ids as $id) {
         // Detect when a bulk action is being triggered...
         if ('trash' === $this->current_action()) {
             wp_trash_post($id);
         }
         if ('publish' === $this->current_action()) {
             wp_publish_post($id);
         }
         if ('pending' === $this->current_action()) {
             // Update post
             $u_post = array();
             $u_post['ID'] = $id;
             $u_post['post_status'] = 'pending';
             // Update the post into the database
             wp_update_post($u_post);
         }
         if ('delete' === $this->current_action()) {
             wp_delete_post($id, true);
         }
         if ('restore' === $this->current_action()) {
             wp_untrash_post($id);
         }
         do_action('ap_moderate_table_do_bulk_action', $id, $this->current_action());
     }
 }
 /**
  * Bulk untrash.
  *
  * @param array $webhooks
  */
 private function bulk_untrash($webhooks)
 {
     foreach ($webhooks as $webhook_id) {
         wp_untrash_post($webhook_id);
     }
     $qty = count($webhooks);
     delete_transient('woocommerce_webhook_ids');
     // Redirect to webhooks page
     wp_redirect(admin_url('admin.php?page=wc-settings&tab=api&section=webhooks&status=trash&untrashed=' . $qty));
     exit;
 }
Esempio n. 18
0
function acf_untrash_field_group($selector = 0)
{
    // disable JSON to avoid conflicts between DB and JSON
    acf_disable_local();
    // load the origional field gorup
    $field_group = acf_get_field_group($selector);
    // bail early if field group did not load correctly
    if (empty($field_group)) {
        return false;
    }
    // get fields
    $fields = acf_get_fields($field_group);
    if (!empty($fields)) {
        foreach ($fields as $field) {
            acf_untrash_field($field['ID']);
        }
    }
    // delete
    wp_untrash_post($field_group['ID']);
    // action for 3rd party customization
    do_action('acf/untrash_field_group', $field_group);
    // return
    return true;
}
 function restore_post($path, $blog_id, $post_id)
 {
     $args = $this->query_args();
     $post = get_post($post_id);
     if (!$post || is_wp_error($post)) {
         return new WP_Error('unknown_post', 'Unknown post', 404);
     }
     if (!current_user_can('delete_post', $post->ID)) {
         return new WP_Error('unauthorized', 'User cannot restore trashed posts', 403);
     }
     /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
     do_action('wpcom_json_api_objects', 'posts');
     wp_untrash_post($post->ID);
     return $this->get_post_by('ID', $post->ID, $args['context']);
 }
/**
 * Handles the front end spamming/unspamming and trashing/untrashing/deleting of
 * replies
 *
 * @since bbPress (r2740)
 *
 * @param string $action The requested action to compare this function to
 * @uses bbp_get_reply() To get the reply
 * @uses current_user_can() To check if the user is capable of editing or
 *                           deleting the reply
 * @uses check_ajax_referer() To verify the nonce and check the referer
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_is_reply_spam() To check if the reply is marked as spam
 * @uses bbp_spam_reply() To make the reply as spam
 * @uses bbp_unspam_reply() To unmark the reply as spam
 * @uses wp_trash_post() To trash the reply
 * @uses wp_untrash_post() To untrash the reply
 * @uses wp_delete_post() To delete the reply
 * @uses do_action() Calls 'bbp_toggle_reply_handler' with success, post data
 *                    and action
 * @uses bbp_get_reply_url() To get the reply url
 * @uses wp_safe_redirect() To redirect to the reply
 * @uses bbPress::errors:add() To log the error messages
 */
function bbp_toggle_reply_handler($action = '')
{
    // Bail if required GET actions aren't passed
    if (empty($_GET['reply_id'])) {
        return;
    }
    // Setup possible get actions
    $possible_actions = array('bbp_toggle_reply_spam', 'bbp_toggle_reply_trash');
    // Bail if actions aren't meant for this function
    if (!in_array($action, $possible_actions)) {
        return;
    }
    $failure = '';
    // Empty failure string
    $view_all = false;
    // Assume not viewing all
    $reply_id = (int) $_GET['reply_id'];
    // What's the reply id?
    $success = false;
    // Flag
    $post_data = array('ID' => $reply_id);
    // Prelim array
    // Make sure reply exists
    $reply = bbp_get_reply($reply_id);
    if (empty($reply)) {
        return;
    }
    // What is the user doing here?
    if (!current_user_can('edit_reply', $reply->ID) || 'bbp_toggle_reply_trash' === $action && !current_user_can('delete_reply', $reply->ID)) {
        bbp_add_error('bbp_toggle_reply_permission', __('<strong>ERROR:</strong> You do not have the permission to do that!', 'bbpress'));
        return;
    }
    // What action are we trying to perform?
    switch ($action) {
        // Toggle spam
        case 'bbp_toggle_reply_spam':
            check_ajax_referer('spam-reply_' . $reply_id);
            $is_spam = bbp_is_reply_spam($reply_id);
            $success = $is_spam ? bbp_unspam_reply($reply_id) : bbp_spam_reply($reply_id);
            $failure = $is_spam ? __('<strong>ERROR</strong>: There was a problem unmarking the reply as spam!', 'bbpress') : __('<strong>ERROR</strong>: There was a problem marking the reply as spam!', 'bbpress');
            $view_all = !$is_spam;
            break;
            // Toggle trash
        // Toggle trash
        case 'bbp_toggle_reply_trash':
            $sub_action = in_array($_GET['sub_action'], array('trash', 'untrash', 'delete')) ? $_GET['sub_action'] : false;
            if (empty($sub_action)) {
                break;
            }
            switch ($sub_action) {
                case 'trash':
                    check_ajax_referer('trash-' . bbp_get_reply_post_type() . '_' . $reply_id);
                    $view_all = true;
                    $success = wp_trash_post($reply_id);
                    $failure = __('<strong>ERROR</strong>: There was a problem trashing the reply!', 'bbpress');
                    break;
                case 'untrash':
                    check_ajax_referer('untrash-' . bbp_get_reply_post_type() . '_' . $reply_id);
                    $success = wp_untrash_post($reply_id);
                    $failure = __('<strong>ERROR</strong>: There was a problem untrashing the reply!', 'bbpress');
                    break;
                case 'delete':
                    check_ajax_referer('delete-' . bbp_get_reply_post_type() . '_' . $reply_id);
                    $success = wp_delete_post($reply_id);
                    $failure = __('<strong>ERROR</strong>: There was a problem deleting the reply!', 'bbpress');
                    break;
            }
            break;
    }
    // Do additional reply toggle actions
    do_action('bbp_toggle_reply_handler', $success, $post_data, $action);
    // No errors
    if (false !== $success && !is_wp_error($success)) {
        /** Redirect **********************************************************/
        // Redirect to
        $redirect_to = bbp_get_redirect_to();
        // Get the reply URL
        $reply_url = bbp_get_reply_url($reply_id, $redirect_to);
        // Add view all if needed
        if (!empty($view_all)) {
            $reply_url = bbp_add_view_all($reply_url, true);
        }
        // Redirect back to reply
        wp_safe_redirect($reply_url);
        // For good measure
        exit;
        // Handle errors
    } else {
        bbp_add_error('bbp_toggle_reply', $failure);
    }
}
Esempio n. 21
0
         }
         if (!wp_trash_post($post_id)) {
             wp_die(__('Error in moving to trash.'));
         }
     }
     $location = add_query_arg(array('trashed' => count($post_ids), 'ids' => join(',', $post_ids)), $location);
     break;
 case 'untrash':
     if (!isset($post_ids)) {
         break;
     }
     foreach ((array) $post_ids as $post_id) {
         if (!current_user_can('delete_post', $post_id)) {
             wp_die(__('You are not allowed to move this post out of the trash.'));
         }
         if (!wp_untrash_post($post_id)) {
             wp_die(__('Error in restoring from trash.'));
         }
     }
     $location = add_query_arg('untrashed', count($post_ids), $location);
     break;
 case 'delete':
     if (!isset($post_ids)) {
         break;
     }
     foreach ((array) $post_ids as $post_id_del) {
         if (!current_user_can('delete_post', $post_id_del)) {
             wp_die(__('You are not allowed to delete this post.'));
         }
         if (!wp_delete_attachment($post_id_del)) {
             wp_die(__('Error in deleting.'));
Esempio n. 22
0
 /**
  * Restore a post from the trash
  * (yet unused)
  *
  * @since 1.0.0
  * @uses wp_untrash_post()
  *
  * @param int $post_id Post ID
  * @return array|bool Post on success, false on error
  */
 public function untrash($post_id)
 {
     return wp_untrash_post($post_id);
 }
Esempio n. 23
0
 function untrashed_post_actions($post_id)
 {
     global $wpdb;
     $post_type = $wpdb->get_var("SELECT post_type FROM {$wpdb->posts} WHERE ID={$post_id}");
     if ($this->settings['sync_delete']) {
         $trid = $this->get_element_trid($post_id, 'post_' . $post_type);
         $translations = $this->get_element_translations($trid, 'post_' . $post_type);
         foreach ($translations as $t) {
             /* The first line of these checks ensures, that we are actually restoring a trashed post.
              * The second line ensures, that this post is not going to be restored anyways through a bulk
              * action from the UI.
              */
             if (isset($t->element_id) && $t->element_id != $post_id && get_post_status($t->element_id) == 'trash' && !(isset($_REQUEST['post']) && is_array($_REQUEST['post']) && in_array($t->element_id, $_REQUEST['post']))) {
                 remove_action('untrashed_post', array($this, 'untrashed_post_actions'));
                 wp_untrash_post($t->element_id);
                 add_action('untrashed_post', array($this, 'untrashed_post_actions'));
             }
         }
     }
     require_once ICL_PLUGIN_PATH . '/inc/cache.php';
     icl_cache_clear($post_type . 's_per_language', true);
 }
Esempio n. 24
0
 /**
  * If questions is restored then restore its answers too.
  * @param  integer $post_id Post ID.
  * @since 2.0.0
  */
 public function untrash_ans_on_question_untrash($post_id)
 {
     $post = get_post($post_id);
     if ($post->post_type == 'question') {
         do_action('ap_untrash_question', $post->ID);
         $ans = get_posts(array('post_type' => 'answer', 'post_status' => 'trash', 'post_parent' => $post_id, 'showposts' => -1));
         if ($ans > 0) {
             foreach ($ans as $p) {
                 do_action('ap_untrash_answer', $p->ID);
                 wp_untrash_post($p->ID);
             }
         }
         // Restore question history.
         ap_restore_question_history($post_id);
     }
     if ($post->post_type == 'answer') {
         $ans = ap_count_published_answers($post->post_parent);
         do_action('untrash_answer', $post->ID, $post->post_author);
         // Update answer count.
         update_post_meta($post->post_parent, ANSPRESS_ANS_META, $ans + 1);
     }
 }
 public function process_bulk_action()
 {
     global $pagenow, $wpdb;
     if (!isset($_REQUEST['_wpnonce'])) {
         return;
     }
     $nonce = esc_attr($_REQUEST['_wpnonce']);
     if (!wp_verify_nonce($nonce, 'bulk-donations')) {
         wp_die(__('Invalid Nonce for deleting WC Donation Orders', WC_QD_TXT));
     }
     $doaction = $this->current_action();
     if ($doaction) {
         $pagenum = $this->get_pagenum();
         $sendback = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'locked', 'ids'), wp_get_referer());
         if (!$sendback) {
             $sendback = admin_url($parent_file);
         }
         $sendback = add_query_arg('paged', $pagenum, $sendback);
         if (strpos($sendback, 'post.php') !== false) {
             $sendback = admin_url($post_new_file);
         }
         if (isset($_REQUEST['post'])) {
             $post_ids = array_map('intval', $_REQUEST['post']);
         }
         var_dump($this->screen);
         if ('delete_all' == $doaction) {
             // Prepare for deletion of all posts with a specified post status (i.e. Empty trash).
             $post_status = preg_replace('/[^a-z0-9_-]+/i', '', 'trash');
             // Validate the post status exists.
             if (get_post_status_object($post_status)) {
                 $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type=%s AND post_status = %s", 'shop_order', $post_status));
             }
             $doaction = 'delete';
         }
         $total_post = count($post_ids);
         $ids = implode(', ', $post_ids);
         $Notice_Txt = '';
         switch ($doaction) {
             case 'trash':
                 $trashed = $locked = 0;
                 foreach ((array) $post_ids as $post_id) {
                     if (!current_user_can('delete_post', $post_id)) {
                         wp_die(__('You are not allowed to move this item to the Trash.'));
                     }
                     if (wp_check_post_lock($post_id)) {
                         $locked++;
                         continue;
                     }
                     if (!wp_trash_post($post_id)) {
                         wp_die(__('Error in moving to Trash.'));
                     }
                     $trashed++;
                     $Notice_Txt = ' Trashed ';
                 }
                 $sendback = add_query_arg(array('trashed' => $trashed, 'ids' => join(',', $post_ids), 'locked' => $locked), $sendback);
                 wc_qd_notice(sprintf(_n('%s Donation Order Trashed  ( %s )', '%s Donation Orders Trashed  ( %s )', $total_post, $ids, WC_QD_TXT), $total_post, $ids));
                 break;
             case 'untrash':
                 $untrashed = 0;
                 foreach ((array) $post_ids as $post_id) {
                     if (!current_user_can('delete_post', $post_id)) {
                         wp_die(__('You are not allowed to restore this item from the Trash.'));
                     }
                     if (!wp_untrash_post($post_id)) {
                         wp_die(__('Error in restoring from Trash.'));
                     }
                     $untrashed++;
                 }
                 $sendback = add_query_arg('untrashed', $untrashed, $sendback);
                 wc_qd_notice(sprintf(_n('%s Donation Order restored from trash  ( %s )', '%s Donation Orders restored from trash ( %s )', $total_post, $ids, WC_QD_TXT), $total_post, $ids));
                 break;
             case 'delete':
                 $deleted = 0;
                 foreach ((array) $post_ids as $post_id) {
                     $post_del = get_post($post_id);
                     if (!current_user_can('delete_post', $post_id)) {
                         wp_die(__('You are not allowed to delete this item.'));
                     }
                     if ($post_del->post_type == 'attachment') {
                         if (!wp_delete_attachment($post_id)) {
                             wp_die(__('Error in deleting.'));
                         }
                     } else {
                         if (!wp_delete_post($post_id)) {
                             wp_die(__('Error in deleting.'));
                         }
                     }
                     $deleted++;
                 }
                 $sendback = add_query_arg('deleted', $deleted, $sendback);
                 wc_qd_notice(sprintf(_n('%s Donation Order permanently deleted  ( %s )', '%s Donation Orders permanently deleted ( %s )', $total_post, $ids, WC_QD_TXT), $total_post, $ids));
                 break;
             case 'edit':
                 if (isset($_REQUEST['bulk_edit'])) {
                     $done = bulk_edit_posts($_REQUEST);
                     if (is_array($done)) {
                         $done['updated'] = count($done['updated']);
                         $done['skipped'] = count($done['skipped']);
                         $done['locked'] = count($done['locked']);
                         $sendback = add_query_arg($done, $sendback);
                     }
                 }
                 break;
         }
     }
     $sendback = remove_query_arg(array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback);
     wp_redirect($sendback);
     exit;
 }
 function restore_post($path, $blog_id, $post_id)
 {
     $args = $this->query_args();
     $post = get_post($post_id);
     if (!$post || is_wp_error($post)) {
         return new WP_Error('unknown_post', 'Unknown post', 404);
     }
     if (!current_user_can('delete_post', $post->ID)) {
         return new WP_Error('unauthorized', 'User cannot restore trashed posts', 403);
     }
     do_action('wpcom_json_api_objects', 'posts');
     wp_untrash_post($post->ID);
     return $this->get_post_by('ID', $post->ID, $args['context']);
 }
Esempio n. 27
0
 public static function untrash_post($post_id)
 {
     if (get_post_type($post_id) == 'event-recurring') {
         global $wpdb;
         //set a constant so we know this event doesn't need 'saving'
         if (!defined('UNTRASHING_' . $post_id)) {
             define('UNTRASHING_' . $post_id, true);
         }
         $EM_Event = em_get_event($post_id, 'post_id');
         $events_array = EM_Events::get(array('recurrence_id' => $EM_Event->event_id, 'scope' => 'all', 'status' => 'all'));
         foreach ($events_array as $event) {
             /* @var $event EM_Event */
             if ($EM_Event->event_id == $event->recurrence_id) {
                 wp_untrash_post($event->post_id);
             }
         }
     }
 }
function make_sure_calendar_page_published($vcita_widget)
{
    $page_id = vcita_default_if_non($vcita_widget, 'calendar_page_id');
    $page = get_page($page_id);
    if (empty($page)) {
        $page = get_page_by_title('Book Appointment');
        $page_id = $page->ID;
    }
    if (empty($page)) {
        $page_id = add_calendar_page();
    } elseif ($page->{"post_status"} == "trash") {
        wp_untrash_post($page_id);
    } elseif ($page->{"post_status"} != "publish") {
        $page_id = add_calendar_page();
    }
    $vcita_widget['calendar_page_id'] = $page_id;
    $vcita_widget['calendar_page_active'] = 'true';
    update_option(VCITA_WIDGET_KEY, $vcita_widget);
    return $vcita_widget;
}
Esempio n. 29
0
/**
 * Ajax handler for sending a post to the trash.
 *
 * @since 3.1.0
 *
 * @param string $action Action to perform.
 */
function wp_ajax_trash_post($action)
{
    if (empty($action)) {
        $action = 'trash-post';
    }
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    check_ajax_referer("{$action}_{$id}");
    if (!current_user_can('delete_post', $id)) {
        wp_die(-1);
    }
    if (!get_post($id)) {
        wp_die(1);
    }
    if ('trash-post' == $action) {
        $done = wp_trash_post($id);
    } else {
        $done = wp_untrash_post($id);
    }
    if ($done) {
        wp_die(1);
    }
    wp_die(0);
}
 /**
  * Installs TML
  *
  * @since 6.0
  * @access public
  */
 public function install()
 {
     global $wpdb;
     // Current version
     $version = $this->get_option('version', Theme_My_Login::version);
     // Check if legacy page exists
     if ($page_id = $this->get_option('page_id')) {
         $page = get_post($page_id);
     } else {
         $page = get_page_by_title('Login');
     }
     // 4.4 upgrade
     if (version_compare($version, '4.4', '<')) {
         remove_role('denied');
     }
     // 6.0 upgrade
     if (version_compare($version, '6.0', '<')) {
         // Replace shortcode
         if ($page) {
             $page->post_content = str_replace('[theme-my-login-page]', '[theme-my-login]', $page->post_content);
             wp_update_post($page);
         }
     }
     // 6.3 upgrade
     if (version_compare($version, '6.3.3', '<')) {
         // Delete obsolete options
         $this->delete_option('page_id');
         $this->delete_option('show_page');
         $this->delete_option('initial_nag');
         $this->delete_option('permalinks');
         $this->delete_option('flush_rules');
         // Move options to their own rows
         foreach ($this->get_options() as $key => $value) {
             if (in_array($key, array('active_modules'))) {
                 continue;
             }
             if (!is_array($value)) {
                 continue;
             }
             update_option("theme_my_login_{$key}", $value);
             $this->delete_option($key);
         }
         // Maybe create login page?
         if ($page) {
             // Make sure the page is not in the trash
             if ('trash' == $page->post_status) {
                 wp_untrash_post($page->ID);
             }
             update_post_meta($page->ID, '_tml_action', 'login');
         }
     }
     // 6.3.7 upgrade
     if (version_compare($version, '6.3.7', '<')) {
         // Convert TML pages to regular pages
         $wpdb->update($wpdb->posts, array('post_type' => 'page'), array('post_type' => 'tml_page'));
         // Get rid of stale rewrite rules
         flush_rewrite_rules(false);
     }
     // 6.4 upgrade
     if (version_compare($version, '6.4', '<')) {
         // Convert e-mail login option
         if ($this->get_option('email_login')) {
             $this->set_option('login_type', 'both');
         }
         $this->delete_option('email_login');
     }
     // Setup default pages
     foreach (Theme_My_Login::default_pages() as $action => $title) {
         if (!($page_id = Theme_My_Login::get_page_id($action))) {
             $page_id = wp_insert_post(array('post_title' => $title, 'post_name' => $action, 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => '[theme-my-login]', 'comment_status' => 'closed', 'ping_status' => 'closed'));
             update_post_meta($page_id, '_tml_action', $action);
         }
     }
     // Activate modules
     foreach ($this->get_option('active_modules', array()) as $module) {
         if (file_exists(WP_PLUGIN_DIR . '/theme-my-login/modules/' . $module)) {
             include_once WP_PLUGIN_DIR . '/theme-my-login/modules/' . $module;
         }
         do_action('tml_activate_' . $module);
     }
     $this->set_option('version', Theme_My_Login::version);
     $this->save_options();
 }