Skip to content

Instantly share code, notes, and snippets.

View pbrocks's full-sized avatar

Paul Barthmaier pbrocks

View GitHub Profile
@pbrocks
pbrocks / my-pmpro-additional-categories.php
Last active December 19, 2024 06:19 — forked from strangerstudios/my_pmpro_additional_categories.php
Add "Purchase Additional Access" box to Membership Checkout for a la carte category purchase.
<?php // Do not include this line in your Customizations plugin
/**
* Require specific category user meta to view posts in designated categories.
* Custom price-adjusting fields are added via PMPro Register Helper add on (required).
* Add all of this code to your active theme's functions.php or a custom plugin.
*/
add_filter( 'pmpro_has_membership_access_filter', 'my_pmpro_additional_categories', 10, 4 );
function my_pmpro_additional_categories( $hasaccess, $thepost, $theuser, $post_membership_levels ) {
global $wpdb;
@pbrocks
pbrocks / pmpro-set-bbpress-role.php
Last active November 7, 2024 04:00
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 / refresh-git-cache.md
Created October 8, 2024 15:19
Refresh your git cache

Refresh git cache

git rm -r --cached .
git add .
git commit -am 'git cache refreshed'
git push
@pbrocks
pbrocks / install-phpcs-with-homebrew.md
Last active June 3, 2024 14:27
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 / 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