Skip to content

Instantly share code, notes, and snippets.

Kellen Mace kellenmace

Block or report user

Report or block kellenmace

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View force-css-js-to-go-live-immediately.php
<?php
// Version CSS file in a theme
wp_enqueue_style(
'theme-styles',
get_stylesheet_directory_uri() . '/style.css',
array(),
filemtime( get_stylesheet_directory() . '/style.css' )
);
View delete-transients-by-prefix.php
<?php
/**
* Searches the database for transients stored there that match a specific prefix.
*
* @author Brad Parbs, Kellen Mace
* @param string $prefix prefix to search for.
* @return array nested array response for wpdb->get_results.
*/
function wds_campbell_search_database_for_transients_by_prefix( $prefix ) {
@kellenmace
kellenmace / class-download-remote-image.php
Last active Jul 15, 2019
Download and Insert a Remote Image File into the WordPress Media Library
View class-download-remote-image.php
<?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 / template-tags.php
Last active Jul 13, 2019
Caching WP_Query() Results Template Tags
View template-tags.php
<?php
/**
* Custom template tags.
*/
/**
* Run a query to get upcoming courses.
*/
function wds_lal_get_upcoming_courses() {
@kellenmace
kellenmace / remove-custom-post-type-slug-from-permalinks-2.php
Last active Jul 5, 2019
Remove custom post type slug from permalinks 2
View remove-custom-post-type-slug-from-permalinks-2.php
<?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 / add-unfiltered_html-capability-to-admins-or-editors.php
Last active Jul 3, 2019
Add unfiltered_html Capability to Admins or Editors in WordPress Multisite
View add-unfiltered_html-capability-to-admins-or-editors.php
<?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 / km-remove-slug-from-custom-post-type.php
Last active Jul 2, 2019
Remove Slug from Custom Post Type URL in WordPress
View km-remove-slug-from-custom-post-type.php
<?php
/**
* Plugin Name: Remove Slug from Custom Post Type
* Description: Remove slug from custom post type URLs.
* 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 / get-id-of-main-site-in-wordpress-multisite.php
Created May 26, 2017
Get the Blog ID of the Main Site in a WordPress Multisite Network
View get-id-of-main-site-in-wordpress-multisite.php
<?php
/*
* Get the Blog ID of the main site in a multisite network.
*
* @return int The blog_id of the main site.
*/
function km_get_main_site_blog_id() {
return get_network()->site_id;
}
@kellenmace
kellenmace / Load-Template-From-WordPress-Plugin.php
Last active Apr 26, 2019
Load Template From WordPress Plugin
View Load-Template-From-WordPress-Plugin.php
<?php
function km_include_gym_dashboard_page_template( $template ) {
if ( is_page( 'gym-dashboard' ) ) {
return plugin_dir_path( __FILE__ ) . 'templates/content-gym-dashboard.php';
}
return $template;
}
View Require post title.php
<?php
// Load admin scripts & styles
function km_load_admin_scripts( $hook ) {
// If the post we're editing isn't a project_summary type, exit this function.
if ( 'project_summary' !== get_post_type() ) {
return;
}
// If we're creating/updating the post, exit this function.
You can’t perform that action at this time.