Skip to content

Instantly share code, notes, and snippets.

View pbrocks's full-sized avatar

Paul Barthmaier pbrocks

View GitHub Profile
@pbrocks
pbrocks / install-phpcs-with-homebrew.md
Last active December 22, 2023 08:16
Install phpcs with Homebrew

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 / pmpro-after-expiration-change-membership-levels.php
Created August 3, 2018 02:34
Change PMPro membership level upon expiration or cancellation to different respective levels based on member's previous level.
<?php
/**
* When users cancel (are changed to membership level 0) we give them another "cancelled" level.
* Can be used to downgrade someone to a free level when they cancel.
* Will allow members to the "cancel level" to cancel from that though.
*/
function pmpro_after_expiration_change_membership_levels( $level_id, $user_id ) {
// set this to the id of the level you want to give members when they cancel
$last_level_5 = 5;
$last_level_6 = 6;
@pbrocks
pbrocks / pmpro-set-bbpress-role.php
Last active August 23, 2023 00:08
Add a dropdown for bbPress role to PMPro's Add a Member screen
<?php
/**
* Adds dropdown for bbPress user role with Moderator and Participant as options
*/
add_action( 'pmpro_add_member_fields', 'add_bbpress_role_to_add_member' );
add_action( 'pmpro_add_member_added', 'pmpro_add_forum_role', 11 );
function add_bbpress_role_to_add_member( $profileuser ) {
global $wp_roles;
@pbrocks
pbrocks / record-current-datetime-at-login.php
Created November 11, 2022 14:24
Record date and time information at login.
<?php
add_action( 'wp_login', 'record_current_datetime_at_login', 10, 2 );
/**
* Record Time and Date at login as a readable string.
* Save in user meta.
*
* @param string $user_login login_name
* @param object $user WP_User object
* @return string Date, time, timezone, offset
*/
@pbrocks
pbrocks / pmprorh-init-buddypress-fields.php
Last active May 9, 2023 10:49 — forked from ideadude/my_pmprorh_init_buddypress_fields.php
Example of defining PMPro Register Helper Fields Synchronized to BuddyPress XProfile Fields
<?php
/**
* Based on the Register Helper example.
* We've added a "buddypress" option for each field
* set to the XProfile name we used when setting up
* the fields in the BuddyPress extended profile.
* If the PMPro BuddyPress Add On is activated
* then the fields will be synchronized.
* Register Helper: https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
* PMPro BuddyPress: https://www.paidmembershipspro.com/add-ons/buddypress-integration/
@pbrocks
pbrocks / gitignore_per_git_branch.md
Created November 11, 2021 16:00 — forked from wizioo/gitignore_per_git_branch.md
HowTo have specific .gitignore for each git branch

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 / pmpro-set-default-country.php
Created August 1, 2018 20:12
Set the default country to United Kingdom/Great Britain using the GB abbreviation. States will be from the GB list. Rename State with a gettext filter.
<?php
/**
* [gettext_pmpro_checkout_city_state_postcode description]
*
* @param [type] $translated_text [description]
* @param [type] $original_text [description]
* @param [type] $domain [description]
*
* @return [type] [description]
*/
@pbrocks
pbrocks / sample-sidebar-plugin.js
Created January 2, 2023 15:26
Gutenberg Sidebar panel open by default
import { registerPlugin } from '@wordpress/plugins';
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
wp.data.dispatch( 'core/edit-post' ) .toggleEditorPanelOpened(
'gp-sample-document-setting-panel/sample-panel'
);
const GP_SampleDocumentSettingPanel = () => (
<PluginDocumentSettingPanel

Keybase proof

I hereby claim:

  • I am pbrocks on github.
  • I am pbrocks (https://keybase.io/pbrocks) on keybase.
  • I have a public key ASBYH7106UoO1BOaVfFV_hG-aL3h8ZIaC1v2rnHgprJaAgo

To claim this, I am signing this object:

@pbrocks
pbrocks / pbrocks-users-list-table.php
Created August 4, 2022 13:51
How to add filters to alter columns of WP_Users_List_Table.
<?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 );