Skip to content

Instantly share code, notes, and snippets.

@atwellpub
Created May 28, 2014 23:52
Show Gist options
  • Save atwellpub/ced50d0faee9563e1d20 to your computer and use it in GitHub Desktop.
Save atwellpub/ced50d0faee9563e1d20 to your computer and use it in GitHub Desktop.
WordPress Plugin - Print Nav Menu - API
<?php
/*
Plugin Name: Print Nav Menu API
Plugin URI: http://www.inboundnow.com/landing-pages/
Description: Listens for nav menu requests and returns html content
Version: 1.0.1
Author: Hudson Atwell
Author URI: http://www.hudsonatwell.co
*/
class WP_Print_Nav_Menu {
public function __construct() {
self::add_hooks();
}
public static function add_hooks() {
add_action('init' , array( __CLASS__ , 'add_listener') );
}
public static function add_listener() {
if ( !isset($_GET['print_nav_js']) ) {
return;
}
header("Access-Control-Allow-Origin: *");
$defaults = array(
'menu' => urldecode($_GET['menu']),
'container' => 'div',
'container_class' => '',
'container_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
);
if ( isset($_GET['walker']) ) {
$defaults['walker'] = new $_GET['walker'];
}
if ( isset($_GET['depth']) ) {
$defaults['depth'] = new $_GET['depth'];
}
if ( isset($_GET['items_wrap']) ) {
$defaults['items_wrap'] = new $_GET['items_wrap'];
}
if ( isset($_GET['link_before']) ) {
$defaults['link_before'] = new $_GET['link_before'];
}
if ( isset($_GET['link_after']) ) {
$defaults['link_after'] = new $_GET['link_after'];
}
if ( isset($_GET['before']) ) {
$defaults['before'] = new $_GET['before'];
}
if ( isset($_GET['after']) ) {
$defaults['after'] = new $_GET['after'];
}
if ( isset($_GET['menu_id']) ) {
$defaults['menu_id'] = new $_GET['menu_id'];
}
if ( isset($_GET['menu_class']) ) {
$defaults['menu_class'] = new $_GET['menu_class'];
}
if ( isset($_GET['container_id']) ) {
$defaults['container_id'] = new $_GET['container_id'];
}
if ( isset($_GET['container_class']) ) {
$defaults['container_class'] = new $_GET['container_class'];
}
wp_nav_menu( $defaults );
exit;
}
}
$GLOBALS['WP_Print_Nav_Menu'] = new WP_Print_Nav_Menu;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment