Skip to content

Instantly share code, notes, and snippets.

View kellenmace's full-sized avatar

Kellen Mace kellenmace

View GitHub Profile
@kellenmace
kellenmace / remove-custom-post-type-slug-from-permalinks-2.php
Last active July 2, 2023 16:18
Remove custom post type slug from permalinks 2
<?php
/**
* Have WordPress match postname to any of our public post types (post, page, race).
* All of our public post types can have /post-name/ as the slug, so they need to be unique across all posts.
* By default, WordPress only accounts for posts and pages where the slug is /post-name/.
*
* @param $query The current query.
*/
function gp_add_cpt_post_names_to_main_query( $query ) {
@kellenmace
kellenmace / automatically-mark-affiliate-wp-referrals-as-paid.php
Created December 31, 2015 08:30
Automatically mark AffiliateWP referrals as paid. After a new affiliate has been created, waits 1 minute then makes sure the status of the last 50 referrals is set to paid. You must have Auto Register New Users enabled in AffiliateWP settings.
<?php
/*
* Schedule cron job to automatically mark referrals as paid shortly after a new affiliate is registered
*/
function affwp_rcp_schedule_mark_referrals_as_paid_cron() {
wp_schedule_event( time() + 60, 'twicedaily', 'affwp_rcp_mark_referrals_as_paid' );
}
add_action( 'affwp_insert_affiliate', 'affwp_rcp_schedule_mark_referrals_as_paid_cron' );
@kellenmace
kellenmace / youtube-video-categories-may-2023.txt
Created May 23, 2023 04:34
Categories that content creators can apply to their YouTube videos as of May, 2023
Autos & Vehicles
Comedy
Education
Entertainment
Film & Animation
Gaming
Howto & Style
Music
News & Politics
Nonprofits & Activism
<?php
/**
* Plugin Name: Pagination Fields
* Description: Adds next & prev post data to WPGraphQL schema
* Version: 0.1.0
* Author: Kellen Mace
* Author URI: https://kellenmace.com/
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
@kellenmace
kellenmace / class-download-remote-image.php
Last active October 13, 2022 13:24
Download and Insert a Remote Image File into the WordPress Media Library
<?php
/**
* This class handles downloading a remote image file and inserting it
* into the WP Media Library.
*
* Usage:
* $download_remote_image = new KM_Download_Remote_Image( $url );
* $attachment_id = $download_remote_image->download();
*
@kellenmace
kellenmace / add-unfiltered_html-capability-to-admins-or-editors.php
Last active September 20, 2022 18:29
Add unfiltered_html Capability to Admins or Editors in WordPress Multisite
<?php
/**
* Enable unfiltered_html capability for Editors.
*
* @param array $caps The user's capabilities.
* @param string $cap Capability name.
* @param int $user_id The user ID.
* @return array $caps The user's capabilities, with 'unfiltered_html' potentially added.
*/
@kellenmace
kellenmace / taxonomy-dropdown-functions.php
Created September 23, 2016 20:22
WordPress Taxonomy Dropdown Functions
<?php
/**
* Get tools, filtered by the taxonomy term, if one was selected.
*
* @return WP_Query Tools in the taxonomy term if one was selected, else all.
*/
function km_get_tools_in_taxonomy_term() {
return new WP_Query( array(
@kellenmace
kellenmace / taxonomy-dropdown-template.php
Created September 23, 2016 20:21
WordPress Taxonomy Dropdown Template
<div class="tools-dropdown">
<form id="tool-category-select" class="tool-category-select" method="get">
<?php
// Create and display the dropdown menu.
wp_dropdown_categories(
array(
'orderby' => 'NAME', // Order the items in the dropdown menu by their name.
'taxonomy' => 'tools', // Only include posts with the taxonomy of 'tools'.
<?php
function hmc_metaboxes( array $meta_boxes ) {
$meta_boxes['home_metabox'] = array(
'id' => '_hmc_home_metabox2',
'title' => __( 'Key Facts', 'hmc' ),
'pages' => array( 'page' ),
'show_on' => array( 'key' => 'page-template', 'value' => 'templates/home-page.php' ),
'context' => 'normal',
'priority' => 'default',
<p>Store Address: <?php echo esc_html( get_post_meta( get_the_ID(), 'store_address', true ) ); ?></p>