Skip to content

Instantly share code, notes, and snippets.

View theMikeD's full-sized avatar

theMikeD theMikeD

View GitHub Profile
@theMikeD
theMikeD / show_page_info.php
Created March 21, 2017 19:49
To see info on a page in WP source.
<?php
add_action( 'wp_head', 'cnmd_debug_insert_template_info_into_src' );
/**
* Insert the template in use and the page ID into <head> of the document src.
*/
function cnmd_debug_insert_template_info_into_src() {
global $template;
global $post;
@theMikeD
theMikeD / indicator.js
Last active October 18, 2016 18:13
Assigns slider counters to RS instances
jQuery(document).ready(function($) {
/**
* Inserts and updates RoyalSlider slide indicators.
* @src http://help.dimsemenov.com/kb/royalslider-javascript-api/creating-slider-index-indicator-slide-1-of-10
*/
var cnmd_create_rs_slide_counter = function() {
$(".royalSlider").each(function () {
var slider = this;
var sliderData = $(slider).data('royalSlider');
@theMikeD
theMikeD / template_debugging.php
Created May 16, 2016 21:03
Puts some helpful wordpress template info into the html document head
/**
* Insert the template in use and the page ID into <head> of the document src.
*/
add_action( 'wp_head', 'cnmd_debug_insert_template_info_into_src' );
function cnmd_debug_insert_template_info_into_src() {
global $template;
global $post;
// Get the path part
$url = parse_url($template, PHP_URL_PATH);
@theMikeD
theMikeD / dumb.php
Last active March 30, 2016 22:03
Menu mods based on user role
<?php
/*----------------------------------------------------/
Remove Admin Menu Items For Editor
/----------------------------------------------------*/
if( current_user_can('editor') ) {
function remove_editor_menus () {
global $menu;
$restricted = array(__('Dashboard'), __('Links'), __('FAQs'), __('FlexSlider'), __('Settings'), __('Comments'));
end ($menu);
while (prev($menu)){
@theMikeD
theMikeD / example.php
Created January 12, 2016 22:29
How to assign a CPT icon to the dashboard
/**
* Sets the icon for a given CPT in the dashboard's "At a Glance" section.
* When registering a post type, adding ‘menu_icon’ => '' will result in the menu item
* being given the class "menu-icon-<cpt-slug>".
*
* Note that the dashicon used in the side menu is specified in the CPT declaration directly,
* but the dashboard icon is not.
* @param $cpt
* @param string $icon
*/
@theMikeD
theMikeD / taxonomy_archive_indication.php
Last active August 29, 2015 14:21
Indicate which pages are taxonomy archives
add_filter( 'display_post_states', 'cnmd_add_archive_page_indicators', 10, 2);
/**
* cnmd_add_archive_page_indicators adds post state labels for custom and builtin taxonomy
* archive pages
*
* @param ARRAY $post_states
* @param POST OBJ $post
*
* @return array
*/
@theMikeD
theMikeD / md_log.php
Last active August 29, 2015 14:12
More flexible replacement for error_log()
<?php
//----------------------------------------------------------------------------------------
// print to the log, either a variable, object or array
function md_log ( $o ){
$callers=debug_backtrace();
error_log ($callers[1]['function']);
if ( is_array( $o ) || is_object( $o ) ) {
error_log(print_r( $o, true));
} else {
error_log( $o );
@theMikeD
theMikeD / gist:b1fe86dbc1fc15d1b312
Created September 12, 2014 22:00
Wordpress PHP to notify of missing plugins
// R E Q U I R E S
// The list of required plugins
$md_csa_required_plugins = array(
array( // ACF
'func' => 'get_field',
'call' => 'md_notify_acf',
),
array( // ACF Repeater
'func' => 'acf_register_repeater_field',
'call' => 'md_notify_acf_repeater',
add_action('genesis_setup','md_genesis_core_setup');
function md_genesis_core_setup() {
unregister_sidebar( 'header-right' );
unregister_sidebar( 'sidebar' );
unregister_sidebar( 'sidebar-alt' );
}
@theMikeD
theMikeD / md_insert_template_info
Last active August 29, 2015 14:02
Function to insert the in-use template and page id into the document head as a comment. Aids in debugging.
add_action( 'wp_head', 'md_insert_template_info');
function md_insert_template_info() {
global $template;
global $post;
// get the path part
$url = parse_url($template, PHP_URL_PATH);
// split on /
$surl = explode('/',$url);