Skip to content

Instantly share code, notes, and snippets.

View DrewAPicture's full-sized avatar

Drew Jaynes DrewAPicture

View GitHub Profile
<?php
// From wp-admin/nav-menus.php
break;
case 'locations':
check_admin_referer( 'save-menu-locations', 'save-menu-locations-nonce', false );
// Get existing menu locations assignments
$locations = get_registered_nav_menus();
$menu_locations = get_nav_menu_locations();
<?php
add_meta_box( 'nav-menu-theme-locations', __( 'Theme Locations' ), 'wp_nav_menu_locations_meta_box' , 'nav-menus', 'side', 'default' );
@DrewAPicture
DrewAPicture / term_singular.php
Last active December 14, 2015 13:48
Too "clever" for core? It's the battle of that one multi-line condition that forces curly braces.
<?php
if ( is_tax() )
$title = get_taxonomy( get_queried_object()->taxonomy )->labels->singular_name;
elseif ( something else )
vs
if ( is_tax() ) {
$term = get_queried_object();
$tax = get_taxonomy( $term->taxonomy );
@DrewAPicture
DrewAPicture / clean_404_emails.php
Last active September 27, 2023 09:03
Original snippet by wp-mix.com at http://wp-mix.com/wordpress-404-email-alerts/ With the improved OOP style, implementation is a lot more straightforward, just add <?php new Clean_404_Email; to the top of your 404.php template.
<?php
// Just require() this class via your theme's functions.php file.
/* Then instantiate this at the top of your 404.php file with:
if ( class_exists( 'Clean_404_Email' ) )
new Clean_404_Email;
*/
class Clean_404_Email {
var $time, $request, $blog, $email, $theme, $theme_data, $site, $referer, $string, $address, $remote, $agent, $message;
@DrewAPicture
DrewAPicture / invalid_locations.php
Created February 16, 2013 21:34
Remove invalid menu locaitons
<?php
if ( is_array( $menu_locations ) ) {
foreach ( $menu_locations as $key => $value ) {
if ( ! is_string( $key ) )
unset( $menu_locations[$key] );
}
}
set_theme_mod( 'nav_menu_locations', $menu_locations );
#!/bin/sh
# A script that leverages Trac XML-RPC (I know, I know) to upload patches.
#
# This script is written specifically for the Mac, in that it reads from
# your keychain to derive your SVN password. You can change the SVN_PASS
# line below if you wanted to pull from ~/.svn/ or what not.
#
# Basic usage: `trac-attach.sh 12345` uploads a patch to ticket #12345,
# using the name 12345.diff. If there exists a 12345.diff, the patch is
<?php foreach( (array) $nav_menus as $_nav_menu ) : ?>
<option value="<?php echo esc_url(add_query_arg( array( 'action' => 'edit', 'menu' => $_nav_menu->term_id, ), admin_url( 'nav-menus.php' ) )); ?>" <?php if ( $nav_menu_selected_id == $_nav_menu->term_id ) echo 'selected="selected"'; ?>>
<?php
echo esc_html( $_nav_menu->truncated_name ) ;
if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations ) ) {
$locations_assigned_to_this_menu = array();
foreach ( array_keys( $menu_locations, $_nav_menu->term_id ) as $menu_location_key ) {
$locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
}
$assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) ) );
@DrewAPicture
DrewAPicture / largo-includes.diff
Created February 3, 2013 23:22
An idea for compacting Largo's includes.
diff --git a/functions.php b/functions.php
index 6855695..84634d8 100644
--- a/functions.php
+++ b/functions.php
@@ -50,47 +50,28 @@ if ( ! function_exists( 'optionsframework_init' ) ) {
* Load up all of the other goodies from the /inc directory
*/
-// a list of recommended plugins
-require_once( get_template_directory() . '/inc/largo-plugin-init.php' );
@DrewAPicture
DrewAPicture / example_help_tab.php
Last active December 11, 2015 18:48
Generally speaking, help tabs in core commonly follow one of the following three formats. Which should we use in a patch-making tutorial for the docs team?
<?php
/**
* Example format #1
*/
$example_string = '<p>' . __( 'This is some help text' ) . '</p>' .
'<p>' . __( 'This is some more help text' ) . '</p>';
get_current_screen()->add_help_tab( array(
'id' => 'example',
Drew@machine:~/Sites/mutrunk$ ack -i -Q 'action="<?php echo'
wp-activate.php
62: <form name="activateform" id="activateform" method="post" action="<?php echo network_site_url('wp-activate.php'); ?>">
wp-admin/includes/dashboard.php
441: <form action="<?php echo network_admin_url('users.php'); ?>" method="get">
448: <form action="<?php echo network_admin_url('sites.php'); ?>" method="get">
wp-admin/includes/file.php
982:<form action="<?php echo $form_post ?>" method="post">