Skip to content

Instantly share code, notes, and snippets.

@csalzano
csalzano / wp-mailhog.php
Last active Sep 30, 2022 — forked from bishless/wp-mailhog.php
Configure WordPress on Valet to use MailHog
View wp-mailhog.php
<?php
/**
* @link
* @since 1.0.0
* @package TODO
*
* @wordpress-plugin
* Plugin Name: Use MailHog
* Description: Configure WordPress on Valet to use MailHog
* Version: 1.0.0
@csalzano
csalzano / password-protection-admin-bypass.php
Created Jun 23, 2022
WordPress plugin. Allows logged-in administrators to bypass password protection on pages and posts.
View password-protection-admin-bypass.php
<?php
defined( 'ABSPATH' ) or exit;
/**
* Plugin Name: Password Protection Admin Bypass
* Description: Allows logged-in administrators to bypass password protection on pages and posts.
* Version: 1.0.0
* Author: Corey Salzano
* Author URI: https://github.com/csalzano
* Plugin URI: https://gist.github.com/csalzano/f10727dfff7614decbe663912d9c86d9
@csalzano
csalzano / acf-hide-field-front-end.php
Created Jan 9, 2022
Hide an ACF field from front-end forms
View acf-hide-field-front-end.php
<?php
/**
* hide_group_id_field
*
* Hides a field when a field group is rendered as a front-end form.
*
* @param array $wrapper
* @param array $field
* @return array
@csalzano
csalzano / wporg-developer-get-template-part.php
Last active Mar 16, 2021
Change which template is served in a Twenty Twenty-One child theme to incorporate wporg-developer
View wporg-developer-get-template-part.php
<?php
//In single.php of twentytwentyone theme, find this line
get_template_part( 'template-parts/content/content-single' );
//and replace it with this condition to blend the code reference features of the wporg-developer theme
if( DevHub\is_parsed_post_type() )
{
@csalzano
csalzano / plugin-zipper.bat
Created Dec 3, 2020
Zips a directory while excluding .git, node_modules, and .gitingore
View plugin-zipper.bat
::plugin-zipper.bat
::Zips a directory while excluding .git, node_modules, and .gitingore
@echo off
set /p slug=Please enter a directory name/plugin slug:
If /I "%slug%"=="" goto earlyexit
tar -a -c -f "%slug%".zip --exclude ".git" --exclude ".gitignore" --exclude "node_modules" "%slug%"
:earlyexit
View exclude-terms-from-editor.php
$taxonomy_name = 'venue';
//Only include venues from the current year in REST API responses
add_filter( "rest_" . $taxonomy_name . "_collection_params", 'hide_old_venues', 10, 2 );
function hide_old_venues( $prepared_args, $request ) {
//Populate the default value of the include argument to only include terms with specific IDs in the meta box
$prepared_args['include']['default'] = get_terms( array(
'taxonomy' => $taxonomy_name,
@csalzano
csalzano / a-provide-licenses.php
Last active Mar 11, 2019
A plugin that provides license keys to the EDD SL Updates on Multisite plugin for Inventory Presser add-ons
View a-provide-licenses.php
<?php
defined( 'ABSPATH' ) OR exit;
/**
* Plugin Name: Make Licenses Available for Updates on Multisite
* Plugin URI: https://gist.github.com/csalzano/621deacc33f2482da205f294b445485a
* Description: A plugin that provides license keys to the EDD SL Updates on Multisite plugin for Inventory Presser add-ons
* Version: 1.0.0
* Author: Corey Salzano
* Author URI: https://coreysalzano.com/
* Text Domain: invp-make-licenses-available
View list-widget-replacement.php
<div class="widget">
<div class="widget-content">
<h2 class="widget-title">At a Glance</h2>
<ul class="at-a-glance">
<li>Founded <b>1729</b></li>
<li>Size <b>23 square miles</b></li>
<li>Population <b>&lt;5,000</b></li>
<li><b>7</b> properties in the National Register of Historic Places</li>
</ul>
</div>
@csalzano
csalzano / edit-term-meta.js
Created Feb 27, 2019
JavaScript that edits a term meta value in a WordPress custom taxonomy
View edit-term-meta.js
//edit a term meta value in our Transmission custom taxonomy
let terms = new wp.api.collections.Tranmission();
terms.fetch().done( function( t ){
let target = t.find( x => 'automatic' === x.slug );
if( ! target ) { return; }
jQuery.ajax({
method: 'POST',
url: myplugin.rest_base_url + 'wp/v2/transmission/' + target.id,
//save the number 6 in a term meta key 'speeds'
data: { meta: { 'speeds': 6 } },
@csalzano
csalzano / delete-term.js
Last active Feb 27, 2019
JavaScript that deletes a term from a WordPress custom taxonomy
View delete-term.js
//find & delete a term in our Transmission custom taxonomy
let terms = new wp.api.collections.Transmission();
terms.fetch().done( function( t ){
let target = t.find( x => 'automatic' === x.slug );
if( ! target ) { return; }
jQuery.ajax({
method: 'DELETE',
url: myplugin.rest_base_url + 'wp/v2/transmission/' + target.id + '?force=true',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', myplugin.nonce ); //must be wp_create_nonce( 'wp_rest' ), see paragraph 4 https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/