Skip to content

Latest commit

 

History

History
1444 lines (761 loc) · 25.5 KB

data-core-editor.md

File metadata and controls

1444 lines (761 loc) · 25.5 KB

The Post Editor’s Data

Namespace: core/editor.

Selectors

canInsertBlockType

Related

  • canInsertBlockType in core/block-editor store.

canUserUseUnfilteredHTML

Returns whether or not the user has the unfiltered_html capability.

Parameters

  • state Object: Editor state.

Returns

  • boolean: Whether the user can or can't post unfiltered HTML.

didPostSaveRequestFail

Returns true if a previous post save was attempted but failed, or false otherwise.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether the post save failed.

didPostSaveRequestSucceed

Returns true if a previous post save was attempted successfully, or false otherwise.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether the post was saved successfully.

getActivePostLock

Returns the active post lock.

Parameters

  • state Object: Global application state.

Returns

  • Object: The lock object.

getAdjacentBlockClientId

Related

  • getAdjacentBlockClientId in core/block-editor store.

getAutosaveAttribute

Deprecated since 5.6. Callers should use the getAutosave( postType, postId, userId ) selector from the '@wordpress/core-data' package and access properties on the returned autosave object using getPostRawValue.

Returns an attribute value of the current autosave revision for a post, or null if there is no autosave for the post.

Parameters

  • state Object: Global application state.
  • attributeName string: Autosave attribute name.

Returns

  • *: Autosave attribute value.

getBlock

Related

  • getBlock in core/block-editor store.

getBlockAttributes

Related

  • getBlockAttributes in core/block-editor store.

getBlockCount

Related

  • getBlockCount in core/block-editor store.

getBlockHierarchyRootClientId

Related

  • getBlockHierarchyRootClientId in core/block-editor store.

getBlockIndex

Related

  • getBlockIndex in core/block-editor store.

getBlockInsertionPoint

Related

  • getBlockInsertionPoint in core/block-editor store.

getBlockListSettings

Related

  • getBlockListSettings in core/block-editor store.

getBlockMode

Related

  • getBlockMode in core/block-editor store.

getBlockName

Related

  • getBlockName in core/block-editor store.

getBlockOrder

Related

  • getBlockOrder in core/block-editor store.

getBlockRootClientId

Related

  • getBlockRootClientId in core/block-editor store.

getBlocks

Related

  • getBlocks in core/block-editor store.

getBlocksByClientId

Related

  • getBlocksByClientId in core/block-editor store.

getBlockSelectionEnd

Related

  • getBlockSelectionEnd in core/block-editor store.

getBlockSelectionStart

Related

  • getBlockSelectionStart in core/block-editor store.

getClientIdsOfDescendants

Related

  • getClientIdsOfDescendants in core/block-editor store.

getClientIdsWithDescendants

Related

  • getClientIdsWithDescendants in core/block-editor store.

getCurrentPost

Returns the post currently being edited in its last known saved state, not including unsaved edits. Returns an object containing relevant default post values if the post has not yet been saved.

Parameters

  • state Object: Global application state.

Returns

  • Object: Post object.

getCurrentPostAttribute

Returns an attribute value of the saved post.

Parameters

  • state Object: Global application state.
  • attributeName string: Post attribute name.

Returns

  • *: Post attribute value.

getCurrentPostId

Returns the ID of the post currently being edited, or null if the post has not yet been saved.

Parameters

  • state Object: Global application state.

Returns

  • ?number: ID of current post.

getCurrentPostLastRevisionId

Returns the last revision ID of the post currently being edited, or null if the post has no revisions.

Parameters

  • state Object: Global application state.

Returns

  • ?number: ID of the last revision.

getCurrentPostRevisionsCount

Returns the number of revisions of the post currently being edited.

Parameters

  • state Object: Global application state.

Returns

  • number: Number of revisions.

getCurrentPostType

Returns the post type of the post currently being edited.

Parameters

  • state Object: Global application state.

Returns

  • string: Post type.

getEditedPostAttribute

Returns a single attribute of the post being edited, preferring the unsaved edit if one exists, but falling back to the attribute for the last known saved state of the post.

Parameters

  • state Object: Global application state.
  • attributeName string: Post attribute name.

Returns

  • *: Post attribute value.

getEditedPostContent

Returns the content of the post being edited.

Parameters

  • state Object: Global application state.

Returns

  • string: Post content.

getEditedPostPreviewLink

Returns the post preview link

Parameters

  • state Object: Global application state.

Returns

  • string?: Preview Link.

getEditedPostSlug

Returns the slug for the post being edited, preferring a manually edited value if one exists, then a sanitized version of the current post title, and finally the post ID.

Parameters

  • state Object: Editor state.

Returns

  • string: The current slug to be displayed in the editor

getEditedPostVisibility

Returns the current visibility of the post being edited, preferring the unsaved value if different than the saved post. The return value is one of "private", "password", or "public".

Parameters

  • state Object: Global application state.

Returns

  • string: Post visibility.

getEditorBlocks

Return the current block list.

Parameters

  • state Object:

Returns

  • Array: Block list.

getEditorSelection

Returns the current selection.

Parameters

  • state Object:

Returns

  • WPBlockSelection: The selection end.

getEditorSelectionEnd

Deprecated since Gutenberg 10.0.0.

Returns the current selection end.

Parameters

  • state Object:

Returns

  • WPBlockSelection: The selection end.

getEditorSelectionStart

Deprecated since Gutenberg 10.0.0.

Returns the current selection start.

Parameters

  • state Object:

Returns

  • WPBlockSelection: The selection start.

getEditorSettings

Returns the post editor settings.

Parameters

  • state Object: Editor state.

Returns

  • Object: The editor settings object.

getFirstMultiSelectedBlockClientId

Related

  • getFirstMultiSelectedBlockClientId in core/block-editor store.

getGlobalBlockCount

Related

  • getGlobalBlockCount in core/block-editor store.

getInserterItems

Related

  • getInserterItems in core/block-editor store.

getLastMultiSelectedBlockClientId

Related

  • getLastMultiSelectedBlockClientId in core/block-editor store.

getMultiSelectedBlockClientIds

Related

  • getMultiSelectedBlockClientIds in core/block-editor store.

getMultiSelectedBlocks

Related

  • getMultiSelectedBlocks in core/block-editor store.

getMultiSelectedBlocksEndClientId

Related

  • getMultiSelectedBlocksEndClientId in core/block-editor store.

getMultiSelectedBlocksStartClientId

Related

  • getMultiSelectedBlocksStartClientId in core/block-editor store.

getNextBlockClientId

Related

  • getNextBlockClientId in core/block-editor store.

getPermalink

Returns the permalink for the post.

Parameters

  • state Object: Editor state.

Returns

  • ?string: The permalink, or null if the post is not viewable.

getPermalinkParts

Returns the permalink for a post, split into it's three parts: the prefix, the postName, and the suffix.

Parameters

  • state Object: Editor state.

Returns

  • Object: An object containing the prefix, postName, and suffix for the permalink, or null if the post is not viewable.

getPostEdits

Returns any post values which have been changed in the editor but not yet been saved.

Parameters

  • state Object: Global application state.

Returns

  • Object: Object of key value pairs comprising unsaved edits.

getPostLockUser

Returns details about the post lock user.

Parameters

  • state Object: Global application state.

Returns

  • Object: A user object.

getPostTypeLabel

Returns a post type label depending on the current post.

Parameters

  • state Object: Global application state.

Returns

  • string|undefined: The post type label if available, otherwise undefined.

getPreviousBlockClientId

Related

  • getPreviousBlockClientId in core/block-editor store.

getSelectedBlock

Related

  • getSelectedBlock in core/block-editor store.

getSelectedBlockClientId

Related

  • getSelectedBlockClientId in core/block-editor store.

getSelectedBlockCount

Related

  • getSelectedBlockCount in core/block-editor store.

getSelectedBlocksInitialCaretPosition

Related

  • getSelectedBlocksInitialCaretPosition in core/block-editor store.

getStateBeforeOptimisticTransaction

Deprecated since Gutenberg 9.7.0.

Returns state object prior to a specified optimist transaction ID, or null if the transaction corresponding to the given ID cannot be found.

getSuggestedPostFormat

Returns a suggested post format for the current post, inferred only if there is a single block within the post and it is of a type known to match a default post format. Returns null if the format cannot be determined.

Parameters

  • state Object: Global application state.

Returns

  • ?string: Suggested post format.

getTemplate

Related

  • getTemplate in core/block-editor store.

getTemplateLock

Related

  • getTemplateLock in core/block-editor store.

hasChangedContent

Returns true if content includes unsaved changes, or false otherwise.

Parameters

  • state Object: Editor state.

Returns

  • boolean: Whether content includes unsaved changes.

hasEditorRedo

Returns true if any future editor history snapshots exist, or false otherwise.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether redo history exists.

hasEditorUndo

Returns true if any past editor history snapshots exist, or false otherwise.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether undo history exists.

hasInserterItems

Related

  • hasInserterItems in core/block-editor store.

hasMultiSelection

Related

  • hasMultiSelection in core/block-editor store.

hasNonPostEntityChanges

Returns true if there are unsaved edits for entities other than the editor's post, and false otherwise.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether there are edits or not.

hasSelectedBlock

Related

  • hasSelectedBlock in core/block-editor store.

hasSelectedInnerBlock

Related

  • hasSelectedInnerBlock in core/block-editor store.

inSomeHistory

Deprecated since Gutenberg 9.7.0.

Returns true if an optimistic transaction is pending commit, for which the before state satisfies the given predicate function.

isAncestorMultiSelected

Related

  • isAncestorMultiSelected in core/block-editor store.

isAutosavingPost

Returns true if the post is autosaving, or false otherwise.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether the post is autosaving.

isBlockInsertionPointVisible

Related

  • isBlockInsertionPointVisible in core/block-editor store.

isBlockMultiSelected

Related

  • isBlockMultiSelected in core/block-editor store.

isBlockSelected

Related

  • isBlockSelected in core/block-editor store.

isBlockValid

Related

  • isBlockValid in core/block-editor store.

isBlockWithinSelection

Related

  • isBlockWithinSelection in core/block-editor store.

isCaretWithinFormattedText

Related

  • isCaretWithinFormattedText in core/block-editor store.

isCleanNewPost

Returns true if there are no unsaved values for the current edit session and if the currently edited post is new (has never been saved before).

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether new post and unsaved values exist.

isCurrentPostPending

Returns true if post is pending review.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether current post is pending review.

isCurrentPostPublished

Return true if the current post has already been published.

Parameters

  • state Object: Global application state.
  • currentPost Object?: Explicit current post for bypassing registry selector.

Returns

  • boolean: Whether the post has been published.

isCurrentPostScheduled

Returns true if post is already scheduled.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether current post is scheduled to be posted.

isEditedPostAutosaveable

Returns true if the post can be autosaved, or false otherwise.

Parameters

  • state Object: Global application state.
  • autosave Object: A raw autosave object from the REST API.

Returns

  • boolean: Whether the post can be autosaved.

isEditedPostBeingScheduled

Return true if the post being edited is being scheduled. Preferring the unsaved status values.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether the post has been published.

isEditedPostDateFloating

Returns whether the current post should be considered to have a "floating" date (i.e. that it would publish "Immediately" rather than at a set time).

Unlike in the PHP backend, the REST API returns a full date string for posts where the 0000-00-00T00:00:00 placeholder is present in the database. To infer that a post is set to publish "Immediately" we check whether the date and modified date are the same.

Parameters

  • state Object: Editor state.

Returns

  • boolean: Whether the edited post has a floating date value.

isEditedPostDirty

Returns true if there are unsaved values for the current edit session, or false if the editing state matches the saved or new post.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether unsaved values exist.

isEditedPostEmpty

Returns true if the edited post has content. A post has content if it has at least one saveable block or otherwise has a non-empty content property assigned.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether post has content.

isEditedPostNew

Returns true if the currently edited post is yet to be saved, or false if the post has been saved.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether the post is new.

isEditedPostPublishable

Return true if the post being edited can be published.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether the post can been published.

isEditedPostSaveable

Returns true if the post can be saved, or false otherwise. A post must contain a title, an excerpt, or non-empty content to be valid for save.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether the post can be saved.

isFirstMultiSelectedBlock

Related

  • isFirstMultiSelectedBlock in core/block-editor store.

isMultiSelecting

Related

  • isMultiSelecting in core/block-editor store.

isPermalinkEditable

Returns whether the permalink is editable or not.

Parameters

  • state Object: Editor state.

Returns

  • boolean: Whether or not the permalink is editable.

isPostAutosavingLocked

Returns whether post autosaving is locked.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Is locked.

isPostLocked

Returns whether the post is locked.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Is locked.

isPostLockTakeover

Returns whether the edition of the post has been taken over.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Is post lock takeover.

isPostSavingLocked

Returns whether post saving is locked.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Is locked.

isPreviewingPost

Returns true if the post is being previewed, or false otherwise.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether the post is being previewed.

isPublishingPost

Returns true if the post is being published, or false otherwise.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether post is being published.

isPublishSidebarEnabled

Returns whether the pre-publish panel should be shown or skipped when the user clicks the "publish" button.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether the pre-publish panel should be shown or not.

isSavingNonPostEntityChanges

Returns true if non-post entities are currently being saved, or false otherwise.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether non-post entities are being saved.

isSavingPost

Returns true if the post is currently being saved, or false otherwise.

Parameters

  • state Object: Global application state.

Returns

  • boolean: Whether post is being saved.

isSelectionEnabled

Related

  • isSelectionEnabled in core/block-editor store.

isTyping

Related

  • isTyping in core/block-editor store.

isValidTemplate

Related

  • isValidTemplate in core/block-editor store.

Actions

autosave

Action generator used in signalling that the post should autosave. This includes server-side autosaving (default) and client-side (a.k.a. local) autosaving (e.g. on the Web, the post might be committed to Session Storage).

Parameters

  • options Object?: Extra flags to identify the autosave.

clearSelectedBlock

Related

  • clearSelectedBlock in core/block-editor store.

disablePublishSidebar

Returns an action object used in signalling that the user has disabled the publish sidebar.

Returns

  • Object: Action object

editPost

Returns an action object used in signalling that attributes of the post have been edited.

Parameters

  • edits Object: Post attributes to edit.
  • options Object: Options for the edit.

enablePublishSidebar

Returns an action object used in signalling that the user has enabled the publish sidebar.

Returns

  • Object: Action object

enterFormattedText

Related

  • enterFormattedText in core/block-editor store.

exitFormattedText

Related

  • exitFormattedText in core/block-editor store.

hideInsertionPoint

Related

  • hideInsertionPoint in core/block-editor store.

insertBlock

Related

  • insertBlock in core/block-editor store.

insertBlocks

Related

  • insertBlocks in core/block-editor store.

insertDefaultBlock

Related

  • insertDefaultBlock in core/block-editor store.

lockPostAutosaving

Returns an action object used to signal that post autosaving is locked.

Usage

// Lock post autosaving with the lock key `mylock`:
wp.data.dispatch( 'core/editor' ).lockPostAutosaving( 'mylock' );

Parameters

  • lockName string: The lock name.

Returns

  • Object: Action object

lockPostSaving

Returns an action object used to signal that post saving is locked.

Usage

const { subscribe } = wp.data;

const initialPostStatus = wp.data.select( 'core/editor' ).getEditedPostAttribute( 'status' );

// Only allow publishing posts that are set to a future date.
if ( 'publish' !== initialPostStatus ) {

	// Track locking.
	let locked = false;

	// Watch for the publish event.
	let unssubscribe = subscribe( () => {
		const currentPostStatus = wp.data.select( 'core/editor' ).getEditedPostAttribute( 'status' );
		if ( 'publish' !== currentPostStatus ) {

			// Compare the post date to the current date, lock the post if the date isn't in the future.
			const postDate = new Date( wp.data.select( 'core/editor' ).getEditedPostAttribute( 'date' ) );
			const currentDate = new Date();
			if ( postDate.getTime() <= currentDate.getTime() ) {
				if ( ! locked ) {
					locked = true;
					wp.data.dispatch( 'core/editor' ).lockPostSaving( 'futurelock' );
				}
			} else {
				if ( locked ) {
					locked = false;
					wp.data.dispatch( 'core/editor' ).unlockPostSaving( 'futurelock' );
				}
			}
		}
	} );
}

Parameters

  • lockName string: The lock name.

Returns

  • Object: Action object

mergeBlocks

Related

  • mergeBlocks in core/block-editor store.

moveBlocksDown

Related

  • moveBlocksDown in core/block-editor store.

moveBlocksUp

Related

  • moveBlocksUp in core/block-editor store.

moveBlockToPosition

Related

  • moveBlockToPosition in core/block-editor store.

multiSelect

Related

  • multiSelect in core/block-editor store.

receiveBlocks

Related

  • receiveBlocks in core/block-editor store.

redo

Returns an action object used in signalling that undo history should restore last popped state.

removeBlock

Related

  • removeBlock in core/block-editor store.

removeBlocks

Related

  • removeBlocks in core/block-editor store.

replaceBlock

Related

  • replaceBlock in core/block-editor store.

replaceBlocks

Related

  • replaceBlocks in core/block-editor store.

resetBlocks

Related

  • resetBlocks in core/block-editor store.

resetEditorBlocks

Returns an action object used to signal that the blocks have been updated.

Parameters

  • blocks Array: Block Array.
  • options ?Object: Optional options.

resetPost

Returns an action object used in signalling that the latest version of the post has been received, either by initialization or save.

Parameters

  • post Object: Post object.

Returns

  • Object: Action object.

savePost

Action generator for saving the current post in the editor.

Parameters

  • options Object:

selectBlock

Related

  • selectBlock in core/block-editor store.

setTemplateValidity

Related

  • setTemplateValidity in core/block-editor store.

setupEditor

Returns an action generator used in signalling that editor has initialized with the specified post object and editor settings.

Parameters

  • post Object: Post object.
  • edits Object: Initial edited attributes object.
  • template Array?: Block Template.

setupEditorState

Returns an action object used to setup the editor state when first opening an editor.

Parameters

  • post Object: Post object.

Returns

  • Object: Action object.

showInsertionPoint

Related

  • showInsertionPoint in core/block-editor store.

startMultiSelect

Related

  • startMultiSelect in core/block-editor store.

startTyping

Related

  • startTyping in core/block-editor store.

stopMultiSelect

Related

  • stopMultiSelect in core/block-editor store.

stopTyping

Related

  • stopTyping in core/block-editor store.

synchronizeTemplate

Related

  • synchronizeTemplate in core/block-editor store.

toggleBlockMode

Related

  • toggleBlockMode in core/block-editor store.

toggleSelection

Related

  • toggleSelection in core/block-editor store.

trashPost

Action generator for trashing the current post in the editor.

undo

Returns an action object used in signalling that undo history should pop.

unlockPostAutosaving

Returns an action object used to signal that post autosaving is unlocked.

Usage

// Unlock post saving with the lock key `mylock`:
wp.data.dispatch( 'core/editor' ).unlockPostAutosaving( 'mylock' );

Parameters

  • lockName string: The lock name.

Returns

  • Object: Action object

unlockPostSaving

Returns an action object used to signal that post saving is unlocked.

Usage

// Unlock post saving with the lock key `mylock`:
wp.data.dispatch( 'core/editor' ).unlockPostSaving( 'mylock' );

Parameters

  • lockName string: The lock name.

Returns

  • Object: Action object

updateBlock

Related

  • updateBlock in core/block-editor store.

updateBlockAttributes

Related

  • updateBlockAttributes in core/block-editor store.

updateBlockListSettings

Related

  • updateBlockListSettings in core/block-editor store.

updateEditorSettings

Undocumented declaration.

updatePost

Deprecated since Gutenberg 9.7.0.

Returns an action object used in signalling that a patch of updates for the latest version of the post have been received.

Returns

  • Object: Action object.

updatePostLock

Returns an action object used to lock the editor.

Parameters

  • lock Object: Details about the post lock status, user, and nonce.

Returns

  • Object: Action object.