Skip to content

Instantly share code, notes, and snippets.

View dylanjameswagner's full-sized avatar

Dylan James Wagner dylanjameswagner

View GitHub Profile
@dylanjameswagner
dylanjameswagner / gist:0dc32b2b31cf5d8b3c3afca2899d5184
Created July 1, 2025 14:17
WordPress - Admin Column - Page Template
add_filter('manage_pages_columns', 'add_page_template_column');
function add_page_template_column($columns) {
$columns['page_template'] = 'Page Template'; // Add a new column with the header "Page Template"
return $columns;
}
add_action('manage_pages_custom_column', 'display_page_template_in_column', 10, 2);
function display_page_template_in_column($column_name, $post_id) {
if ($column_name == 'page_template') {
$template_file = get_page_template_slug($post_id);
@dylanjameswagner
dylanjameswagner / coverage-export-parser.php
Last active June 11, 2021 14:50
Google Chrome Coverage Export Parser PHP
<?php
/**
* Google Chrome Coverage Export Parser PHP
*
* Export a coverage report from Google Chrome:
* Developer Tools > 3-dot menu > More tools > Coverage
*
* Download the coverage report JSON file by clicking the "Export..." icon on
* the Coverage panel toolbar
*
@dylanjameswagner
dylanjameswagner / create-vcard.php
Created November 8, 2019 14:24
This creates a .vcf file from the post types. Create a VCard For Brokers (this was first built for Mericle) Return the last segment of the URI This feature works by creating/modifying a vcf file when a broker post type is saved. the template
<?php
/**
* Create a VCard For Brokers (this was first built for Mericle)
* Return the last segment of the URI
*
*
* This feature works by creating/modifying a vcf file when a broker post type is saved. the template then points to that saved file.
* File will not create if you don't Save/Update the post type.
*
@dylanjameswagner
dylanjameswagner / labels.sh
Created June 14, 2019 14:19
adds custom labels and Deployment/Testing Plan checklists to Github
USER=$GIT_AUTH_USER
PASS=$GIT_AUTH_TOKEN
if git rev-parse --git-dir > /dev/null 2>&1; then :
# This is a valid git repository (but the current working
# directory may not be the top level.
# Check the output of the git rev-parse command if you care)
REPO=`git remote show github | grep "Fetch URL:" | sed "s#^.*/\(.*\).git#\1#"`
echo $REPO
OWNER=`git remote show github | grep "Fetch URL:" | cut -d "@" -f2 | cut -d ":" -f2 | cut -d "/" -f1`
@dylanjameswagner
dylanjameswagner / redirects.php
Created June 14, 2019 14:19
PHP Redirects to emulate .htaccess redirects on nginx
<?php
// include this file in your root index.php before any Wordpress files start getting pulled in.
// allow us to force garbage collection (for performance)
// commented out for now because it should be enabled by default. Going to test without it first.
// gc_enable(); // PHP >= 5.3.0
// old_path => new_path
// make sure all of your old_paths have no trailing slash
@dylanjameswagner
dylanjameswagner / rewrite-page-priority.php
Created June 14, 2019 14:18
rewrite-page-priority.php
<?php
/**
* Page Rewrite Priority
*
* @link https://wordpress.stackexchange.com/questions/22438/how-to-make-pages-slug-have-priority-over-any-other-taxonomies-like-custom-post
*/
function carbon_rewrite_init() {
$GLOBALS['wp_rewrite']->use_verbose_page_rules = true;
}
add_action( 'init', 'carbon_rewrite_init' );
@dylanjameswagner
dylanjameswagner / create-admin-account.php
Last active May 1, 2025 16:18
WordPress: create administrator account from functions.php
<?php
add_action( 'init', function () {
if ( $_SERVER['HTTP_HOST'] === 'example.com.local' ) {
/** Add User */
$username = 'username';
$password = 'password';
$email = 'email@example.com';
@dylanjameswagner
dylanjameswagner / dirname_basename.js
Created June 5, 2017 18:54 — forked from umidjons/dirname_basename.js
PHP dirname() and basename() alternatives for JavaScript
function basename( path )
{
return path.replace( /\\/g, '/' ).replace( /.*\//, '' );
}
function dirname( path )
{
return path.replace( /\\/g, '/' ).replace( /\/[^\/]*$/, '' );
}
console.log( dirname( '/srv/www/dev/umid/admin/cfg.admin.php' ) );
@dylanjameswagner
dylanjameswagner / tag-cloud.php
Created May 3, 2017 14:35
Add an active class to the current tag in a tag cloud widget.
function carbon_tag_cloud_class_active($tags_data) {
$body_class = get_body_class();
foreach ($tags_data as $key => $tag) {
if(in_array('tag-'.$tag['id'], $body_class)) {
$tags_data[$key]['class'] = $tags_data[$key]['class'] ." active-tag";
}
}
@dylanjameswagner
dylanjameswagner / acf-readonly-disabled.php
Created April 4, 2017 13:02
Add Disabled/Read-Only Options to ACF Fields
<?php
add_action('acf/render_field_settings/type=number', 'add_readonly_and_disabled_to_number_field');
function add_readonly_and_disabled_to_text_field($field) {
acf_render_field_setting( $field, array(
'label' => __('Read Only?','acf'),
'instructions' => '',
'type' => 'radio',
'name' => 'readonly',
'choices' => array(