is_editable( $post_id ) ) { return $failed; } if ( null !== $this->page_builders->name_of( $post_id ) ) { return $failed; } $content = $post->post_content; $rewritten = $this->content_rewriter->apply( $edit, $content ); if ( $rewritten === $content ) { return $failed; } $this->write( $post_id, $rewritten ); $saved_content = get_post_field( self::CONTENT_FIELD, $post_id, self::RAW_CONTEXT ); if ( $saved_content === $content ) { return $failed; } $this->post_link_sync->sync( $post_id ); return new JournalEntry( $link_id, $post_id, $content ); } public function restore( JournalEntry $entry ): void { if ( null === $entry->content_before_fix ) { return; } $this->write( $entry->post_id, $entry->content_before_fix ); $this->post_link_sync->sync( $entry->post_id ); } private function is_editable( int $post_id ): bool { require_once ABSPATH . 'wp-admin/includes/post.php'; return current_user_can( self::EDIT_CAPABILITY, $post_id ) && false === wp_check_post_lock( $post_id ); } private function write( int $post_id, string $content ): void { wp_save_post_revision( $post_id ); wp_update_post( array( 'ID' => $post_id, self::CONTENT_FIELD => wp_slash( $content ), ) ); } }