Skip to content

Instantly share code, notes, and snippets.


Paul Barthmaier pbrocks

View GitHub Profile
pbrocks / higher-order-component.js
Created Apr 27, 2019
From the Handbook, creating a higher order component is a best practice for the WordPress abstraction layer of React.
View higher-order-component.js
const { createHigherOrderComponent } = wp.compose;
const withClientIdClassName = createHigherOrderComponent( ( BlockListBlock ) => {
return ( props ) => {
return <BlockListBlock { ...props } className={ "block-" + props.clientId } />;
}, 'withClientIdClassName' );
wp.hooks.addFilter( 'editor.BlockListBlock', 'my-plugin/with-client-id-class-name', withClientIdClassName );
pbrocks / wclancpa-2019-block-categories.php
Created Apr 27, 2019
PHP snippet to add a panel to the WP Block Inserter.
View wclancpa-2019-block-categories.php
* Adding a block category creates a Panel
function create_wclancpa_2019_panel( $categories, $post ) {
return array_merge(
'slug' => 'wclancpa-2019',
pbrocks / wclancpa-2019-imageblockstyle.js
Last active Nov 17, 2021
The core image block in WordPress does not ship with its own style, but you can easily add styles with the Block Style filter, thereby enabling you to target the block with custom CSS or JS. Here I am adding two, but only one will receive any treatment.
View wclancpa-2019-imageblockstyle.js
wp.blocks.registerBlockStyle( 'core/image', {
name: 'phader',
label: 'Philly Phader'
} );
pbrocks / redirect-to-login-if-not-logged-in.php
Created Dec 24, 2018
Redirect to login if not logged in or if not PMPro membership page.
View redirect-to-login-if-not-logged-in.php
* Redirect to login or homepage if user is logged out or not a member
* Add this code to your active theme's functions.php file.
function my_template_redirect() {
global $current_user;
$okay_pages = array(
pmpro_getOption( 'billing_page_id' ),
pbrocks / pmpro-access.php
Last active Nov 19, 2020
Using the getfile.php element in PMPro, you can lock down files and/or directories within the URL structure of your domain.
View pmpro-access.php
This code handles loading a file from the /protected-directory/ directory.
Plugin Name: PMPro Access
(!) Be sure to change line 44 below to point to your protected directory if something other than /protected/
(!) Be sure to change line 64 below to check the levels you need.
(!) Add this code to your customizations plugin.
(!) You should have a corresponding bit of code in your Apache .htaccess file to redirect files to this script. e.g.
pbrocks / acf_modifications.php
Created Nov 15, 2018 — forked from courtneymyers/acf_modifications.php
Reduces initial height of Advanced Custom Fields WYSIWYG fields to 100px, and enables autoresizing of WYSIWYG field, as text is entered. Best practice would be to include this function in a site-specific plugin.
View acf_modifications.php
* -----------------------------------------------------------------------------
* Advanced Custom Fields Modifications
* -----------------------------------------------------------------------------
function PREFIX_apply_acf_modifications() {
pbrocks /
Created Nov 15, 2018 — forked from psorensen/
Wordpress/TinyMCE - Add elements to formats dropdown

Adding Elements to the TinyMCE Format Dropdown

On a recent migration project, one of the requirements was to add a few blockquote styles to the TinyMCE dropdown list to match the editorial process of the old CMS. Wordpress provides a filter to add a secondary or tetriary dropdown, but if you only have a couple additional elements, it seems like bad UX to seperate it from the original dropdown.

Going off a tip from Chancey Mathews, I realized that Wordpress does not send a argument for block_formats when initializing TinyMCE, thus relying on the defaults. By adding this argument to the tiny_mce_before_init filter, we can add in our extra elements*:

* Note: since we're overriding the defaults, we need to include the original elements (p, h1-h6..etc)

function mce_formats( $init ) {
pbrocks / multiline_field.js
Created Nov 15, 2018 — forked from hunk/multiline_field.js
View multiline_field.js
if('undefined' != typeof tinyMCEPreInit){
// this is for relative_urls when the main editor is on text mode
if ( typeof tinymce !== 'undefined' ) {
for ( id in tinyMCEPreInit.mceInit ) {
init = tinyMCEPreInit.mceInit[id];
init.selector = "";
tinymce.init( init );
pbrocks / editor.jsx
Created Nov 15, 2018
The modification of react-tinymce component for webpack
View editor.jsx
// Dependencies
import _ from 'lodash'
// React
import React from 'react'
import PropTypes from 'prop-types'
// TinyMCE
import tinymce from 'tinymce/tinymce'
import 'tinymce/themes/modern/theme'
pbrocks / php-block.js
Created Oct 28, 2018 — forked from pento/php-block.js
Converting a shortcode to a block: this method is fast to do, but a mediocre UX. You should only use this as a stopgap until you can implement a full block UI.
View php-block.js
// License: GPLv2+
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender,
TextControl = wp.components.TextControl,
InspectorControls = wp.editor.InspectorControls;
* Here's where we register the block in JavaScript.