Exemplo n.º 1
1
function trashposts()
{
    $today = date('Ymd', current_time('timestamp', 0));
    $args = array('posts_per_page' => -1, 'post_type' => 'post');
    $the_query = new WP_Query($args);
    // The Loop
    if ($the_query->have_posts()) {
        while ($the_query->have_posts()) {
            $the_query->the_post();
            if (get_field('date')) {
                // if it has a start date i.e a single show/event
                if (get_field('end_date')) {
                    // if it has multiday shows
                    if (get_field('end_date') < $today) {
                        // and last one has past
                        wp_trash_post($post->ID);
                    }
                } else {
                    // if it has no end date ie single day show
                    if (get_field('date') < $today) {
                        // if it's past
                        wp_trash_post($post->ID);
                    }
                }
            }
        }
    }
    /* Restore original Post Data */
    wp_reset_postdata();
}
Exemplo n.º 2
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);
 }
Exemplo n.º 3
1
function motopressCERemoveTemporaryPost()
{
    require_once dirname(__FILE__) . '/../verifyNonce.php';
    require_once dirname(__FILE__) . '/../settings.php';
    require_once dirname(__FILE__) . '/../access.php';
    require_once dirname(__FILE__) . '/../Requirements.php';
    require_once dirname(__FILE__) . '/../functions.php';
    require_once dirname(__FILE__) . '/../getLanguageDict.php';
    require_once dirname(__FILE__) . '/ThemeFix.php';
    global $motopressCESettings;
    $motopressCELang = motopressCEGetLanguageDict();
    $errors = array();
    $post_id = $_POST['post_id'];
    $post = get_post($post_id);
    if (!is_null($post)) {
        $delete = wp_trash_post($post_id);
        new MPCEThemeFix(MPCEThemeFix::ACTIVATE);
        if ($delete === false) {
            $errors[] = $motopressCELang->CERemoveTemporaryPostError;
        }
    }
    if (!empty($errors)) {
        if ($motopressCESettings['debug']) {
            print_r($errors);
        } else {
            motopressCESetError($motopressCELang->CERemoveTemporaryPostError);
        }
    }
    exit;
}
Exemplo n.º 4
1
 public function unlinkTranslationFor($objectId, $objectKind)
 {
     // Trash the translations' WP_Post first
     global $wpdb;
     $this->logger->logQueryStart();
     $locales = Strata::i18n()->getLocales();
     $app = Strata::app();
     foreach ($locales as $locale) {
         if ($objectKind === "WP_Post" && $locale->isTranslationOfPost($objectId)) {
             $translation = $locale->getTranslatedPost($objectId);
             if (!is_null($translation)) {
                 wp_trash_post($translation->ID);
             }
         } elseif ($objectKind === "Term" && $locale->hasTermTranslation($objectId)) {
             $translation = $locale->getTranslatedTerm($objectId);
             if (!is_null($translation)) {
                 wp_delete_term($translation->term_id);
             }
         }
     }
     // Then delete all the polyglot references
     // to that original post.
     $result = $wpdb->delete($wpdb->prefix . 'polyglot', array("translation_of" => $objectId, "obj_kind" => $objectKind));
     $this->logger->logQueryCompletion($wpdb->last_query);
     return $result;
 }
 function delete_discount($force_delete = false)
 {
     if ($force_delete) {
         wp_delete_post($this->id);
     } else {
         wp_trash_post($this->id);
     }
 }
Exemplo n.º 6
0
 public function idx_ajax_delete_dynamic_page()
 {
     if ($_POST['wrapper_page_id']) {
         wp_delete_post($_POST['wrapper_page_id'], true);
         wp_trash_post($_POST['wrapper_page_id']);
     }
     die;
 }
Exemplo n.º 7
0
 function cron()
 {
     global $wpdb;
     $result = $wpdb->get_results($wpdb->prepare('SELECT post_id FROM ' . $wpdb->postmeta . ' WHERE meta_key = "_expiration_date" AND meta_value < %s', time()));
     foreach ($result as $a) {
         wp_trash_post($a->post_id);
     }
 }
 public function trash_translation($trans_id)
 {
     if (WPML_WordPress_Actions::is_bulk_trash($trans_id)) {
         // Do nothing as the translation is part of the bulk trash.
     } else {
         wp_trash_post($trans_id);
     }
 }
 function delete_template($force_delete = false)
 {
     if ($force_delete) {
         wp_delete_post($this->id);
     } else {
         wp_trash_post($this->id);
     }
 }
 function delete_ticket_instance($force_delete = true)
 {
     if ($force_delete) {
         wp_delete_post($this->id);
     } else {
         wp_trash_post($this->id);
     }
 }
 function delete_api_key($force_delete = true)
 {
     if ($force_delete) {
         wp_delete_post($this->id);
     } else {
         wp_trash_post($this->id);
     }
 }
Exemplo n.º 12
0
 function test_trashed_post()
 {
     $post_id = $this->factory->post->create(array('post_title' => 'test post'));
     SP_API()->post('_refresh');
     $this->assertEquals(array('test-post'), $this->search_and_get_field(array('query' => 'test post')));
     wp_trash_post($post_id);
     SP_API()->post('_refresh');
     $this->assertEmpty($this->search_and_get_field(array('query' => 'test post')));
 }
 /**
  * @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);
 }
Exemplo n.º 14
0
function stage_post_trash_callback()
{
    global $wpdb;
    // this is how you get access to the database
    $id = intval($_POST['post_id']);
    wp_trash_post($id);
    echo 'successfully deleted ' . $id;
    die;
    // this is required to return a proper result
}
 private function apply_age_limit(WP_Post $post)
 {
     $this->meta->set_post_id($post->ID);
     if ($this->meta->get_cron_id() == $this->cron_id) {
         $post_date = strtotime($this->meta->get_post_date());
         if ($post_date < $this->age_limit) {
             wp_trash_post($post->ID);
         }
     }
 }
 public function trash()
 {
     if (empty($this->id)) {
         return;
     }
     if (!EMPTY_TRASH_DAYS) {
         return $this->delete();
     }
     $post = wp_trash_post($this->id);
     return (bool) $post;
 }
Exemplo n.º 17
0
 public function delete()
 {
     if (!$this->c->exists()) {
         return false;
     }
     $deleted = wp_trash_post($this->c->get_id());
     if ($deleted) {
         $this->c->set_id(0);
     }
     return (bool) $deleted;
 }
 /**
  * Handles actions on job dashboard
  */
 public function job_dashboard_handler()
 {
     if (!empty($_REQUEST['action']) && !empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'job_manager_my_job_actions')) {
         $action = sanitize_title($_REQUEST['action']);
         $job_id = absint($_REQUEST['job_id']);
         try {
             // Get Job
             $job = get_post($job_id);
             // Check ownership
             if (!job_manager_user_can_edit_job($job_id)) {
                 throw new Exception(__('Invalid ID', 'wp-job-manager'));
             }
             switch ($action) {
                 case 'mark_filled':
                     // Check status
                     if ($job->_filled == 1) {
                         throw new Exception(__('This position has already been filled', 'wp-job-manager'));
                     }
                     // Update
                     update_post_meta($job_id, '_filled', 1);
                     // Message
                     $this->job_dashboard_message = '<div class="job-manager-message">' . sprintf(__('%s has been filled', 'wp-job-manager'), $job->post_title) . '</div>';
                     break;
                 case 'mark_not_filled':
                     // Check status
                     if ($job->_filled != 1) {
                         throw new Exception(__('This position is not filled', 'wp-job-manager'));
                     }
                     // Update
                     update_post_meta($job_id, '_filled', 0);
                     // Message
                     $this->job_dashboard_message = '<div class="job-manager-message">' . sprintf(__('%s has been marked as not filled', 'wp-job-manager'), $job->post_title) . '</div>';
                     break;
                 case 'delete':
                     // Trash it
                     wp_trash_post($job_id);
                     // Message
                     $this->job_dashboard_message = '<div class="job-manager-message">' . sprintf(__('%s has been deleted', 'wp-job-manager'), $job->post_title) . '</div>';
                     break;
                 case 'relist':
                     // redirect to post page
                     wp_redirect(add_query_arg(array('job_id' => absint($job_id)), job_manager_get_permalink('submit_job_form')));
                     break;
                 default:
                     do_action('job_manager_job_dashboard_do_action_' . $action);
                     break;
             }
             do_action('job_manager_my_job_do_action', $action, $job_id);
         } catch (Exception $e) {
             $this->job_dashboard_message = '<div class="job-manager-error">' . $e->getMessage() . '</div>';
         }
     }
 }
 function delete_template($force_delete = false)
 {
     if ($force_delete) {
         if (get_post_type($this->id) == 'certificates') {
             wp_delete_post($this->id);
         }
     } else {
         if (get_post_type($this->id) == 'certificates') {
             wp_trash_post($this->id);
         }
     }
 }
Exemplo n.º 20
0
 public function test_submitting_comment_to_trashed_post_returns_error()
 {
     $error = 'comment_on_trash';
     $this->assertSame(0, did_action($error));
     $post = self::factory()->post->create_and_get();
     wp_trash_post($post);
     $data = array('comment_post_ID' => $post->ID);
     $comment = wp_handle_comment_submission($data);
     $this->assertSame(1, did_action($error));
     $this->assertWPError($comment);
     $this->assertSame($error, $comment->get_error_code());
 }
Exemplo n.º 21
0
 public static function idx_uninstall()
 {
     $page_id = get_option('idx_broker_dynamic_wrapper_page_id');
     if ($page_id) {
         wp_delete_post($page_id, true);
         wp_trash_post($page_id);
     }
     //clear transients made by the plugin
     eval('$idx_api = \\IDX\\Idx_Api;');
     eval('$idx_pages = new \\IDX\\Idx_Pages();');
     $idx_api->idx_clean_transients();
     $idx_pages->delete_all_idx_pages();
 }
Exemplo n.º 22
0
function delete_post_type_callback()
{
    // Check the nonce
    $nonce = $_REQUEST['nonce'];
    if (!wp_verify_nonce($nonce, 'wp_rest')) {
        echo 'Security check failed. Please try again.';
        wp_die();
    }
    $post_id = (int) $_REQUEST['post_id'];
    $trash = wp_trash_post($post_id);
    echo $trash ? '1' : '0';
    wp_die();
    // this is required to terminate immediately and return a proper response
}
Exemplo n.º 23
0
/**
 * Trash menu items when remove post type erm_menu
 *
 * @since 1.0
 */
function erm_trash_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_trash_post($id);
    }
}
Exemplo n.º 24
0
function sui_delete_user_images($images_to_delete)
{
    $images_deleted = 0;
    foreach ($images_to_delete as $user_image) {
        if (isset($_POST['sui_image_delete_id_' . $user_image]) && wp_verify_nonce($_POST['sui_image_delete_id_' . $user_image], 'sui_image_delete_' . $user_image)) {
            if ($post_thumbnail_id = get_post_thumbnail_id($user_image)) {
                wp_delete_attachment($post_thumbnail_id);
            }
            wp_trash_post($user_image);
            $images_deleted++;
        }
    }
    return $images_deleted;
}
Exemplo n.º 25
0
 /**
  * Check if we can add a trashed product to the cart.
  */
 public function test_add_to_cart_trashed()
 {
     // Create dummy product
     $product = WC_Helper_Product::create_simple_product();
     // Trash product
     wp_trash_post($product->id);
     // Refetch product, to be sure
     $product = wc_get_product($product->id);
     // Add product to cart
     $this->assertFalse(WC()->cart->add_to_cart($product->id, 1));
     // Clean up the cart
     WC()->cart->empty_cart();
     // Clean up product
     WC_Helper_Product::delete_product($product->id);
 }
Exemplo n.º 26
0
 function delete_event($force_delete = false)
 {
     if ($force_delete) {
         wp_delete_post($this->id);
     } else {
         wp_trash_post($this->id);
     }
     //delete event ticket types
     $args = array('post_type' => 'tc_tickets', 'meta_key' => 'event_name', 'meta_value' => $this->id);
     $ticket_types = get_posts($args);
     foreach ($ticket_types as $ticket_type) {
         $ticket_type_instance = new TC_Ticket($ticket_type->ID);
         $ticket_type_instance->delete_ticket();
     }
 }
 function delete_order($force_delete = true, $id = false)
 {
     $id = $id ? $id : $this->id;
     if ($force_delete) {
         wp_delete_post($id);
     } else {
         wp_trash_post($id);
     }
     //Delete associated ticket instances
     $args = array('post_type' => 'tc_tickets_instances', 'post_status' => 'any', 'post_parent' => $id);
     $ticket_instances = get_posts($args);
     foreach ($ticket_instances as $ticket_instance) {
         $ticket_instance_instance = new TC_Ticket_Instance($ticket_instance->ID);
         $ticket_instance_instance->delete_ticket_instance($force_delete);
     }
 }
Exemplo n.º 28
0
 /**
  * @group bp_activity_catch_transition_post_type_status
  * @group activity_tracking
  */
 public function test_bp_activity_catch_transition_post_type_status_publish_trash()
 {
     $bp = buddypress();
     register_post_type('foo', array('label' => 'foo', 'public' => true, 'supports' => array('buddypress-activity')));
     $post_id = $this->factory->post->create(array('post_status' => 'publish', 'post_type' => 'foo'));
     $post = get_post($post_id);
     // 'new' => 'publish'
     $this->assertTrue($this->activity_exists_for_post($post_id, 'new_foo'), 'Published post type should have activity');
     wp_trash_post($post->ID);
     // 'publish' => 'publish' (password protected)
     $this->assertFalse($this->activity_exists_for_post($post_id, 'new_foo'), 'Unpublished post type should not have activity');
     _unregister_post_type('foo');
     // Reset globals
     unset($bp->activity->actions->activity->new_foo);
     $bp->activity->track = array();
 }
 /**
  * Handles actions on job dashboard
  */
 public function job_dashboard_handler()
 {
     if (!empty($_REQUEST['action']) && !empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'job_manager_my_job_actions')) {
         $action = sanitize_title($_REQUEST['action']);
         $job_id = absint($_REQUEST['job_id']);
         try {
             // Get Job
             $job = get_post($job_id);
             // Check ownership
             if ($job->post_author != get_current_user_id()) {
                 throw new Exception(__('Invalid Job ID', 'wp-job-manager'));
             }
             switch ($action) {
                 case 'mark_filled':
                     // Check status
                     if ($job->_filled == 1) {
                         throw new Exception(__('This job is already filled', 'wp-job-manager'));
                     }
                     // Update
                     update_post_meta($job_id, '_filled', 1);
                     // Message
                     $this->job_dashboard_message = '<div class="job-manager-message">' . sprintf(__('%s has been filled', 'wp-job-manager'), $job->post_title) . '</div>';
                     break;
                 case 'mark_not_filled':
                     // Check status
                     if ($job->_filled != 1) {
                         throw new Exception(__('This job is already not filled', 'wp-job-manager'));
                     }
                     // Update
                     update_post_meta($job_id, '_filled', 0);
                     // Message
                     $this->job_dashboard_message = '<div class="job-manager-message">' . sprintf(__('%s has been marked as not filled', 'wp-job-manager'), $job->post_title) . '</div>';
                     break;
                 case 'delete':
                     // Trash it
                     wp_trash_post($job_id);
                     // Message
                     $this->job_dashboard_message = '<div class="job-manager-message">' . sprintf(__('%s has been deleted', 'wp-job-manager'), $job->post_title) . '</div>';
                     break;
             }
             do_action('job_manager_my_job_do_action', $action, $job_id);
         } catch (Exception $e) {
             $this->job_dashboard_message = '<div class="job-manager-error">' . $e->getMessage() . '</div>';
         }
     }
 }
 function test_push()
 {
     RemoteSyncPlugin::instance()->install();
     $postId = wp_insert_post(array('post_content' => 'content', 'post_name' => 'the-slug', 'post_title' => "Hello Post"));
     update_option("rs_remote_site_url", "http://example.com/");
     Curl::mockResult(array());
     Curl::mockResult(array());
     Curl::mockResult(array());
     $op = new RemoteSyncOperations();
     $op->push();
     wp_trash_post($postId);
     Curl::initMock();
     Curl::mockResult(array(array("slug" => 'the-slug', 'revision' => "hello")));
     Curl::mockResult(array());
     Curl::mockResult(array());
     $op = new RemoteSyncOperations();
     $op->push();
 }