Skip to content

Instantly share code, notes, and snippets.

if ( !class_exists('JMO_Custom_Nav')) {
class JMO_Custom_Nav {
public function add_nav_menu_meta_boxes() {
add_meta_box(
'wl_login_nav_link',
__('WishList Login'),
array( $this, 'nav_menu_link'),
'nav-menus',
'side',
'low'
@johnmorris
johnmorris / gist:5245822
Last active December 15, 2015 10:29
Hijacking WordPress menus using wp_nav_menu_objects
if ( !class_exists( 'HijackMe' ) ) {
class HijackMe {
public function hijack_menu($objects) {
/**
* If user isn't logged in, we return the link as normal
*/
if ( !is_user_logged_in() ) {
return $objects;
}
/**
@johnmorris
johnmorris / gist:5477371
Last active May 22, 2019 11:52
How to create an HTML select box from a MySQL results array using PHP.http://youtu.be/rSncrXP0HeU
<?php
$sql = "SELECT * FROM queried_table";
$query = mysql_query($sql);
while ( $results[] = mysql_fetch_object ( $query ) );
array_pop ( $results );
?>
@johnmorris
johnmorris / gist:5477376
Last active May 22, 2019 11:52
Dynamic select box - the HTML. Video tutorial at: http://youtu.be/rSncrXP0HeU
<select name="the_name">
<?php foreach ( $results as $option ) : ?>
<option value="<?php echo $option->desired_value; ?>"><?php echo $option->desired_label; ?></option>
<?php endforeach; ?>
</select>
@johnmorris
johnmorris / gist:5481789
Created April 29, 2013 14:11
How to Create a Custom Loop in WordPress Using WP_Query
<?php
/*** Custom Loop ***/
function demo_loop() {
$args = array(
'cat' => 3,
'posts_per_page' => 1
);
$demo_posts = new WP_Query($args);
@johnmorris
johnmorris / gist:5481857
Created April 29, 2013 14:20
How to Create an ics Import File Using PHP
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
/**
* Get the event ID
*/
$event_id = @$_GET['event_id'];
/**
* If no event ID or event_id is not an integer, do nothing
*/
@johnmorris
johnmorris / gist:5481972
Last active June 13, 2019 07:26
How to Sort Multidimensional Arrays Using PHP
<?php
$arr = array(
array('name' => 'John', 'age' => 30, 'website' => 'http://learnphp.co'),
array('name' => 'Joe', 'age' => 28, 'website' => 'http://johnmorrisonline.com'),
array('name' => 'Amy', 'age' => 32, 'website' => 'http://amy.com'),
array('name' => 'Alex', 'age' => 22, 'website' => 'http://thealex.com'),
array('name' => 'Pat', 'age' => 40, 'website' => 'http://patsjourney.com'),
);
?>
@johnmorris
johnmorris / gist:6306322
Created August 22, 2013 12:02
Move the primary navigation menu to the top of a page using the Genesis theme.
// Child theme setup function
function child_theme_setup() {
// Remove the primary navigation from its current location
remove_action( 'genesis_after_header', 'genesis_do_nav' );
// Add the primary navigation to the top of the page
add_action( 'genesis_before_header', 'genesis_do_nav' );
}
// Hook into genesis_setup
@johnmorris
johnmorris / gist:7851237
Last active September 7, 2016 11:06
This PHP function accepts a birthday as a parameter and will return the age based on that birthday. Handy for social sites/applications.
<?php
// PHP 5.3-
function birthday($birthday){
$age = strtotime($birthday);
if($age === false){
return false;
}
list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age));
@johnmorris
johnmorris / gist:8116213
Created December 24, 2013 17:52
Get the thumbnail source URL in WordPress
function wp_get_thumb_src($post = false, $size = 'thumbnail') {
if ( ! $post ) {
global $post;
}
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), $size );
$url = $thumb['0'];
return $url;
}