Skip to content

Instantly share code, notes, and snippets.

View pbrocks's full-sized avatar

Paul Barthmaier pbrocks

View GitHub Profile
@pbrocks
pbrocks / pmpro-access.php
Last active November 19, 2020 04:23
Using the getfile.php element in PMPro, you can lock down files and/or directories within the URL structure of your domain.
<?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
pbrocks / acf_modifications.php
Created November 15, 2018 06:33 — 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.
<?php
/*
* -----------------------------------------------------------------------------
* Advanced Custom Fields Modifications
* -----------------------------------------------------------------------------
*/
function PREFIX_apply_acf_modifications() {
?>
<style>
@pbrocks
pbrocks / tinymce-add-formats.md
Created November 15, 2018 06:26 — forked from psorensen/tinymce-add-formats.md
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
pbrocks / multiline_field.js
Created November 15, 2018 06:24 — forked from hunk/multiline_field.js
field_types/multiline_field/multiline_field.js
jQuery.mf_bind('add',function(){
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
pbrocks / editor.jsx
Created November 15, 2018 06:24
The modification of react-tinymce component for webpack
// 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
pbrocks / php-block.js
Created October 28, 2018 17:09 — 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.
// 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.
@pbrocks
pbrocks / pmpro-365give-new-reg-helper.php
Created October 17, 2018 00:54
New Register Helper plugin Customizations
<?php
/**
* Plugin Name: PMPro - Register Helper Customizations
* Plugin URI: https://www.paidmembershipspro.com/wp/pmpro-customizations/
* Description: Customizations for Levels 1 and 4
* Version: 0.2
* Author: Steve Moen & Nicola
* Author URI: https://www.365give.ca
*/
// we have to put everything in a function called on init, so we are sure Register Helper is loaded
@pbrocks
pbrocks / a-login-redirect-to-referrer.php
Created October 15, 2018 07:21
Redirect users on login
<?php
/**
* Redirect user to referrer after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*/
function a_login_redirect_to_referrer( $redirect_to, $request, $user ) {
@pbrocks
pbrocks / pmpro-custom-register-helper.php
Last active October 10, 2018 00:21
Custom Register Helper fields for Paid Memberships Pro
<?php // Do not include this or the doc block if adding to a Customizations plugin
/**
* Add this to its own folder in your plugins directory or copy the code below this doc block to a Customizations Plugin and customize to suit your needs.
*
* Plugin Name: PMPro Register Helper Examples
*
* Description: Create a folder name in your plugins' folder with the same name as this filename, but without the .php extension. Save this file in that folder and then you can activate this plugin in your WordPress dashboard,
*
* Author: pbrocks
* Author URI: https://github.com/pbrocks
@pbrocks
pbrocks / pmpro-billing-fields-to-profile.php
Last active August 3, 2021 06:21
Add the billing fields created by Paid Memberships Pro to your user Profile for easy editing and inclusion in the Members List CSV.
<?php
/**
* Plugin Name: PMPro Customizations 2 - Billing to Profile
*
* Add PMPro billing fields to the edit user profile page.
*
* You must have installed both Paid Memberships Pro and the Register Helper plugins
*
* https://github.com/strangerstudios/pmpro-register-helper
*/