|
<?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; |