Skip to content

Instantly share code, notes, and snippets.

View pbrocks's full-sized avatar

Paul Barthmaier pbrocks

View GitHub Profile
@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
@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
*/

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 );
@pbrocks
pbrocks / securing-acf.php
Created July 12, 2022 13:38 — forked from tomjn/securing-acf.php
ACF's `the_field` function is insecure by default, here's a selection of wrappers that fix that
<?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 20:25
Sample Swiper with minimal CSS
<!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 / 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 / dev-note-5.8-block-api.md
Created November 8, 2021 18:39 — forked from gziolo/dev-note-5.8-block-api.md
Block API enhancements in WordPress 5.8

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 / add_pipelines_environment.sh
Created August 30, 2021 04:10 — forked from h2floh/add_pipelines_environment.sh
Bash script showing how to leverage az login to call Azure DevOps REST endpoints
#!/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 August 23, 2021 16:56 — 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/
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');