Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Barthmaier pbrocks

View GitHub Profile
@pbrocks
pbrocks / install-phpcs-with-homebrew.md
Last active Sep 5, 2022
Install phpcs with Homebrew
View install-phpcs-with-homebrew.md

Install phpcs with Homebrew

To set up php linting, you’ll want to install this PHP CodeSniffer repo and configure with this WordPress Coding Standards repo: . There are a number of ways to do this, whether direct download, Composer, Homebrew, Pear, etc. The following is what works for me on MacOS using Homebrew:

In a terminal window on your Mac, start by updating your Homebrew.

brew doctor

Then install the Code Sniffer:

@pbrocks
pbrocks / pbrocks-users-list-table.php
Created Aug 4, 2022
How to add filters to alter columns of WP_Users_List_Table.
View pbrocks-users-list-table.php
<?php
/**
* Adjustments to /wp-admin/users.php screen.
*
* @package WP_List_Table
*/
add_filter( 'manage_users_columns', 'add_id_any_position_of_users_columns' );
add_filter( 'manage_users_columns', 'nickname_manage_users_columns', 10, 1 );
add_filter( 'manage_users_custom_column', 'nickname_manage_users_custom_column', 10, 3 );
@pbrocks
pbrocks / securing-acf.php
Created Jul 12, 2022 — forked from tomjn/securing-acf.php
ACF's `the_field` function is insecure by default, here's a selection of wrappers that fix that
View securing-acf.php
<?php
function the_field_url( $selector, $post_id=0, $format_value=true ) {
echo esc_url( get_field( $selector, $post_id, $format_value ) );
}
function the_field_url_raw( $selector, $post_id=0, $format_value=true ) {
echo esc_url_raw( get_field( $selector, $post_id, $format_value ) );
}
@pbrocks
pbrocks / swiper-js-sample
Created May 2, 2022
Sample Swiper with minimal CSS
View swiper-js-sample
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>SwiperJS - PBrocks - Sample</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"
/>
<link
@pbrocks
pbrocks / pmpro-defult-country-code.php
Created Dec 2, 2017
Code to add to pmpro-customizations.php to adjust default country for PMPro VAT
View pmpro-defult-country-code.php
/**
* Default to country code for Spain if none is set.
* Add to PMPro Customizations plugin.
*/
function init_set_default_vat_country_code() {
//default to Spain
if(!isset($_SESSION['eucountry'])) {
$eucountry = 'ES';
}
}
@pbrocks
pbrocks / pmpro-cancelled-level.php
Last active Mar 10, 2022 — forked from strangerstudios/pmpro_cancelled_level.php
Move PMPro members to another level when they cancel.
View pmpro-cancelled-level.php
<?php
/**
* By default cancelled members are changed to level 0. This recipe changes that behavior to give them a "cancelled" level that
* you have created for that purpose. Can be used to downgrade someone to a free level if they cancel.
*/
/**
* [pmpro_after_change_membership_level_default_level description]
*
* @param [type] $level_id [description]
* @param [type] $user_id [description]
@pbrocks
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
pbrocks / gitignore_per_git_branch.md
Created Nov 11, 2021 — forked from wizioo/gitignore_per_git_branch.md
HowTo have specific .gitignore for each git branch
View gitignore_per_git_branch.md

How to have specific .gitignore for each git branch

Objective

My objective is to have some production files ignored on specific branches. Git doesn't allow to do it.

Solution

My solution is to make a general .gitignore file and add .gitignore.branch_name files for the branches I want to add specific file exclusion. I'll use post-checkout hook to copy those .gitignore.branch_name in place of .git/info/exclude each time I go to the branch with git checkout branch_name.

@pbrocks
pbrocks / dev-note-5.8-block-api.md
Created Nov 8, 2021 — forked from gziolo/dev-note-5.8-block-api.md
Block API enhancements in WordPress 5.8
View dev-note-5.8-block-api.md

Block API Enhancements

As of WordPress 5.8 release, we encourage using block.json file metadata as the canonical way to register block types. We have been working on Block Metadata specification for a few major WordPress releases, and we reached the point where all planned features are in place.

Example:

notice/block.json

{
	"apiVersion": 2,
@pbrocks
pbrocks / a-gettext-filter-4-pmpro.php
Last active Oct 5, 2021
Sometimes we may want to change the wording of the language used in a plugin or theme, but don't want to edit code directly. A cleaner way to go is to use the built in filter that WordPress has called 'gettext'. This filter will search your codebase for translatable strings and replace when an exact match is found.
View a-gettext-filter-4-pmpro.php
<?php
/**
* This filter will search your codebase for translatable strings and replace when an exact match is found.
*
* Here we're changing 'Membership' to 'Subscription' for Paid Memberships Pro.
*
* Add this code to your PMPro Customizations Plugin
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* Note: When adding to your Customizations Plugin, be careful not to include the opening php tag on line 1 above.
*