Skip to content

Instantly share code, notes, and snippets.

View phpbits's full-sized avatar
🎯
Focusing

Jeffrey Carandang phpbits

🎯
Focusing
View GitHub Profile
@phpbits
phpbits / api.js
Created October 3, 2018 06:35
Use withSelect instead of withAPIData
const { apiFetch } = wp;
const { registerStore, withSelect } = wp.data;
const actions = {
setUserRoles( userRoles ) {
return {
type: 'SET_USER_ROLES',
userRoles,
};
},
@phpbits
phpbits / Edit.js
Created October 3, 2018 06:38
Access on Edit component using withSelect
edit: withSelect( ( select ) => {
return {
roles: select('phpbits/test-block').receiveUserRoles(),
};
} )( props => {
console.log( this.props.roles );
});
@phpbits
phpbits / apiRequest.js
Created October 3, 2018 06:42
Using wp.apiRequest to access custom endpoints.
wp.apiRequest( { path: '/phpbits/test-blocks/v1/user-roles/' } )
.then(
( obj ) => {
console.log( obj );
}
);
/**
* WordPress Dependencies
*/
const { addFilter } = wp.hooks;
/**
* Add custom attribute for mobile visibility.
*
* @param {Object} settings Settings for the block.
*
@phpbits
phpbits / advanced-settings.js
Last active March 11, 2022 21:07
Add custom toggle control on Gutenberg Advanced Block Panel. View full tutorials at https://jeffreycarandang.com/extending-gutenberg-core-blocks-with-custom-attributes-and-controls/
/**
* WordPress Dependencies
*/
const { __ } = wp.i18n;
const { addFilter } = wp.hooks;
const { Fragment } = wp.element;
const { InspectorAdvancedControls } = wp.editor;
const { createHigherOrderComponent } = wp.compose;
const { ToggleControl } = wp.components;
/**
* External Dependencies
*/
import classnames from 'classnames';
/**
* Add custom element class in save element.
*
* @param {Object} extraProps Block element.
* @param {Object} blockType Blocks object.
@phpbits
phpbits / full-codes.js
Last active July 1, 2022 11:32
Extend core Gutenberg blocks with custom attributes and settings. View full tutorials here : https://jeffreycarandang.com/extending-gutenberg-core-blocks-with-custom-attributes-and-controls/
/**
* External Dependencies
*/
import classnames from 'classnames';
/**
* WordPress Dependencies
*/
const { __ } = wp.i18n;
const { addFilter } = wp.hooks;
@phpbits
phpbits / format-underline.js
Last active April 27, 2021 17:45
Create custom Underline rich text format for Gutenberg editor. Learn more at https://jeffreycarandang.com/how-to-create-custom-text-formats-for-gutenberg-block-editor/
/**
* WordPress dependencies
*/
const { __ } = wp.i18n;
const { Fragment } = wp.element;
const { toggleFormat } = wp.richText;
const { RichTextToolbarButton, RichTextShortcut } = wp.editor;
const { registerFormatType } = wp.richText;
/**
@phpbits
phpbits / editorskit-template-block-sizes.php
Last active May 17, 2019 04:38
Change Gutenberg Blocks Width to Match Page Template
<?php
//add theme support for template blocks width
add_theme_support('editorskit-template-block-sizes', array(
'default' => array(
'default' => '700px',
'wide' => '1000px',
'full' => '1200px',
),
'page-templates/landing.php' => array(
@phpbits
phpbits / editorskit-genesis-layout-block-sizes.php
Created May 17, 2019 04:39
Change Gutenberg Blocks Width to Match Genesis Layout Selection
<?php
//Genesis Framework layout support for blocks width
add_theme_support('editorskit-genesis-layout-block-sizes', array(
'content-sidebar' => array(
'default' => array(
'post' => '700px',
'page' => '800px',
),
'wide' => '900px',