本文整理汇总了PHP中wp_delete_post_revision函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_delete_post_revision函数的具体用法?PHP wp_delete_post_revision怎么用?PHP wp_delete_post_revision使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_delete_post_revision函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_custom_values
/**
* Save or update custom values
*
* @param array $values - an associative array of values
* @param string $theme optional - the theme name, defaults to the active the theme
*/
static function update_custom_values($values, $theme = null)
{
if (empty($theme)) {
$theme_data = wp_get_theme();
$theme = $theme_data->get_stylesheet();
}
// Need the current version of the settings
if ($post = self::get_post()) {
$post_id = $post->ID;
} else {
$post_id = false;
}
if (!is_array($values)) {
$values = array();
} else {
foreach ($values as $field => $value) {
//fix the pixels ones
if (strpos($field, "-pixels")) {
$values[str_replace("-pixels", "", $field)] = $value . "px";
unset($values[$field]);
}
}
}
$post_data = array('post_content' => json_encode($values), 'post_name' => $theme, 'post_type' => self::POST_TYPE, 'post_status' => 'publish');
if (empty($post_id)) {
$post_id = wp_insert_post($post_data);
} else {
$post_data['ID'] = $post_id;
wp_update_post($post_data);
// Clear out meta data
$meta_keys = get_post_custom_keys($post_id);
if (count($meta_keys)) {
foreach ($meta_keys as $meta_key) {
delete_post_meta($post_id, $meta_key);
}
}
// Delete revisions past the five most recent
$revisions = wp_get_post_revisions($post_id);
$revisions = array_slice($revisions, 5);
foreach ($revisions as $revision) {
wp_delete_post_revision($revision->ID);
}
}
// clear cache
$cache_key = 'customlessvars_' . $theme . '_current';
delete_transient($cache_key);
// Regenerate and cache
foreach (self::$less_files as $less_file) {
if ($compiled = self::compile_less($less_file, $values)) {
update_post_meta($post_id, $less_file, addslashes($compiled));
}
}
}
示例2: sweep
/**
* Does the sweeping/cleaning up
*
* @since 1.0.0
*
* @access public
* @param string $name
* @return string Processed message
*/
public function sweep($name)
{
global $wpdb;
$message = '';
switch ($name) {
case 'revisions':
$query = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s", 'revision'));
if ($query) {
foreach ($query as $id) {
wp_delete_post_revision(intval($id));
}
$message = sprintf(__('%s Revisions Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
}
break;
case 'auto_drafts':
$query = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status = %s", 'auto-draft'));
if ($query) {
foreach ($query as $id) {
wp_delete_post(intval($id), true);
}
$message = sprintf(__('%s Auto Drafts Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
}
break;
case 'deleted_posts':
$query = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status = %s", 'trash'));
if ($query) {
foreach ($query as $id) {
wp_delete_post($id, true);
}
$message = sprintf(__('%s Deleted Posts Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
}
break;
case 'unapproved_comments':
$query = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_approved = %s", '0'));
if ($query) {
foreach ($query as $id) {
wp_delete_comment(intval($id), true);
}
$message = sprintf(__('%s Unapproved Comments Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
}
break;
case 'spam_comments':
$query = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_approved = %s", 'spam'));
if ($query) {
foreach ($query as $id) {
wp_delete_comment(intval($id), true);
}
$message = sprintf(__('%s Spam Comments Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
}
break;
case 'deleted_comments':
$query = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE (comment_approved = %s OR comment_approved = %s)", 'trash', 'post-trashed'));
if ($query) {
foreach ($query as $id) {
wp_delete_comment(intval($id), true);
}
$message = sprintf(__('%s Trash Comments Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
}
break;
case 'transient_options':
$query = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE(%s)", '%_transient_%'));
if ($query) {
foreach ($query as $option_name) {
if (strpos($option_name, '_site_transient_') !== false) {
delete_site_transient(str_replace('_site_transient_', '', $option_name));
} else {
delete_transient(str_replace('_transient_', '', $option_name));
}
}
$message = sprintf(__('%s Transient Options Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
}
break;
case 'orphan_postmeta':
$query = $wpdb->get_results("SELECT post_id, meta_key FROM {$wpdb->postmeta} WHERE post_id NOT IN (SELECT ID FROM {$wpdb->posts})");
if ($query) {
foreach ($query as $meta) {
$post_id = intval($meta->post_id);
if ($post_id === 0) {
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key));
} else {
delete_post_meta($post_id, $meta->meta_key);
}
}
$message = sprintf(__('%s Orphaned Post Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
}
break;
case 'orphan_commentmeta':
$query = $wpdb->get_results("SELECT comment_id, meta_key FROM {$wpdb->commentmeta} WHERE comment_id NOT IN (SELECT comment_ID FROM {$wpdb->comments})");
if ($query) {
foreach ($query as $meta) {
$comment_id = intval($meta->comment_id);
//.........这里部分代码省略.........
示例3: wp_delete_post
/**
* Trashes or deletes a post or page.
*
* When the post and page is permanently deleted, everything that is tied to it is deleted also.
* This includes comments, post meta fields, and terms associated with the post.
*
* The post or page is moved to trash instead of permanently deleted unless trash is
* disabled, item is already in the trash, or $force_delete is true.
*
* @since 1.0.0
* @uses do_action() on 'delete_post' before deletion unless post type is 'attachment'.
* @uses do_action() on 'deleted_post' after deletion unless post type is 'attachment'.
* @uses wp_delete_attachment() if post type is 'attachment'.
* @uses wp_trash_post() if item should be trashed.
*
* @param int $postid Post ID.
* @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false.
* @return mixed False on failure
*/
function wp_delete_post($postid = 0, $force_delete = false)
{
global $wpdb;
if (!($post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID = %d", $postid)))) {
return $post;
}
if (!$force_delete && ($post->post_type == 'post' || $post->post_type == 'page') && get_post_status($postid) != 'trash' && EMPTY_TRASH_DAYS) {
return wp_trash_post($postid);
}
if ($post->post_type == 'attachment') {
return wp_delete_attachment($postid, $force_delete);
}
do_action('before_delete_post', $postid);
delete_post_meta($postid, '_wp_trash_meta_status');
delete_post_meta($postid, '_wp_trash_meta_time');
wp_delete_object_term_relationships($postid, get_object_taxonomies($post->post_type));
$parent_data = array('post_parent' => $post->post_parent);
$parent_where = array('post_parent' => $postid);
if (is_post_type_hierarchical($post->post_type)) {
// Point children of this page to its parent, also clean the cache of affected children
$children_query = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type);
$children = $wpdb->get_results($children_query);
$wpdb->update($wpdb->posts, $parent_data, $parent_where + array('post_type' => $post->post_type));
}
// Do raw query. wp_get_post_revisions() is filtered
$revision_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_type = 'revision'", $postid));
// Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up.
foreach ($revision_ids as $revision_id) {
wp_delete_post_revision($revision_id);
}
// Point all attachments to this post up one level
$wpdb->update($wpdb->posts, $parent_data, $parent_where + array('post_type' => 'attachment'));
$comment_ids = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID = %d", $postid));
foreach ($comment_ids as $comment_id) {
wp_delete_comment($comment_id, true);
}
$post_meta_ids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d ", $postid));
foreach ($post_meta_ids as $mid) {
delete_metadata_by_mid('post', $mid);
}
do_action('delete_post', $postid);
$wpdb->delete($wpdb->posts, array('ID' => $postid));
do_action('deleted_post', $postid);
clean_post_cache($post);
if (is_post_type_hierarchical($post->post_type) && $children) {
foreach ($children as $child) {
clean_post_cache($child);
}
}
wp_clear_scheduled_hook('publish_future_post', array($postid));
do_action('after_delete_post', $postid);
return $post;
}
示例4: revision_delete_action
/**
* Ajax callback to handle deleting the revision, then redirecting
* back to the post edit page with a confirmation message.
*/
public function revision_delete_action()
{
/**
* Bail if required values unset.
*/
if (!isset($_GET['revision'])) {
return;
}
$revision_id = sanitize_key($_GET['revision']);
/**
* Verify revision ID valud.
*/
if (!($revision = wp_get_post_revision($revision_id))) {
break;
}
/**
* Verify parent post valid.
*/
if (!($post = get_post($revision->post_parent))) {
break;
}
/**
* Verify current user can edit parent post.
*/
if (!current_user_can('edit_post', $post)) {
break;
}
/**
* Verify revisions not disabled and we're not looking at an autosave.
*/
if (!constant('WP_POST_REVISIONS') && !wp_is_post_autosave($revision)) {
break;
}
/**
* Check the nonce.
*/
check_admin_referer("delete-revision_{$post->ID}|{$revision->ID}");
/**
* Every checks out, delete the revision.
*/
wp_delete_post_revision($revision->ID);
wp_redirect(add_query_arg(array('message' => 99, 'revision' => $revision->ID), get_edit_post_link($post->ID, 'url')));
exit;
}
开发者ID:adamsilverstein,项目名称:wp-post-revision-delete-action,代码行数:48,代码来源:wp-post-revision-delete-action.php
示例5: wp_delete_post
/**
* Trash or delete a post or page.
*
* When the post and page is permanently deleted, everything that is tied to
* it is deleted also. This includes comments, post meta fields, and terms
* associated with the post.
*
* The post or page is moved to trash instead of permanently deleted unless
* trash is disabled, item is already in the trash, or $force_delete is true.
*
* @since 1.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
* @see wp_delete_attachment()
* @see wp_trash_post()
*
* @param int $postid Optional. Post ID. Default 0.
* @param bool $force_delete Optional. Whether to bypass trash and force deletion.
* Default false.
* @return array|false|WP_Post False on failure.
*/
function wp_delete_post($postid = 0, $force_delete = false)
{
global $wpdb;
if (!($post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID = %d", $postid)))) {
return $post;
}
if (!$force_delete && ($post->post_type == 'post' || $post->post_type == 'page') && get_post_status($postid) != 'trash' && EMPTY_TRASH_DAYS) {
return wp_trash_post($postid);
}
if ($post->post_type == 'attachment') {
return wp_delete_attachment($postid, $force_delete);
}
/**
* Filter whether a post deletion should take place.
*
* @since 4.4.0
*
* @param bool $delete Whether to go forward with deletion.
* @param WP_Post $post Post object.
* @param bool $force_delete Whether to bypass the trash.
*/
$check = apply_filters('pre_delete_post', null, $post, $force_delete);
if (null !== $check) {
return $check;
}
/**
* Fires before a post is deleted, at the start of wp_delete_post().
*
* @since 3.2.0
*
* @see wp_delete_post()
*
* @param int $postid Post ID.
*/
do_action('before_delete_post', $postid);
delete_post_meta($postid, '_wp_trash_meta_status');
delete_post_meta($postid, '_wp_trash_meta_time');
wp_delete_object_term_relationships($postid, get_object_taxonomies($post->post_type));
$parent_data = array('post_parent' => $post->post_parent);
$parent_where = array('post_parent' => $postid);
if (is_post_type_hierarchical($post->post_type)) {
// Point children of this page to its parent, also clean the cache of affected children.
$children_query = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type);
$children = $wpdb->get_results($children_query);
$wpdb->update($wpdb->posts, $parent_data, $parent_where + array('post_type' => $post->post_type));
}
// Do raw query. wp_get_post_revisions() is filtered.
$revision_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_type = 'revision'", $postid));
// Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up.
foreach ($revision_ids as $revision_id) {
wp_delete_post_revision($revision_id);
}
// Point all attachments to this post up one level.
$wpdb->update($wpdb->posts, $parent_data, $parent_where + array('post_type' => 'attachment'));
wp_defer_comment_counting(true);
$comment_ids = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID = %d", $postid));
foreach ($comment_ids as $comment_id) {
wp_delete_comment($comment_id, true);
}
wp_defer_comment_counting(false);
$post_meta_ids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d ", $postid));
foreach ($post_meta_ids as $mid) {
delete_metadata_by_mid('post', $mid);
}
/**
* Fires immediately before a post is deleted from the database.
*
* @since 1.2.0
*
* @param int $postid Post ID.
*/
do_action('delete_post', $postid);
$result = $wpdb->delete($wpdb->posts, array('ID' => $postid));
if (!$result) {
return false;
}
/**
* Fires immediately after a post is deleted from the database.
*
//.........这里部分代码省略.........
示例6: wp_delete_post
/**
* Trashes or deletes a post or page.
*
* When the post and page is permanently deleted, everything that is tied to it is deleted also.
* This includes comments, post meta fields, and terms associated with the post.
*
* The post or page is moved to trash instead of permanently deleted unless trash is
* disabled, item is already in the trash, or $force_delete is true.
*
* @since 1.0.0
* @uses do_action() on 'delete_post' before deletion unless post type is 'attachment'.
* @uses do_action() on 'deleted_post' after deletion unless post type is 'attachment'.
* @uses wp_delete_attachment() if post type is 'attachment'.
* @uses wp_trash_post() if item should be trashed.
*
* @param int $postid Post ID.
* @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false.
* @return mixed False on failure
*/
function wp_delete_post($postid = 0, $force_delete = false)
{
global $wpdb, $wp_rewrite;
if (!($post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID = %d", $postid)))) {
return $post;
}
if (!$force_delete && ($post->post_type == 'post' || $post->post_type == 'page') && get_post_status($postid) != 'trash' && EMPTY_TRASH_DAYS) {
return wp_trash_post($postid);
}
if ($post->post_type == 'attachment') {
return wp_delete_attachment($postid, $force_delete);
}
do_action('before_delete_post', $postid);
delete_post_meta($postid, '_wp_trash_meta_status');
delete_post_meta($postid, '_wp_trash_meta_time');
wp_delete_object_term_relationships($postid, get_object_taxonomies($post->post_type));
$parent_data = array('post_parent' => $post->post_parent);
$parent_where = array('post_parent' => $postid);
if ('page' == $post->post_type) {
// if the page is defined in option page_on_front or post_for_posts,
// adjust the corresponding options
if (get_option('page_on_front') == $postid) {
update_option('show_on_front', 'posts');
delete_option('page_on_front');
}
if (get_option('page_for_posts') == $postid) {
delete_option('page_for_posts');
}
// Point children of this page to its parent, also clean the cache of affected children
$children_query = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_parent = %d AND post_type='page'", $postid);
$children = $wpdb->get_results($children_query);
$wpdb->update($wpdb->posts, $parent_data, $parent_where + array('post_type' => 'page'));
} else {
unstick_post($postid);
}
// Do raw query. wp_get_post_revisions() is filtered
$revision_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_type = 'revision'", $postid));
// Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up.
foreach ($revision_ids as $revision_id) {
wp_delete_post_revision($revision_id);
}
// Point all attachments to this post up one level
$wpdb->update($wpdb->posts, $parent_data, $parent_where + array('post_type' => 'attachment'));
$comment_ids = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID = %d", $postid));
if (!empty($comment_ids)) {
do_action('delete_comment', $comment_ids);
foreach ($comment_ids as $comment_id) {
wp_delete_comment($comment_id, true);
}
do_action('deleted_comment', $comment_ids);
}
$post_meta_ids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d ", $postid));
if (!empty($post_meta_ids)) {
do_action('delete_postmeta', $post_meta_ids);
$in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'";
$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE meta_id IN({$in_post_meta_ids})");
do_action('deleted_postmeta', $post_meta_ids);
}
do_action('delete_post', $postid);
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->posts} WHERE ID = %d", $postid));
do_action('deleted_post', $postid);
if ('page' == $post->post_type) {
clean_page_cache($postid);
foreach ((array) $children as $child) {
clean_page_cache($child->ID);
}
$wp_rewrite->flush_rules(false);
} else {
clean_post_cache($postid);
}
wp_clear_scheduled_hook('publish_future_post', array($postid));
do_action('after_delete_post', $postid);
return $post;
}
示例7: tdomf_moderation_handler
//.........这里部分代码省略.........
tdomf_set_state_edit('approved', $last_edit[0]->edit_id);
if ($user_id > 0) {
tdomf_trust_user($user_id);
}
}
}
tdomf_log_message('These edits have been approved: ' . implode(", ", $edit_list));
$message .= sprintf(__("Approved contributions on these submissions: %s.", "tdomf"), implode(", ", $post_list));
break;
case 'edit_revert':
$edit_list = array();
$post_list = array();
foreach ($posts as $post) {
$last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
if (!empty($last_edit) && $last_edit[0]->state == 'approved' && $last_edit[0]->revision_id != 0 && $last_edit[0]->current_revision_id != 0) {
$edit_list[] = $last_edit[0]->edit_id;
$post_list[] = $post;
wp_restore_post_revision($last_edit[0]->current_revision_id);
tdomf_set_state_edit('unapproved', $last_edit[0]->edit_id);
}
}
tdomf_log_message('These edits have been reverted: ' . implode(", ", $edit_list));
$message .= sprintf(__("Latest contribution on these submissions have been reverted: %s.", "tdomf"), implode(", ", $post_list));
break;
case 'edit_delete':
$edit_list = array();
$post_list = array();
foreach ($posts as $post) {
$last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
if (!empty($last_edit) && $last_edit[0]->state != 'approved') {
$edit_list[] = $last_edit[0]->edit_id;
$post_list[] = $post;
if ($last_edit[0]->revision_id != 0) {
wp_delete_post_revision($edit->revision_id);
tdomf_log_message("Deleting revision " . $last_edit[0]->revision_id . " on post " . $post);
}
if ($last_edit[0]->current_revision_id != 0) {
wp_delete_post_revision($last_edit[0]->current_revision_id);
tdomf_log_message("Deleting revision " . $last_edit[0]->current_revision_id . " on post " . $post);
}
}
tdomf_delete_edits($edit_list);
}
tdomf_log_message('These edits have been deleted: ' . implode(", ", $edit_list));
$message .= sprintf(__("Latest contribution on these submissions have been deleted: %s.", "tdomf"), implode(", ", $post_list));
break;
case 'edit_spamit':
$edit_list = array();
$post_list = array();
foreach ($posts as $post) {
$last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
if (!empty($last_edit) && $last_edit[0]->state != 'spam') {
$edit_list[] = $last_edit[0]->edit_id;
$post_list[] = $post;
tdomf_spamit_edit($last_edit[0]);
}
}
tdomf_log_message('These edits have been marked as spam: ' . implode(", ", $edit_list));
$message .= sprintf(__("Latest contribution on these submissions have been marked as spam: %s.", "tdomf"), implode(", ", $post_list));
break;
case 'edit_hamit':
$edit_list = array();
$post_list = array();
foreach ($posts as $post) {
$last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
if (!empty($last_edit) && $last_edit[0]->state == 'soam') {
示例8: wp_create_post_autosave
/**
* Creates autosave data for the specified post from $_POST data.
*
* @package WordPress
* @subpackage Post_Revisions
* @since 2.6.0
*
* @param mixed $post_data Associative array containing the post data or int post ID.
* @return mixed The autosave revision ID. WP_Error or 0 on error.
*/
function wp_create_post_autosave($post_data)
{
if (is_numeric($post_data)) {
$post_id = $post_data;
$post_data = $_POST;
} else {
$post_id = (int) $post_data['post_ID'];
}
$post_data = _wp_translate_postdata(true, $post_data);
if (is_wp_error($post_data)) {
return $post_data;
}
$post_author = get_current_user_id();
// Store one autosave per author. If there is already an autosave, overwrite it.
if ($old_autosave = wp_get_post_autosave($post_id, $post_author)) {
$new_autosave = _wp_post_revision_data($post_data, true);
$new_autosave['ID'] = $old_autosave->ID;
$new_autosave['post_author'] = $post_author;
// If the new autosave has the same content as the post, delete the autosave.
$post = get_post($post_id);
$autosave_is_different = false;
foreach (array_intersect(array_keys($new_autosave), array_keys(_wp_post_revision_fields($post))) as $field) {
if (normalize_whitespace($new_autosave[$field]) != normalize_whitespace($post->{$field})) {
$autosave_is_different = true;
break;
}
}
if (!$autosave_is_different) {
wp_delete_post_revision($old_autosave->ID);
return 0;
}
/**
* Fires before an autosave is stored.
*
* @since 4.1.0
*
* @param array $new_autosave Post array - the autosave that is about to be saved.
*/
do_action('wp_creating_autosave', $new_autosave);
return wp_update_post($new_autosave);
}
// _wp_put_post_revision() expects unescaped.
$post_data = wp_unslash($post_data);
// Otherwise create the new autosave as a special post revision
return _wp_put_post_revision($post_data, true);
}
示例9: meta_modal
public function meta_modal()
{
global $post, $post_type, $post_type_object, $current_screen, $wp_meta_modal_sections;
$post_ID = $post->ID;
set_current_screen($post_type);
if (!wp_check_post_lock($post->ID)) {
$active_post_lock = wp_set_post_lock($post->ID);
}
$messages = array();
$messages['post'] = array(0 => '', 1 => sprintf(__('Post updated. <a href="%s">View post</a>', 'wplms-front-end'), esc_url(get_permalink($post_ID))), 2 => __('Custom field updated.'), 3 => __('Custom field deleted.'), 4 => __('Post updated.'), 5 => isset($_GET['revision']) ? sprintf(__('Post restored to revision from %s', 'wplms-front-end'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('Post published. <a href="%s">View post</a>', 'wplms-front-end'), esc_url(get_permalink($post_ID))), 7 => __('Post saved.'), 8 => sprintf(__('Post submitted. <a target="_blank" href="%s">Preview post</a>', 'wplms-front-end'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))), 9 => sprintf(__('Post scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview post</a>', 'wplms-front-end'), date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))), 10 => sprintf(__('Post draft updated. <a target="_blank" href="%s">Preview post</a>', 'wplms-front-end'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))));
$messages['page'] = array(0 => '', 1 => sprintf(__('Page updated. <a href="%s">View page</a>', 'wplms-front-end'), esc_url(get_permalink($post_ID))), 2 => __('Custom field updated.'), 3 => __('Custom field deleted.'), 4 => __('Page updated.'), 5 => isset($_GET['revision']) ? sprintf(__('Page restored to revision from %s'), 'wplms-front-end', wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('Page published. <a href="%s">View page</a>', 'wplms-front-end'), esc_url(get_permalink($post_ID))), 7 => __('Page saved.'), 8 => sprintf(__('Page submitted. <a target="_blank" href="%s">Preview page</a>', 'wplms-front-end'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))), 9 => sprintf(__('Page scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview page</a>', 'wplms-front-end'), date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))), 10 => sprintf(__('Page draft updated. <a target="_blank" href="%s">Preview page</a>', 'wplms-front-end'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))));
$messages['attachment'] = array_fill(1, 10, __('Media attachment updated.', 'wplms-front-end'));
// Hack, for now.
$messages = apply_filters('post_updated_messages', $messages);
$message = false;
if (isset($_GET['message'])) {
$_GET['message'] = absint($_GET['message']);
if (isset($messages[$post_type][$_GET['message']])) {
$message = $messages[$post_type][$_GET['message']];
} elseif (!isset($messages[$post_type]) && isset($messages['post'][$_GET['message']])) {
$message = $messages['post'][$_GET['message']];
}
}
$notice = false;
$form_extra = '';
if ('auto-draft' == $post->post_status) {
if ('edit' == $action) {
$post->post_title = '';
}
$autosave = false;
$form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
} else {
$autosave = wp_get_post_autosave($post_ID);
}
$form_action = 'editpost';
$nonce_action = 'update-post_' . $post_ID;
// Detect if there exists an autosave newer than the post and if that autosave is different than the post
if ($autosave && mysql2date('U', $autosave->post_modified_gmt, false) > mysql2date('U', $post->post_modified_gmt, false)) {
foreach (_wp_post_revision_fields() as $autosave_field => $_autosave_field) {
if (normalize_whitespace($autosave->{$autosave_field}) != normalize_whitespace($post->{$autosave_field})) {
$notice = sprintf(__('There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>', 'wplms-front-end'), get_edit_post_link($autosave->ID));
break;
}
}
// If this autosave isn't different from the current post, begone.
if (!$notice) {
wp_delete_post_revision($autosave->ID);
}
unset($autosave_field, $_autosave_field);
}
$post_type_object = get_post_type_object($post_type);
$this->add_meta_modal_section('submitdiv', __('Publish'), array($this, 'meta_section_publish'), 10, 10);
if (post_type_supports($post_type, 'revisions') && 'auto-draft' !== $post->post_status) {
$revisions = wp_get_post_revisions($post->ID);
$count = count($revisions);
if ($count > 1) {
$this->add_meta_modal_section('revisionsdiv', __('Revisions', 'wplms-front-end') . ' (' . $count . ')', 'post_revisions_meta_box', 30, 50);
}
}
if (current_theme_supports('post-formats') && post_type_supports($post_type, 'post-formats')) {
$this->add_meta_modal_section('formatdiv', _x('Format', 'post format', 'wplms-front-end'), 'post_format_meta_box', 20, 10);
}
foreach (get_object_taxonomies($post) as $tax_name) {
$taxonomy = get_taxonomy($tax_name);
if (!$taxonomy->show_ui || false === $taxonomy->meta_box_cb) {
continue;
}
$label = $taxonomy->labels->name;
if (!is_taxonomy_hierarchical($tax_name)) {
$tax_meta_box_id = 'tagsdiv-' . $tax_name;
} else {
$tax_meta_box_id = $tax_name . 'div';
}
$this->add_meta_modal_section($tax_meta_box_id, $label, $taxonomy->meta_box_cb, 20, 20, array('taxonomy' => $tax_name));
}
if (post_type_supports($post_type, 'page-attributes')) {
$this->add_meta_modal_section('pageparentdiv', 'page' == $post_type ? __('Page Attributes', 'wplms-front-end') : __('Attributes', 'wplms-front-end'), 'page_attributes_meta_box', 10, 10);
}
if (post_type_supports($post_type, 'excerpt')) {
$this->add_meta_modal_section('postexcerpt', __('Excerpt', 'wplms-front-end'), 'post_excerpt_meta_box', 30, 10);
}
if (post_type_supports($post_type, 'trackbacks')) {
$this->add_meta_modal_section('trackbacksdiv', __('Send Trackbacks', 'wplms-front-end'), 'post_trackback_meta_box', 30, 20);
}
if (post_type_supports($post_type, 'custom-fields')) {
$this->add_meta_modal_section('postcustom', __('Custom Fields', 'wplms-front-end'), 'post_custom_meta_box', 30, 30);
}
if (post_type_supports($post_type, 'comments')) {
$this->add_meta_modal_section('commentstatusdiv', __('Discussion', 'wplms-front-end'), 'post_comment_status_meta_box', 30, 40);
}
require_once 'meta-modal-template.php';
unset($GLOBALS['current_screen']);
}
示例10: tdomf_cleanup_spam
function tdomf_cleanup_spam()
{
global $wpdb;
if (!get_option(TDOMF_OPTION_SPAM_AUTO_DELETE)) {
return;
}
// delete edit spam older than a month
$edit_list = '';
$time_diff = tdomf_timestamp_wp_sql(time() - 2592000);
// 1 month in seconds
$edits = tdomf_get_edits(array('state' => 'spam', 'older_than' => $time_diff));
if (count($edits) > 0) {
foreach ($edits as $edit) {
$edit_list[] = $edit->edit_id;
if ($edit->revision_id != 0) {
wp_delete_post_revision($edit->revision_id);
}
if ($edit->current_revision_id != 0) {
wp_delete_post_revision($last_edit[0]->current_revision_id);
}
}
tdomf_delete_edits($edit_list);
tdomf_log_message("Deleting spam edits older than a month: " . implode(",", $edit_list));
}
// delete spam more than a month old
$query = "SELECT ID, post_modified_gmt\n FROM {$wpdb->posts}\n LEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)\n WHERE meta_key = '" . TDOMF_KEY_SPAM . "'";
$spam_posts = $wpdb->get_results($query);
if (count($spam_posts) > 0) {
$list = "";
foreach ($spam_posts as $post) {
// we use to use post_modified_gmt but since 2.6 or 2.7 this is
// no longer set when the post is initially created in draft
//
$post_date_gmt = get_post_meta($post->ID, TDOMF_KEY_SUBMISSION_DATE, true);
if ($post_date_gmt != false) {
$post_date_ts = mysql2date('U', $post_date_gmt);
$diff = time() - $post_date_ts;
if ($diff >= 2952000) {
// 1 month (30 days)
$list .= $post->ID . ", ";
wp_delete_post($post->ID);
}
tdomf_log_message($post->ID . ' ' . $post_data_ts . ' ' . $diff);
} else {
// old way
//
$last_updated = strtotime($post->post_modified_gmt);
$diff = time() - $last_updated;
if ($diff >= 2952000) {
// 1 month (30 days)
$list .= $post->ID . ", ";
wp_delete_post($post->ID);
}
}
}
if ($list != "") {
tdomf_log_message("Deleting spam posts older than a month: {$list}");
}
} else {
#tdomf_log_message("No spam submissions to clean up!",TDOMF_LOG_GOOD);
}
}
示例11: wp_save_post_revision
/**
* Saves an already existing post as a post revision.
*
* Typically used immediately after post updates.
* Adds a copy of the current post as a revision, so latest revision always matches current post
*
* @since 2.6.0
*
* @uses _wp_put_post_revision()
*
* @param int $post_id The ID of the post to save as a revision.
* @return mixed Null or 0 if error, new revision ID, if success.
*/
function wp_save_post_revision($post_id)
{
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!($post = get_post($post_id))) {
return;
}
if (!post_type_supports($post->post_type, 'revisions')) {
return;
}
if ('auto-draft' == $post->post_status) {
return;
}
if (!wp_revisions_enabled($post)) {
return;
}
// Compare the proposed update with the last stored revision verifying that
// they are different, unless a plugin tells us to always save regardless.
// If no previous revisions, save one
if ($revisions = wp_get_post_revisions($post_id)) {
// grab the last revision, but not an autosave
foreach ($revisions as $revision) {
if (false !== strpos($revision->post_name, "{$revision->post_parent}-revision")) {
$last_revision = $revision;
break;
}
}
if (isset($last_revision) && apply_filters('wp_save_post_revision_check_for_changes', true, $last_revision, $post)) {
$post_has_changed = false;
foreach (array_keys(_wp_post_revision_fields()) as $field) {
if (normalize_whitespace($post->{$field}) != normalize_whitespace($last_revision->{$field})) {
$post_has_changed = true;
break;
}
}
// Check whether revisioned meta fields have changed.
foreach (_wp_post_revision_meta_keys() as $meta_key) {
if (get_post_meta($post->ID, $meta_key, true) != get_post_meta($last_revision->ID, $meta_key, true)) {
$post_has_changed = true;
break;
}
}
// Check whether the post format has changed
if (get_post_format($post->ID) != get_post_meta($last_revision->ID, '_revision_post_format', true)) {
$post_has_changed = true;
}
//don't save revision if post unchanged
if (!$post_has_changed) {
return;
}
}
}
$return = _wp_put_post_revision($post);
$revisions_to_keep = wp_revisions_to_keep($post);
if ($revisions_to_keep < 0) {
return $return;
}
// all revisions and autosaves
$revisions = wp_get_post_revisions($post_id, array('order' => 'ASC'));
$delete = count($revisions) - $revisions_to_keep;
if ($delete < 1) {
return $return;
}
$revisions = array_slice($revisions, 0, $delete);
for ($i = 0; isset($revisions[$i]); $i++) {
if (false !== strpos($revisions[$i]->post_name, 'autosave')) {
continue;
}
wp_delete_post_revision($revisions[$i]->ID);
}
return $return;
}
示例12: delete_revisions
static function delete_revisions()
{
//Add nonce check
check_admin_referer('revision-control-delete');
if (empty($_POST['revisions'])) {
$x = new WP_AJAX_Response();
$x->add(array('data' => -1));
$x->send();
return;
}
$revisions = stripslashes($_POST['revisions']);
$revisions = explode(',', $revisions);
$revisions = array_map('intval', $revisions);
$deleted = array();
foreach ($revisions as $revision_id) {
$revision = get_post($revision_id);
if (wp_is_post_revision($revision) && !wp_is_post_autosave($revision) && current_user_can('delete_post', $revision->post_parent)) {
if (wp_delete_post_revision($revision_id)) {
$deleted[] = $revision_id;
}
}
}
$x = new WP_AJAX_Response();
$x->add(array('data' => 1, 'supplemental' => array('revisions' => implode(',', $deleted))));
$x->send();
}
示例13: front_end_editor_shortcodes
public function front_end_editor_shortcodes($attr)
{
global $wp, $current_screen, $wp_meta_boxes, $post;
$is_bac = $this->is_bac();
$output = '';
/**
* Start Checking the Conditional needed to render editor
* Define Variable needed for use in whole function
*
*
*/
if (!is_user_logged_in()) {
if ($is_bac === true) {
wp_safe_redirect(bon_accounts()->my_account_url());
} else {
if (is_woocommerce_activated()) {
wp_safe_redirect(get_permalink(wc_get_page_id('myaccount')));
}
}
} else {
if (!$this->is_edit()) {
return;
}
$object_id = $this->get_post_to_edit();
if (!$object_id) {
bon_error_notice()->add('invalid_post', __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?'), 'error');
return;
}
$post_object = get_post($this->get_post_to_edit());
setup_postdata($GLOBALS['post'] =& $post_object);
$current_post_type = get_post_type($object_id);
if (!$post_object) {
bon_error_notice()->add('invalid_post', __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?'), 'error');
return;
}
if (!current_user_can('edit_post', $object_id)) {
bon_error_notice()->add('permission_denied', __('You are not allowed to edit this item.'), 'error');
return;
}
if (!post_type_supports($post_object->post_type, 'front-end-editor')) {
bon_error_notice()->add('unsupported_posttype', __('The post type assigned is not supporting front end post', 'bon'), 'error');
}
$form_extra = '';
$notice = false;
if ($post_object->post_status === 'auto-draft') {
$post_object->post_title = '';
$post_object->comment_status = get_option('default_comment_status');
$post_object->ping_status = get_option('default_ping_status');
$autosave = false;
$form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
} else {
$autosave = wp_get_post_autosave($object_id);
}
$form_action = 'editpost';
$nonce_action = 'update-post_' . $object_id;
$form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr($object_id) . "' />";
$content_css = array(trailingslashit(get_stylesheet_directory_uri()) . 'assets/css/editor-styles.css', trailingslashit(includes_url()) . 'css/dashicons.min.css', trailingslashit(includes_url()) . 'js/mediaelement/mediaelementplayer.min.css', trailingslashit(includes_url()) . 'js/mediaelement/wp-mediaelement.css', trailingslashit(includes_url()) . 'js/tinymce/skins/wordpress/wp-content.css', trailingslashit(includes_url()) . 'css/editor.min.css');
$content_css = join(',', array_map('esc_url', array_unique($content_css)));
$args = array('post_ID' => $object_id, 'post_type' => $current_post_type, 'user_ID' => get_current_user_id(), 'post' => $post_object, 'post_type_object' => get_post_type_object($current_post_type), 'autosave' => $autosave, 'form_extra' => $form_extra, 'form_action' => $form_action, 'nonce_action' => $nonce_action, 'editor_settings' => array('dfw' => true, 'drag_drop_upload' => true, 'tabfocus_elements' => 'insert-media-button, save-post', 'editor_height' => 360, 'tinymce' => array('resize' => false, 'add_unload_trigger' => false, 'content_css' => $content_css)));
ob_start();
bon_get_template('posts/editor.php', $args);
$args['editor'] = ob_get_clean();
unset($args['editor_settings']);
set_current_screen($current_post_type);
$current_screen->set_parentage('edit.php?post_type=' . $current_post_type);
if (!wp_check_post_lock($object_id)) {
$args['active_post_lock'] = wp_set_post_lock($object_id);
}
$messages = $this->get_wp_messages($post_object);
$message = false;
if (isset($_GET['message'])) {
$_GET['message'] = absint($_GET['message']);
if (isset($messages[$current_post_type][$_GET['message']])) {
$message = $messages[$current_post_type][$_GET['message']];
} elseif (!isset($messages[$current_post_type]) && isset($messages['post'][$_GET['message']])) {
$message = $messages['post'][$_GET['message']];
}
}
// Detect if there exists an autosave newer than the post and if that autosave is different than the post
if ($autosave && mysql2date('U', $autosave->post_modified_gmt, false) > mysql2date('U', $post_object->post_modified_gmt, false)) {
foreach (_wp_post_revision_fields() as $autosave_field => $_autosave_field) {
if (normalize_whitespace($autosave->{$autosave_field}) != normalize_whitespace($post_object->{$autosave_field})) {
bon_error_notice()->add('autosave_exists', sprintf(__('There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>'), get_edit_post_link($autosave->ID)), 'notice');
break;
}
}
// If this autosave isn't different from the current post, begone.
if (!$notice) {
wp_delete_post_revision($autosave->ID);
}
unset($autosave_field, $_autosave_field);
}
bon_get_template('posts/post.php', $args);
unset($GLOBALS['current_screen']);
wp_reset_postdata();
}
}
示例14: wp_get_post_autosave
$autosave = wp_get_post_autosave($post_ID);
}
$form_action = 'editpost';
$nonce_action = 'update-post_' . $post_ID;
$form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr($post_ID) . "' />";
// Detect if there exists an autosave newer than the post and if that autosave is different than the post
if ($autosave && mysql2date('U', $autosave->post_modified_gmt, false) > mysql2date('U', $post->post_modified_gmt, false)) {
foreach (_wp_post_revision_fields($post) as $autosave_field => $_autosave_field) {
if (normalize_whitespace($autosave->{$autosave_field}) != normalize_whitespace($post->{$autosave_field})) {
$notice = sprintf(__('There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>'), get_edit_post_link($autosave->ID));
break;
}
}
// If this autosave isn't different from the current post, begone.
if (!$notice) {
wp_delete_post_revision($autosave->ID);
}
unset($autosave_field, $_autosave_field);
}
$post_type_object = get_post_type_object($post_type);
// All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action).
require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';
$publish_callback_args = null;
if (post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status) {
$revisions = wp_get_post_revisions($post_ID);
// We should aim to show the revisions meta box only when there are revisions.
if (count($revisions) > 1) {
reset($revisions);
// Reset pointer for key()
$publish_callback_args = array('revisions_count' => count($revisions), 'revision_id' => key($revisions));
add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core');
示例15: bdr_page
//.........这里部分代码省略.........
?>
<input type="hidden" name="bdr_rev_no" value="<?php
echo $bdr_res_no;
?>
" />
<input class="button-primary" type="submit" name="bdr_del_act" value="<?php
printf(__('Yes , I would like to delete them! (A Total Of %s)', 'bdr'), $bdr_res_no);
?>
" />
<input class="button" type="submit" name="goback" value="<?php
_e('No , I prefer to keep them!', 'bdr');
?>
" />
</form>
<?php
} else {
?>
<div class="updated bdr_no_rev">
<p>
<?php
_e('Great! You have no revisions now!', 'bdr');
?>
</p>
</div>
<?php
}
} elseif (isset($_POST['bdr_del_act']) && check_admin_referer(plugin_basename(__FILE__))) {
$bdr_ngg_fix = bdr_get_ngg_fix();
$bdr_revisions = $wpdb->get_results("SELECT `ID` AS revision_id\n\t\t\t\t\tFROM ({$wpdb->posts})\n\t\t\t\t\tWHERE `post_type` = 'revision'\n\t\t\t\t\tORDER BY `ID` DESC");
if (is_array($bdr_ngg_fix)) {
remove_action($bdr_ngg_fix['tag'], array($bdr_ngg_fix['class'], $bdr_ngg_fix['method']), $bdr_ngg_fix['priority']);
}
foreach ($bdr_revisions as $bdr_revision) {
wp_delete_post_revision($bdr_revision->revision_id);
}
if (is_array($bdr_ngg_fix)) {
add_action($bdr_ngg_fix['tag'], array($bdr_ngg_fix['class'], $bdr_ngg_fix['method']), $bdr_ngg_fix['priority']);
}
$bdr_del_no = $_POST['bdr_rev_no'];
$bdr_rev_new = $bdr_rev_no + $bdr_del_no;
update_option('bdr_rev_no', $bdr_rev_new);
?>
<div class="updated bdr_updated">
<p>
<strong><?php
printf(__('Deleted %s revisions!', 'bdr'), sprintf('<span>%s</span>', $bdr_del_no));
?>
</strong>
</p>
</div>
<script type="text/javascript">
document.getElementById( 'bdr_revs_no' ).innerHTML = <?php
echo $bdr_rev_new;
?>
;
</script>
<?php
} elseif (isset($_POST['bdr_maintain_mysql']) && check_admin_referer(plugin_basename(__FILE__))) {
if (isset($_POST['bdr_operation']) && $_POST['bdr_operation'] == 'OPTIMIZE') {
$bdr_operation = 'OPTIMIZE';
} else {
$bdr_operation = 'CHECK';
}
$bdr_tables = $wpdb->get_results('SHOW TABLES IN ' . DB_NAME);
$bdr_query = "{$bdr_operation} TABLE";
$bdr_tables_in_db_name = 'Tables_in_' . DB_NAME;