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 Oct 5, 2021
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 / 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.
*
@pbrocks
pbrocks / add_pipelines_environment.sh
Created Aug 30, 2021 — forked from h2floh/add_pipelines_environment.sh
Bash script showing how to leverage az login to call Azure DevOps REST endpoints
View add_pipelines_environment.sh
#!/bin/bash
## Demo script to show how to leverage Azure DevOps CLI Extension to call DevOps REST API directly
## without the need for PAT token
# configuration
YOUR_AZURE_DEV_OPS_ORG=''
YOUR_AZURE_DEV_OPS_PROJECT_NAME=''
# Reverse Engineered this part by looking into Azure DevOps CLI Extension
# https://github.com/Azure/azure-devops-cli-extension/blob/8cf32a41126b2b66f130843d4d16de19290052b9/azure-devops/azext_devops/devops_sdk/client.py#L71
@pbrocks
pbrocks / global-search-and-replace-query.sql
Created Aug 23, 2021 — forked from joedooley/global-search-and-replace-query.sql
SQL query that Find's all old URL's and Replaces with new URL values. This can be ran from phpmyadmin, etc... https://wpbeaches.com/updating-wordpress-mysql-database-after-moving-to-a-new-url/
View global-search-and-replace-query.sql
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
@pbrocks
pbrocks / pmpro-billing-fields-to-profile.php
Last active Aug 3, 2021
Add the billing fields created by Paid Memberships Pro to your user Profile for easy editing and inclusion in the Members List CSV.
View pmpro-billing-fields-to-profile.php
<?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
*/
@pbrocks
pbrocks / edit-form-advanced.php
Created Jul 17, 2021 — forked from tanamako/edit-form-advanced.php
Wordpress管理画面カスタマイズ
View edit-form-advanced.php
<?php
/**
* Post advanced form for inclusion in the administration panels.
*
* @package WordPress
* @subpackage Administration
*/
// don't load directly
if ( !defined('ABSPATH') )
@pbrocks
pbrocks / pmpro-redirect-during-checkout.php
Last active Jul 8, 2021
An example of how to use `pmpro_checkout_level` to redirect and interject communication with users during checkout. Sample taken from an attempt to prevent downgrading.
View pmpro-redirect-during-checkout.php
<?php // Do not include in Customizations plugin
/**
* pmpro_checkout_level Use `pmpro_checkout_level` to redirect and interject communication with users during checkout.
*
* @param array $levels The array created in admin
*
* @return array Output of the array
*/
function pmpro_redirect_during_checkout( $level ) {
// Check to see if the current user is downgrading (Gold to Silver or Gold to Free)
@pbrocks
pbrocks / pmpro-after-expiration-change-membership-levels-adjusted.php
Last active May 31, 2021
Change PMPro membership level upon expiration or cancellation to different respective levels based on member's previous level.
View pmpro-after-expiration-change-membership-levels-adjusted.php
<?php // do not copy to Customizations plugin
/**
* After expiration, assign them a specific "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_upon_expiration_change_membership_levels( $level_id, $user_id ) {
// set this to the id of the original level
$last_level_2 = 2;
@pbrocks
pbrocks / pmpro-after-expiration-change-membership-levels.php
Created Aug 3, 2018
Change PMPro membership level upon expiration or cancellation to different respective levels based on member's previous level.
View pmpro-after-expiration-change-membership-levels.php
<?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 / block.js
Last active May 8, 2021
A little more explanation about how to build a WP block with php.
View block.js
/**
* Before registering the block in JavaScript, we want
* to deconstruct the necessary variables.
*/
const el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender,
TextControl = wp.components.TextControl,
TextareaControl = wp.components.TextareaControl,
InspectorControls = wp.editor.InspectorControls;