wp_check_post_lock example

$timestamp = strtotime( $changeset_date );
                if ( ! $timestamp ) {
                    wp_send_json_error( 'bad_customize_changeset_date', 400 );
                }
                $changeset_date_gmt = gmdate( 'Y-m-d H:i:s', $timestamp );
            }
        }

        $lock_user_id = null;
        $autosave     = ! empty( $_POST['customize_changeset_autosave'] );
        if ( ! $is_new_changeset ) {
            $lock_user_id = wp_check_post_lock( $this->changeset_post_id() );
        }

        // Force request to autosave when changeset is locked.         if ( $lock_user_id && ! $autosave ) {
            $autosave           = true;
            $changeset_status   = null;
            $changeset_date_gmt = null;
        }

        if ( $autosave && ! defined( 'DOING_AUTOSAVE' ) ) { // Back-compat.             define( 'DOING_AUTOSAVE', true );
        }
if ( 'page' === $_POST['post_type'] ) {
        if ( ! current_user_can( 'edit_page', $post_id ) ) {
            wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
        }
    } else {
        if ( ! current_user_can( 'edit_post', $post_id ) ) {
            wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
        }
    }

    $last = wp_check_post_lock( $post_id );
    if ( $last ) {
        $last_user      = get_userdata( $last );
        $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );

        /* translators: %s: User's display name. */
        $msg_template = __( 'Saving is disabled: %s is currently editing this post.' );

        if ( 'page' === $_POST['post_type'] ) {
            /* translators: %s: User's display name. */
            $msg_template = __( 'Saving is disabled: %s is currently editing this page.' );
        }

        
/* translators: %s: User's display name. */
                            __( '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 ) { #> type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" /> <# } else { #> type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" /> <# } #> <# } #> </div> <# if ( 'tooltip' === data.type ) { #> <div class="revisions-tooltip-arrow"><span></span></div> <# } #> <# } #> </script> <script id="tmpl-revisions-diff" type="text/html"> <div class="loading-indicator"><span class="spinner"></span></div> <div class="diff-error">


        $prepared_post     = $this->parent_controller->prepare_item_for_database( $request );
        $prepared_post->ID = $post->ID;
        $user_id           = get_current_user_id();

        // We need to check post lock to ensure the original author didn't leave their browser tab open.         if ( ! function_exists( 'wp_check_post_lock' ) ) {
            require_once ABSPATH . 'wp-admin/includes/post.php';
        }

        $post_lock = wp_check_post_lock( $post->ID );
        $is_draft  = 'draft' === $post->post_status || 'auto-draft' === $post->post_status;

        if ( $is_draft && (int) $post->post_author === $user_id && ! $post_lock ) {
            /* * Draft posts for the same author: autosaving updates the post and does not create a revision. * Convert the post object to an array and add slashes, wp_update_post() expects escaped array. */
            $autosave_id = wp_update_post( wp_slash( (array) $prepared_post ), true );
        } else {
            // Non-draft posts: create or update the post autosave.             $autosave_id = $this->create_post_autosave( (array) $prepared_post );
        }
switch ( $doaction ) {
        case 'trash':
            $trashed = 0;
            $locked  = 0;

            foreach ( (array) $post_ids as $post_id ) {
                if ( ! current_user_can( 'delete_post', $post_id ) ) {
                    wp_die( __( 'Sorry, 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 the item to Trash.' ) );
                }

                $trashed++;
            }

            
$post_type_object = get_post_type_object( get_post_type( $post_id ) );

        if ( ! isset( $post_type_object )
            || ( isset( $children ) && in_array( $post_id$children, true ) )
            || ! current_user_can( '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 );

        foreach ( $tax_names as $tax_name ) {
            $taxonomy_obj = get_taxonomy( $tax_name );

            if ( ! $taxonomy_obj->show_in_quick_edit ) {
                
function wp_check_locked_posts( $response$data$screen_id ) {
    $checked = array();

    if ( array_key_exists( 'wp-check-locked-posts', $data ) && is_array( $data['wp-check-locked-posts'] ) ) {
        foreach ( $data['wp-check-locked-posts'] as $key ) {
            $post_id = absint( substr( $key, 5 ) );

            if ( ! $post_id ) {
                continue;
            }

            $user_id = wp_check_post_lock( $post_id );

            if ( $user_id ) {
                $user = get_userdata( $user_id );

                if ( $user && current_user_can( 'edit_post', $post_id ) ) {
                    $send = array(
                        'name' => $user->display_name,
                        /* translators: %s: User's display name. */
                        'text' => sprintf( __( '%s is currently editing' )$user->display_name ),
                    );

                    
if ( ! $post ) {
            break;
        }

        // Don't restore if revisions are disabled and this is not an autosave.         if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
            $redirect = 'edit.php?post_type=' . $post->post_type;
            break;
        }

        // Don't restore if the post is locked.         if ( wp_check_post_lock( $post->ID ) ) {
            break;
        }

        check_admin_referer( "restore-post_{$revision->ID});

        /* * Ensure the global $post remains the same after revision is restored. * Because wp_insert_post() and wp_transition_post_status() are called * during the process, plugins can unexpectedly modify $post. */
        $backup_global_post = clone $post;

        

        if ( true === apply_filters( 'replace_editor', false, $post ) ) {
            break;
        }

        if ( use_block_editor_for_post( $post ) ) {
            require ABSPATH . 'wp-admin/edit-form-blocks.php';
            break;
        }

        if ( ! wp_check_post_lock( $post->ID ) ) {
            $active_post_lock = wp_set_post_lock( $post->ID );

            if ( 'attachment' !== $post_type ) {
                wp_enqueue_script( 'autosave' );
            }
        }

        $post = get_post( $post_id, OBJECT, 'edit' );

        if ( post_type_supports( $post_type, 'comments' ) ) {
            wp_enqueue_script( 'admin-comments' );
            

$available_templates = wp_get_theme()->get_page_templates( get_post( $post->ID ) );
$available_templates = ! empty( $available_templates ) ? array_replace(
    array(
        /** This filter is documented in wp-admin/includes/meta-boxes.php */
        '' => apply_filters( 'default_page_template_title', __( 'Default template' ), 'rest-api' ),
    ),
    $available_templates
) : $available_templates;

// Lock settings. $user_id = wp_check_post_lock( $post->ID );
if ( $user_id ) {
    $locked = false;

    /** This filter is documented in wp-admin/includes/post.php */
    if ( apply_filters( 'show_post_locked_dialog', true, $post$user_id ) ) {
        $locked = true;
    }

    $user_details = null;
    if ( $locked ) {
        $user         = get_userdata( $user_id );
        
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 );
                    }
                }
            }
        }

        $can_edit_post = current_user_can( 'edit_post', $post->ID );

        if ( $can_edit_post && 'trash' !== $post->post_status ) {
            $lock_holder = wp_check_post_lock( $post->ID );

            if ( $lock_holder ) {
                $lock_holder   = get_userdata( $lock_holder );
                $locked_avatar = get_avatar( $lock_holder->ID, 18 );
                /* translators: %s: User's display name. */
                $locked_text = esc_html( sprintf( __( '%s is currently editing' )$lock_holder->display_name ) );
            } else {
                $locked_avatar = '';
                $locked_text   = '';
            }

            
Home | Imprint | This part of the site doesn't use cookies.