Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Lubos Belak hejty

🎯
Focusing
Block or report user

Report or block hejty

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hejty
hejty / gutenberg-snippets-26.js
Created Feb 22, 2019
➋➏ Get a revisions count of the current post
View gutenberg-snippets-26.js
const { select } = wp.data;
const { getCurrentPostRevisionsCount } = select( 'core/editor' );
const revisions = getCurrentPostRevisionsCount();
@hejty
hejty / gutenberg-snippets-25.js
Created Feb 20, 2019
➋➎ Get the post author's display name
View gutenberg-snippets-25.js
const { select } = wp.data;
const { getAuthors } = select( 'core' );
const { getEditedPostAttribute } = select( 'core/editor' );
const authorID = getEditedPostAttribute( 'author' );
const { name } = getAuthors().find(a => a.id === authorID);
@hejty
hejty / gutenberg-snippets-24.js
Created Feb 10, 2019
➋➍ Schedule a post for tomorrow (24 hours from now)
View gutenberg-snippets-24.js
const { dispatch } = wp.data;
const { editPost } = dispatch( 'core/editor' );
const NOW = new Date();
const ONE_DAY_IN_MS = 24 * 60 * 60 * 1000;
const TOMORROW = new Date( NOW.getTime() + ONE_DAY_IN_MS );
const schedulePost = date => editPost( { date } );
schedulePost( TOMORROW );
@hejty
hejty / gutenberg-snippets-23.js
Last active Feb 9, 2019
➋➌ Save a post as a draft
View gutenberg-snippets-23.js
const { dispatch } = wp.data;
const { editPost, savePost } = dispatch( 'core/editor' );
const setStatusToDraft = ( async () => {
await editPost( { status: 'draft' } );
await savePost();
} )();
@hejty
hejty / gutenberg-snippets-22.js
Created Feb 6, 2019
➋➋ Check if the post has any Gutenberg blocks
View gutenberg-snippets-22.js
const { select } = wp.data;
const { getBlockCount } = select( 'core/editor' );
const hasBlocks = () => !! getBlockCount();
hasBlocks();
@hejty
hejty / gutenberg-snippets-21.js
Created Feb 5, 2019
➋➊ Count the words of the post content
View gutenberg-snippets-21.js
const { select } = wp.data;
const { count } = wp.wordcount;
const { getEditedPostAttribute } = select( 'core/editor' );
const content = getEditedPostAttribute( 'content' );
const countWords = count( content, 'words' );
@hejty
hejty / gutenberg-snippets-20.js
Created Feb 4, 2019
➋×➓ Check if a logged-in user can upload files
View gutenberg-snippets-20.js
const { select } = wp.data;
const { hasUploadPermissions } = select( 'core' );
const canUpload = hasUploadPermissions();
@hejty
hejty / gutenberg-snippets-19.js
Created Feb 3, 2019
➊➒ Get the maximum upload size allowed
View gutenberg-snippets-19.js
const { select } = wp.data;
const { getEditorSettings } = select( 'core/editor' );
const { maxUploadFileSize } = getEditorSettings();
const maxMB = Number( maxUploadFileSize / Math.pow( 1024, 2 ) );
@hejty
hejty / gutenberg-snippets-18.js
Created Jan 31, 2019
➊➑ Retrieve the details of a specific post
View gutenberg-snippets-18.js
const POST_ID = 25;
const { select } = wp.data;
const { getEntityRecords } = select( 'core' );
const [ postDetails ] = getEntityRecords( 'postType', 'post', { include: POST_ID } );
@hejty
hejty / gutenberg-snippets-17.js
Created Jan 30, 2019
➊➐ Get a list of registered taxonomy objects
View gutenberg-snippets-17.js
const { select } = wp.data;
const { getTaxonomies } = select( 'core' );
const taxonomies = getTaxonomies();
You can’t perform that action at this time.