本文整理汇总了PHP中wp_check_post_lock函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_check_post_lock函数的具体用法?PHP wp_check_post_lock怎么用?PHP wp_check_post_lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_check_post_lock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_autosave_locked_post
/**
* Test autosaving a locked post
* @return void
*/
public function test_autosave_locked_post()
{
// Lock the post to another user
wp_set_current_user(self::$editor_id);
wp_set_post_lock(self::$post_id);
wp_set_current_user(self::$admin_id);
// Ensure post is locked
$this->assertEquals(self::$editor_id, wp_check_post_lock(self::$post_id));
// Set up the $_POST request
$md5 = md5(uniqid());
$_POST = array('action' => 'heartbeat', '_nonce' => wp_create_nonce('heartbeat-nonce'), 'data' => array('wp_autosave' => array('post_id' => self::$post_id, '_wpnonce' => wp_create_nonce('update-post_' . self::$post_id), 'post_content' => self::$post->post_content . PHP_EOL . $md5, 'post_type' => 'post')));
// Make the request
try {
$this->_handleAjax('heartbeat');
} catch (WPAjaxDieContinueException $e) {
unset($e);
}
$response = json_decode($this->_last_response, true);
// Ensure everything is correct
$this->assertNotEmpty($response['wp_autosave']);
$this->assertTrue($response['wp_autosave']['success']);
// Check that the original post was NOT edited
$post = get_post(self::$post_id);
$this->assertFalse(strpos($post->post_content, $md5));
// Check if the autosave post was created
$autosave = wp_get_post_autosave(self::$post_id, get_current_user_id());
$this->assertNotEmpty($autosave);
$this->assertGreaterThanOrEqual(0, strpos($autosave->post_content, $md5));
}
示例2: handle_locking
protected function handle_locking($post_id)
{
$last_user = wp_check_post_lock($post_id);
if ($last_user) {
$message = __('Error: %s is currently editing this.', 'front-end-editor');
$message = sprintf($message, esc_html(get_userdata($last_user)->display_name));
throw new Exception($message);
}
wp_set_post_lock($post_id);
}
示例3: test_postLock
public function test_postLock()
{
$this->user_own_post = $this->factory->user->create(['role' => 'administrator']);
$this->user_editor = $this->factory->user->create(['role' => 'administrator']);
wp_set_current_user($this->user_own_post);
$post = $this->factory->post->create_and_get();
$data = ['elementor_post_lock' => ['post_ID' => $post->ID]];
$response = apply_filters('heartbeat_received', [], $data, '');
// Switch to other user
wp_set_current_user($this->user_editor);
$this->assertEquals($this->user_own_post, wp_check_post_lock($post->ID));
$response = apply_filters('heartbeat_received', [], $data, '');
$this->assertArrayHasKey('locked_user', $response);
}
示例4: init
/**
* Initializes the builder interface.
*
* @since 1.0
* @return void
*/
public static function init()
{
// Enable editing if the builder is active.
if (FLBuilderModel::is_builder_active() && !defined('DOING_AJAX')) {
// Tell W3TC not to minify while the builder is active.
define('DONOTMINIFY', true);
// Tell Autoptimize not to minify while the builder is active.
add_filter('autoptimize_filter_noptimize', '__return_true');
// Remove 3rd party editor buttons.
remove_all_actions('media_buttons', 999999);
remove_all_actions('media_buttons_context', 999999);
// Get the post.
require_once ABSPATH . 'wp-admin/includes/post.php';
$post_id = FLBuilderModel::get_post_id();
// Check to see if the post is locked.
if (wp_check_post_lock($post_id) !== false) {
header('Location: ' . admin_url('/post.php?post=' . $post_id . '&action=edit'));
} else {
FLBuilderModel::enable_editing();
}
}
}
示例5: edit
private function edit()
{
global $title, $post_ID, $p, $post, $post_referredby;
$title = __('Edit Page');
$page_ID = $post_ID = $p = (int) $_GET['post'];
$post = $this->get_page($post_ID);
if (current_user_can('edit_page', $page_ID)) {
if ($last = wp_check_post_lock($post->ID)) {
$last_user = get_userdata($last);
$last_user_name = $last_user ? $last_user->display_name : __('Somebody');
$message = sprintf(__('Warning: %s is currently editing this page'), esc_html($last_user_name));
$message = '<p><font color="red">' . $message . '</font></p>';
add_action('admin_notices', create_function('', "echo '{$message}';"));
} else {
wp_set_post_lock($post->ID);
}
} else {
$this->base->ks_die(__('You are not allowed to edit this page.'));
// exit;
}
$post_referredby = $this->sendback;
include dirname(__FILE__) . '/edit-page-form.php';
}
示例6: callback
function callback($path = '', $blog_id = 0, $post_id = 0)
{
$blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
if (is_wp_error($blog_id)) {
return $blog_id;
}
$args = $this->query_args();
$input = $this->input(false);
if (!is_array($input) || !$input) {
return new WP_Error('invalid_input', 'Invalid request input', 400);
}
$post = get_post($post_id);
if (!$post || is_wp_error($post)) {
return new WP_Error('unknown_post', 'Unknown post', 404);
}
if (!current_user_can('edit_post', $post->ID)) {
return new WP_Error('unauthorized', 'User cannot edit post', 403);
}
$post_data = array('post_ID' => $post_id, 'post_title' => $input['title'], 'post_content' => $input['content'], 'post_excerpt' => $input['excerpt']);
$preview_url = add_query_arg('preview', 'true', get_permalink($post->ID));
if (!wp_check_post_lock($post->ID) && get_current_user_id() == $post->post_author && ('auto-draft' == $post->post_status || 'draft' == $post->post_status)) {
// Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked
$auto_ID = edit_post(wp_slash($post_data));
} else {
// Non drafts or other users drafts are not overwritten. The autosave is stored in a special post revision for each user.
$auto_ID = wp_create_post_autosave(wp_slash($post_data));
$nonce = wp_create_nonce('post_preview_' . $post->ID);
$preview_url = add_query_arg(array('preview_id' => $auto_ID, 'preview_nonce' => $nonce), $preview_url);
}
$updated_post = get_post($auto_ID);
if ($updated_post && $updated_post->ID && $updated_post->post_modified) {
return array('ID' => $auto_ID, 'post_ID' => $post->ID, 'modified' => $this->format_date($updated_post->post_modified), 'preview_URL' => $preview_url);
} else {
return new WP_Error('autosave_error', __('Autosave encountered an unexpected error', 'jetpack'), 500);
}
}
示例7: redirect_post
}
redirect_post($post_id);
// Send user on their way while we keep working
exit;
case 'trash':
check_admin_referer('trash-post_' . $post_id);
if (!$post) {
wp_die(__('The item you are trying to move to the Trash no longer exists.'));
}
if (!$post_type_object) {
wp_die(__('Unknown post type.'));
}
if (!current_user_can('delete_post', $post_id)) {
wp_die(__('You are not allowed to move this item to the Trash.'));
}
if ($user_id = wp_check_post_lock($post_id)) {
$user = get_userdata($user_id);
wp_die(sprintf(__('You cannot move this item to the Trash. %s is currently editing.'), $user->display_name));
}
if (!wp_trash_post($post_id)) {
wp_die(__('Error in moving to Trash.'));
}
wp_redirect(add_query_arg(array('trashed' => 1, 'ids' => $post_id), $sendback));
exit;
case 'untrash':
check_admin_referer('untrash-post_' . $post_id);
if (!$post) {
wp_die(__('The item you are trying to restore from the Trash no longer exists.'));
}
if (!$post_type_object) {
wp_die(__('Unknown post type.'));
示例8: bulk_edit_posts
/**
* Process the post data for the bulk editing of posts.
*
* Updates all bulk edited posts/pages, adding (but not removing) tags and
* categories. Skips pages when they would be their own parent or child.
*
* @since 2.7.0
*
* @param array $post_data Optional, the array of post data to process if not provided will use $_POST superglobal.
* @return array
*/
function bulk_edit_posts($post_data = null)
{
global $wpdb;
if (empty($post_data)) {
$post_data =& $_POST;
}
if (isset($post_data['post_type'])) {
$ptype = get_post_type_object($post_data['post_type']);
} else {
$ptype = get_post_type_object('post');
}
if (!current_user_can($ptype->cap->edit_posts)) {
if ('page' == $ptype->name) {
wp_die(__('You are not allowed to edit pages.'));
} else {
wp_die(__('You are not allowed to edit posts.'));
}
}
if (-1 == $post_data['_status']) {
$post_data['post_status'] = null;
unset($post_data['post_status']);
} else {
$post_data['post_status'] = $post_data['_status'];
}
unset($post_data['_status']);
$post_IDs = array_map('intval', (array) $post_data['post']);
$reset = array('post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tax_input', 'post_category', 'sticky');
foreach ($reset as $field) {
if (isset($post_data[$field]) && ('' == $post_data[$field] || -1 == $post_data[$field])) {
unset($post_data[$field]);
}
}
if (isset($post_data['post_category'])) {
if (is_array($post_data['post_category']) && !empty($post_data['post_category'])) {
$new_cats = array_map('absint', $post_data['post_category']);
} else {
unset($post_data['post_category']);
}
}
$tax_input = array();
if (isset($post_data['tax_input'])) {
foreach ($post_data['tax_input'] as $tax_name => $terms) {
if (empty($terms)) {
continue;
}
if (is_taxonomy_hierarchical($tax_name)) {
$tax_input[$tax_name] = array_map('absint', $terms);
} else {
$comma = _x(',', 'tag delimiter');
if (',' !== $comma) {
$terms = str_replace($comma, ',', $terms);
}
$tax_input[$tax_name] = explode(',', trim($terms, " \n\t\r\v,"));
}
}
}
if (isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent'])) {
$pages = $wpdb->get_results("SELECT ID, post_parent FROM {$wpdb->posts} WHERE post_type = 'page'");
$children = array();
for ($i = 0; $i < 50 && $parent > 0; $i++) {
$children[] = $parent;
foreach ($pages as $page) {
if ($page->ID == $parent) {
$parent = $page->post_parent;
break;
}
}
}
}
if (isset($post_data['post_format'])) {
if ('0' == $post_data['post_format']) {
$post_data['post_format'] = false;
} elseif (!current_theme_supports('post-formats', $post_data['post_format'])) {
unset($post_data['post_format']);
}
}
$updated = $skipped = $locked = array();
foreach ($post_IDs as $post_ID) {
$post_type_object = get_post_type_object(get_post_type($post_ID));
if (!isset($post_type_object) || isset($children) && in_array($post_ID, $children) || !current_user_can($post_type_object->cap->edit_post, $post_ID)) {
$skipped[] = $post_ID;
continue;
}
if (wp_check_post_lock($post_ID)) {
$locked[] = $post_ID;
continue;
}
$post = get_post($post_ID);
$tax_names = get_object_taxonomies($post);
//.........这里部分代码省略.........
示例9: wp_print_revision_templates
/**
* Print JavaScript templates required for the revisions experience.
*
* @since 4.1.0
*
* @global WP_Post $post The global `$post` object.
*/
function wp_print_revision_templates()
{
global $post;
?>
<script id="tmpl-revisions-frame" type="text/html">
<div class="revisions-control-frame"></div>
<div class="revisions-diff-frame"></div>
</script>
<script id="tmpl-revisions-buttons" type="text/html">
<div class="revisions-previous">
<input class="button" type="button" value="<?php
echo esc_attr_x('Previous', 'Button label for a previous revision');
?>
" />
</div>
<div class="revisions-next">
<input class="button" type="button" value="<?php
echo esc_attr_x('Next', 'Button label for a next revision');
?>
" />
</div>
</script>
<script id="tmpl-revisions-checkbox" type="text/html">
<div class="revision-toggle-compare-mode">
<label>
<input type="checkbox" class="compare-two-revisions"
<#
if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) {
#> checked="checked"<#
}
#>
/>
<?php
esc_attr_e('Compare any two revisions');
?>
</label>
</div>
</script>
<script id="tmpl-revisions-meta" type="text/html">
<# if ( ! _.isUndefined( data.attributes ) ) { #>
<div class="diff-title">
<# if ( 'from' === data.type ) { #>
<strong><?php
_ex('From:', 'Followed by post revision info');
?>
</strong>
<# } else if ( 'to' === data.type ) { #>
<strong><?php
_ex('To:', 'Followed by post revision info');
?>
</strong>
<# } #>
<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
{{{ data.attributes.author.avatar }}}
<div class="author-info">
<# if ( data.attributes.autosave ) { #>
<span class="byline"><?php
printf(__('Autosave by %s'), '<span class="author-name">{{ data.attributes.author.name }}</span>');
?>
</span>
<# } else if ( data.attributes.current ) { #>
<span class="byline"><?php
printf(__('Current Revision by %s'), '<span class="author-name">{{ data.attributes.author.name }}</span>');
?>
</span>
<# } else { #>
<span class="byline"><?php
printf(__('Revision by %s'), '<span class="author-name">{{ data.attributes.author.name }}</span>');
?>
</span>
<# } #>
<span class="time-ago">{{ data.attributes.timeAgo }}</span>
<span class="date">({{ data.attributes.dateShort }})</span>
</div>
<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
<input <?php
if (wp_check_post_lock($post->ID)) {
?>
disabled="disabled"
<?php
} else {
?>
<# if ( data.attributes.current ) { #>
disabled="disabled"
<# } #>
<?php
}
?>
<# if ( data.attributes.autosave ) { #>
//.........这里部分代码省略.........
示例10: bulk_edit_posts
/**
* {@internal Missing Short Description}}
*
* Updates all bulk edited posts/pages, adding (but not removing) tags and
* categories. Skips pages when they would be their own parent or child.
*
* @since unknown
*
* @return array
*/
function bulk_edit_posts($post_data = null)
{
global $wpdb;
if (empty($post_data)) {
$post_data =& $_POST;
}
if (isset($post_data['post_type']) && 'page' == $post_data['post_type']) {
if (!current_user_can('edit_pages')) {
wp_die(__('You are not allowed to edit pages.'));
}
} else {
if (!current_user_can('edit_posts')) {
wp_die(__('You are not allowed to edit posts.'));
}
}
$post_IDs = array_map('intval', (array) $post_data['post']);
$reset = array('post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tags_input', 'post_category', 'sticky');
foreach ($reset as $field) {
if (isset($post_data[$field]) && ('' == $post_data[$field] || -1 == $post_data[$field])) {
unset($post_data[$field]);
}
}
if (isset($post_data['post_category'])) {
if (is_array($post_data['post_category']) && !empty($post_data['post_category'])) {
$new_cats = array_map(absint, $post_data['post_category']);
} else {
unset($post_data['post_category']);
}
}
if (isset($post_data['tags_input'])) {
$new_tags = preg_replace('/\\s*,\\s*/', ',', rtrim(trim($post_data['tags_input']), ' ,'));
$new_tags = explode(',', $new_tags);
}
if (isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent'])) {
$pages = $wpdb->get_results("SELECT ID, post_parent FROM {$wpdb->posts} WHERE post_type = 'page'");
$children = array();
for ($i = 0; $i < 50 && $parent > 0; $i++) {
$children[] = $parent;
foreach ($pages as $page) {
if ($page->ID == $parent) {
$parent = $page->post_parent;
break;
}
}
}
}
$updated = $skipped = $locked = array();
foreach ($post_IDs as $post_ID) {
if (isset($children) && in_array($post_ID, $children)) {
$skipped[] = $post_ID;
continue;
}
if (wp_check_post_lock($post_ID)) {
$locked[] = $post_ID;
continue;
}
if (isset($new_cats)) {
$cats = (array) wp_get_post_categories($post_ID);
$post_data['post_category'] = array_unique(array_merge($cats, $new_cats));
}
if (isset($new_tags)) {
$tags = wp_get_post_tags($post_ID, array('fields' => 'names'));
$post_data['tags_input'] = array_unique(array_merge($tags, $new_tags));
}
$post_data['ID'] = $post_ID;
$updated[] = wp_update_post($post_data);
if (current_user_can('edit_others_posts') && isset($post_data['sticky'])) {
if ('sticky' == $post_data['sticky']) {
stick_post($post_ID);
} else {
unstick_post($post_ID);
}
}
}
return array('updated' => $updated, 'skipped' => $skipped, 'locked' => $locked);
}
示例11: single_row
function single_row($post, $level = 0)
{
global $mode;
static $alternate;
$global_post = get_post();
$GLOBALS['post'] = $post;
setup_postdata($post);
$edit_link = get_edit_post_link($post->ID);
$title = _draft_or_post_title();
$post_type_object = get_post_type_object($post->post_type);
$can_edit_post = current_user_can('edit_post', $post->ID);
$alternate = 'alternate' == $alternate ? '' : 'alternate';
$classes = $alternate . ' iedit author-' . (get_current_user_id() == $post->post_author ? 'self' : 'other');
$lock_holder = wp_check_post_lock($post->ID);
if ($lock_holder) {
$classes .= ' wp-locked';
$lock_holder = get_userdata($lock_holder);
}
if ($post->post_parent) {
$count = count(get_post_ancestors($post->ID));
$classes .= ' level-' . $count;
} else {
$classes .= ' level-0';
}
?>
<tr id="post-<?php
echo $post->ID;
?>
" class="<?php
echo implode(' ', get_post_class($classes, $post->ID));
?>
">
<?php
list($columns, $hidden) = $this->get_column_info();
foreach ($columns as $column_name => $column_display_name) {
$class = "class=\"{$column_name} column-{$column_name}\"";
$style = '';
if (in_array($column_name, $hidden)) {
$style = ' style="display:none;"';
}
$attributes = "{$class}{$style}";
switch ($column_name) {
case 'cb':
?>
<th scope="row" class="check-column">
<label class="screen-reader-text" for="cb-select-<?php
the_ID();
?>
"><?php
printf(__('Select %s'), $title);
?>
</label>
<input id="cb-select-<?php
the_ID();
?>
" type="checkbox" name="select_posts[]" value="<?php
the_ID();
?>
" data-post_id="<?php
the_ID();
?>
" data-post_type="<?php
echo $post->post_type;
?>
" />
<?php
if ($can_edit_post) {
?>
<div class="locked-indicator"></div>
<?php
}
?>
</th>
<?php
break;
case 'title':
$attributes = 'class="post-title page-title column-title"' . $style;
if ($this->hierarchical_display) {
if (0 == $level && (int) $post->post_parent > 0) {
//sent level 0 by accident, by default, or because we don't know the actual level
$find_main_page = (int) $post->post_parent;
while ($find_main_page > 0) {
$parent = get_post($find_main_page);
if (is_null($parent)) {
break;
}
$level++;
$find_main_page = (int) $parent->post_parent;
if (!isset($parent_name)) {
/** This filter is documented in wp-includes/post-template.php */
$parent_name = apply_filters('the_title', $parent->post_title, $parent->ID);
}
}
}
}
$pad = str_repeat('— ', $level);
echo "<td {$attributes}><strong>";
// post format filtering
if ($format = get_post_format($post->ID)) {
$label = get_post_format_string($format);
//.........这里部分代码省略.........
示例12: wp_die
if (empty($post->ID)) {
wp_die(__("You attempted to edit a page that doesn't exist. Perhaps it was deleted?"));
}
if ('page' != $post->post_type) {
wp_redirect(get_edit_post_link($post_ID, 'url'));
exit;
}
wp_enqueue_script('page');
if (user_can_richedit()) {
wp_enqueue_script('editor');
}
add_thickbox();
wp_enqueue_script('media-upload');
wp_enqueue_script('word-count');
if (current_user_can('edit_page', $page_ID)) {
if ($last = wp_check_post_lock($post->ID)) {
$last_user = get_userdata($last);
$last_user_name = $last_user ? $last_user->display_name : __('Somebody');
$message = sprintf(__('Warning: %s is currently editing this page'), wp_specialchars($last_user_name));
$message = str_replace("'", "\\'", "<div class='error'><p>{$message}</p></div>");
add_action('admin_notices', create_function('', "echo '{$message}';"));
} else {
wp_set_post_lock($post->ID);
wp_enqueue_script('autosave');
}
}
require_once 'admin-header.php';
if (!current_user_can('edit_page', $page_ID)) {
die(__('You are not allowed to edit this page.'));
}
include 'edit-page-form.php';
示例13: wp_refresh_post_lock
/**
* Check lock status on the New/Edit Post screen and refresh the lock
*
* @since 3.6.0
*
* @param array $response The Heartbeat response.
* @param array $data The $_POST data sent.
* @param string $screen_id The screen id.
* @return array The Heartbeat response.
*/
function wp_refresh_post_lock($response, $data, $screen_id)
{
if (array_key_exists('wp-refresh-post-lock', $data)) {
$received = $data['wp-refresh-post-lock'];
$send = array();
if (!($post_id = absint($received['post_id']))) {
return $response;
}
if (!current_user_can('edit_post', $post_id)) {
return $response;
}
if (($user_id = wp_check_post_lock($post_id)) && ($user = get_userdata($user_id))) {
$error = array('text' => sprintf(__('%s has taken over and is currently editing.'), $user->display_name));
if ($avatar = get_avatar($user->ID, 64)) {
if (preg_match("|src='([^']+)'|", $avatar, $matches)) {
$error['avatar_src'] = $matches[1];
}
}
$send['lock_error'] = $error;
} else {
if ($new_lock = wp_set_post_lock($post_id)) {
$send['new_lock'] = implode(':', $new_lock);
}
}
$response['wp-refresh-post-lock'] = $send;
}
return $response;
}
示例14: explode
$post_ids = explode(',', $_REQUEST['ids']);
} elseif (!empty($_REQUEST['post'])) {
$post_ids = array_map('intval', $_REQUEST['post']);
}
if (!isset($post_ids)) {
wp_redirect($sendback);
exit;
}
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++;
}
$sendback = add_query_arg(array('trashed' => $trashed, 'ids' => join(',', $post_ids), 'locked' => $locked), $sendback);
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.'));
示例15: body_class
function body_class($classes)
{
global $post;
$classes[] = 'fee fee-off';
require_once ABSPATH . '/wp-admin/includes/post.php';
if (wp_check_post_lock($post->ID)) {
$classes[] = 'fee-locked';
}
return $classes;
}