Esempio n. 1
0
/**
 * Restores a post or page from the Trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post' before undeletion
 * @uses do_action() on 'untrashed_post' after undeletion
 *
 * @param int $post_id Post ID.
 * @return mixed False on failure
 */
function wp_untrash_post($post_id = 0)
{
    if (!($post = wp_get_single_post($post_id, ARRAY_A))) {
        return $post;
    }
    if ($post['post_status'] != 'trash') {
        return false;
    }
    do_action('untrash_post', $post_id);
    $post_status = get_post_meta($post_id, '_wp_trash_meta_status', true);
    $post['post_status'] = $post_status;
    delete_post_meta($post_id, '_wp_trash_meta_status');
    delete_post_meta($post_id, '_wp_trash_meta_time');
    wp_insert_post($post);
    wp_untrash_post_comments($post_id);
    do_action('untrashed_post', $post_id);
    return $post;
}
 public function untrashed_post_comments($post_id)
 {
     wp_untrash_post_comments($post_id);
 }
Esempio n. 3
0
/**
 * Restore a post or page from the Trash.
 *
 * @since 2.9.0
 *
 * @param int $post_id Optional. Post ID. Default is ID of the global $post.
 * @return WP_Post|false WP_Post object. False on failure.
 */
function wp_untrash_post($post_id = 0)
{
    if (!($post = get_post($post_id, ARRAY_A))) {
        return $post;
    }
    if ($post['post_status'] != 'trash') {
        return false;
    }
    /**
     * Fires before a post is restored from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post', $post_id);
    $post_status = get_post_meta($post_id, '_wp_trash_meta_status', true);
    $post['post_status'] = $post_status;
    delete_post_meta($post_id, '_wp_trash_meta_status');
    delete_post_meta($post_id, '_wp_trash_meta_time');
    wp_insert_post(wp_slash($post));
    wp_untrash_post_comments($post_id);
    /**
     * Fires after a post is restored from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post', $post_id);
    return $post;
}
Esempio n. 4
0
 function process_bulk_action()
 {
     global $edd_options;
     $ids = isset($_GET['vendor']) ? $_GET['vendor'] : false;
     if (empty($ids)) {
         return;
     }
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $current_action = $_GET['action'];
     $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
     $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
     foreach ($ids as $id) {
         if ('approve_vendor' === $current_action) {
             if ($id < 2) {
                 break;
             }
             if (user_can($id, 'fes_is_admin') || user_can($id, 'frontend_vendor')) {
                 break;
             }
             if (!user_can($id, 'pending_vendor')) {
                 break;
             }
             $user = new WP_User($id);
             $user->remove_role('pending_vendor');
             $user->add_role('frontend_vendor');
             $subject = apply_filters('fes_application_approved_message_subj', __('Application Approved', 'edd_fes'), 0);
             $message = EDD_FES()->helper->get_option('fes-vendor-app-approved-email', '');
             $type = "user";
             $args['permissions'] = 'fes-vendor-app-approved-email-toggle';
             EDD_FES()->emails->send_email($user->user_email, $from_name, $from_email, $subject, $message, $type, $id, $args);
             do_action('fes_approve_vendor_admin', $id);
             if (isset($_GET['redirect']) && $_GET['redirect'] == '2') {
                 wp_redirect(admin_url('admin.php?page=fes-vendors&vendor=' . $id . '&action=edit&approved=2'));
                 exit;
             }
         }
         if ('revoke_vendor' === $current_action) {
             if ($id < 2) {
                 break;
             }
             if (!(user_can($id, 'fes_is_admin') || user_can($id, 'frontend_vendor'))) {
                 break;
             }
             $user = new WP_User($id);
             $user->remove_role('frontend_vendor');
             $user->remove_cap('fes_is_admin');
             $user->add_role('subscriber');
             // remove all their posts
             $args = array('post_type' => 'download', 'author' => $id, 'posts_per_page' => -1, 'fields' => 'ids', 'post_status' => 'any');
             $query = new WP_Query($args);
             foreach ($query->posts as $id) {
                 wp_delete_post($id, false);
             }
             $subject = apply_filters('fes_application_revoked_message_subj', __('Application Revoked', 'edd_fes'), 0);
             $message = EDD_FES()->helper->get_option('fes-vendor-app-revoked-email', '');
             EDD_FES()->emails->send_email($user->user_email, $from_name, $from_email, $subject, $message, "user", $id, array('fes-vendor-app-revoked-email-toggle'));
             do_action('fes_revoke_vendor_admin', $id);
         }
         if ('decline_vendor' === $current_action) {
             if ($id < 2) {
                 break;
             }
             if (user_can($id, 'fes_is_admin') || user_can($id, 'frontend_vendor')) {
                 break;
             }
             if (!user_can($id, 'pending_vendor')) {
                 break;
             }
             $user = new WP_User($id);
             $user->remove_role('pending_vendor');
             $subject = apply_filters('fes_application_declined_message_subj', __('Application Declined', 'edd_fes'), 0);
             $message = EDD_FES()->helper->get_option('fes-vendor-app-declined-email', '');
             EDD_FES()->emails->send_email($user->user_email, $from_name, $from_email, $subject, $message, "user", $id, array('fes-vendor-app-declined-email-toggle'));
             do_action('fes_decline_vendor_admin', $id);
         }
         if ('suspend_vendor' === $current_action) {
             if ($id < 2) {
                 break;
             }
             if (user_can($id, 'pending_vendor')) {
                 break;
             }
             if (user_can($id, 'suspended_vendor')) {
                 break;
             }
             $user = new WP_User($id);
             $user->remove_role('frontend_vendor');
             $user->add_role('suspended_vendor');
             // remove all their posts
             $args = array('post_type' => 'download', 'author' => $id, 'posts_per_page' => -1, 'fields' => 'ids', 'post_status' => 'any');
             $query = new WP_Query($args);
             foreach ($query->posts as $download) {
                 update_post_meta($download, 'fes_previous_status', get_post_status($download));
                 // Make sure products are never entirely deleted when suspending a vendor
                 if (defined('EMPTY_TRASH_DAYS') && !EMPTY_TRASH_DAYS) {
                     wp_update_post(array('ID' => $download, 'post_status' => 'draft'));
                 } else {
                     wp_trash_post($download);
                 }
             }
             $subject = apply_filters('fes_vendor_suspended_message_subj', __('Suspended', 'edd_fes'), 0);
             $message = EDD_FES()->helper->get_option('fes-vendor-suspended-email', '');
             EDD_FES()->emails->send_email($user->user_email, $from_name, $from_email, $subject, $message, 'user', $id, array('fes-vendor-suspended-email-toggle'));
             do_action('fes_vendor_suspended_admin', $id);
             if (isset($_GET['redirect']) && $_GET['redirect'] == '2') {
                 wp_redirect(admin_url('admin.php?page=fes-vendors&vendor=' . $id . '&action=edit&approved=2'));
                 exit;
             }
         }
         if ('unsuspend_vendor' === $current_action) {
             if ($id < 2) {
                 break;
             }
             if (user_can($id, 'pending_vendor')) {
                 break;
             }
             if (user_can($id, 'frontend_vendor')) {
                 break;
             }
             $user = new WP_User($id);
             $user->add_role('frontend_vendor');
             $user->remove_role('suspended_vendor');
             // remove all their posts
             $args = array('post_type' => 'download', 'author' => $id, 'posts_per_page' => -1, 'fields' => 'ids', 'post_status' => array('pending', 'trash'));
             $query = new WP_Query($args);
             foreach ($query->posts as $download) {
                 $status = get_post_meta($download, 'fes_previous_status', true);
                 if (!$status) {
                     $status = 'pending';
                 }
                 wp_update_post(array('ID' => $download, 'post_status' => $status));
                 wp_untrash_post_comments($download);
             }
             $subject = apply_filters('fes_vendor_unsuspended_message_subj', __('Unsuspended', 'edd_fes'), 0);
             $message = EDD_FES()->helper->get_option('fes-vendor-unsuspended-email', '');
             EDD_FES()->emails->send_email($user->user_email, $from_name, $from_email, $subject, $message, "user", $id, array('fes-vendor-unsuspended-email-toggle'));
             do_action('fes_vendor_unsuspended_admin', $id);
             if (isset($_GET['redirect']) && $_GET['redirect'] == '2') {
                 wp_redirect(admin_url('admin.php?page=fes-vendors&vendor=' . $id . '&action=edit&approved=2'));
                 exit;
             }
         }
     }
 }