/** * If any trashed posts have a given slug, add a suffix. * * Store its desired (i.e. current) slug so it can try to reclaim it * if the post is untrashed. * * For internal use. * * @since 4.5.0 * * @param string $post_name Slug. * @param string $post__not_in Post ID that should be ignored. */ function wp_add_trashed_suffix_to_post_name_for_trashed_posts($post_name, $post_ID = 0) { $trashed_posts_with_desired_slug = get_posts(array('name' => $post_name, 'post_status' => 'trash', 'post_type' => 'any', 'nopaging' => true, 'post__not_in' => array($post_ID))); if (!empty($trashed_posts_with_desired_slug)) { foreach ($trashed_posts_with_desired_slug as $_post) { wp_add_trashed_suffix_to_post_name_for_post($_post); } } }
/** * Set a job post to the "completed" status * * `wp_trash_post()` calls `wp_insert_post()`, which can't be used before `init` due to capabilities checks */ private function mark_job_post_completed($job_post_id, $flush_cache = true) { // If called before `init`, we need to modify directly because post types aren't registered earlier if (did_action('init')) { wp_trash_post($job_post_id); } else { global $wpdb; $wpdb->update($wpdb->posts, array('post_status' => self::POST_STATUS_COMPLETED), array('ID' => $job_post_id)); wp_add_trashed_suffix_to_post_name_for_post($job_post_id); $this->posts_to_clean[] = $job_post_id; } // Delete internal cache // Should only be skipped when deleting duplicates, as they are excluded from the cache if ($flush_cache) { wp_cache_delete(self::CACHE_KEY); } return true; }