| 1 |
<?php |
| 2 |
/** |
| 3 |
* Create a set of Users WP specific links for use in the Menus admin UI. |
| 4 |
* |
| 5 |
* @link http://wpgeodirectory.com |
| 6 |
* @since 1.0.0 |
| 7 |
* |
| 8 |
* @package userswp |
| 9 |
* @subpackage userswp/admin/menus |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
defined( 'ABSPATH' ) || exit; |
| 14 |
|
| 15 |
/** |
| 16 |
* Create a set of Users WP specific links for use in the Menus admin UI. |
| 17 |
* |
| 18 |
* Borrowed heavily from {@link Walker_Nav_Menu_Checklist}, but modified so as not |
| 19 |
* to require an actual post type or taxonomy, and to force certain CSS classes. |
| 20 |
* |
| 21 |
* @since 1.0.0 |
| 22 |
*/ |
| 23 |
class UsersWP_Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { |
| 24 |
|
| 25 |
/** |
| 26 |
* Constructor. |
| 27 |
* |
| 28 |
* @see Walker_Nav_Menu::__construct() for a description of parameters. |
| 29 |
* |
| 30 |
* @param array|bool $fields See {@link Walker_Nav_Menu::__construct()}. |
| 31 |
*/ |
| 32 |
public function __construct( $fields = false ) { |
| 33 |
if ( $fields ) { |
| 34 |
$this->db_fields = $fields; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Create the markup to start a tree level. |
| 40 |
* |
| 41 |
* @see Walker_Nav_Menu::start_lvl() for description of parameters. |
| 42 |
* |
| 43 |
* @param string $output See {@Walker_Nav_Menu::start_lvl()}. |
| 44 |
* @param int $depth See {@Walker_Nav_Menu::start_lvl()}. |
| 45 |
* @param array $args See {@Walker_Nav_Menu::start_lvl()}. |
| 46 |
*/ |
| 47 |
public function start_lvl( &$output, $depth = 0, $args = array() ) { |
| 48 |
$indent = str_repeat( "\t", $depth ); |
| 49 |
$output .= "\n$indent<ul class='children'>\n"; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Create the markup to end a tree level. |
| 54 |
* |
| 55 |
* @see Walker_Nav_Menu::end_lvl() for description of parameters. |
| 56 |
* |
| 57 |
* @param string $output See {@Walker_Nav_Menu::end_lvl()}. |
| 58 |
* @param int $depth See {@Walker_Nav_Menu::end_lvl()}. |
| 59 |
* @param array $args See {@Walker_Nav_Menu::end_lvl()}. |
| 60 |
*/ |
| 61 |
public function end_lvl( &$output, $depth = 0, $args = array() ) { |
| 62 |
$indent = str_repeat( "\t", $depth ); |
| 63 |
$output .= "\n$indent</ul>"; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Create the markup to start an element. |
| 68 |
* |
| 69 |
* @see Walker::start_el() for description of parameters. |
| 70 |
* |
| 71 |
* @param string $output Passed by reference. Used to append additional |
| 72 |
* content. |
| 73 |
* @param object $item Menu item data object. |
| 74 |
* @param int $depth Depth of menu item. Used for padding. |
| 75 |
* @param object|array $args See {@Walker::start_el()}. |
| 76 |
* @param int $id See {@Walker::start_el()}. |
| 77 |
*/ |
| 78 |
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
| 79 |
|
| 80 |
global $_nav_menu_placeholder; |
| 81 |
|
| 82 |
$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; |
| 83 |
$possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder; |
| 84 |
$possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0; |
| 85 |
|
| 86 |
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; |
| 87 |
|
| 88 |
$output .= $indent . '<li>'; |
| 89 |
$output .= '<label class="menu-item-title">'; |
| 90 |
$output .= '<input type="checkbox" class="menu-item-checkbox'; |
| 91 |
|
| 92 |
if ( property_exists( $item, 'label' ) ) { |
| 93 |
$title = $item->label; |
| 94 |
} |
| 95 |
|
| 96 |
$output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> '; |
| 97 |
$output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title ); |
| 98 |
$output .= '</label>'; |
| 99 |
|
| 100 |
if ( empty( $item->url ) ) { |
| 101 |
$item->url = $item->guid; |
| 102 |
} |
| 103 |
|
| 104 |
if ( ! in_array( array( 'users-wp-menu', 'users-wp-'. $item->post_excerpt .'-nav' ), $item->classes ) ) { |
| 105 |
$item->classes[] = 'users-wp-menu'; |
| 106 |
$item->classes[] = 'users-wp-'. $item->post_excerpt .'-nav'; |
| 107 |
} |
| 108 |
|
| 109 |
// maybe add a specific lightbox class |
| 110 |
if ( isset($item->lightbox_class) && ! in_array( $item->lightbox_class , $item->classes ) ) { |
| 111 |
$item->classes[] = $item->lightbox_class; |
| 112 |
} |
| 113 |
|
| 114 |
// Menu item hidden fields. |
| 115 |
$output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />'; |
| 116 |
$output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />'; |
| 117 |
$output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. esc_attr( $item->menu_item_parent ) .'" />'; |
| 118 |
$output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="custom" />'; |
| 119 |
$output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />'; |
| 120 |
$output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />'; |
| 121 |
$output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />'; |
| 122 |
$output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />'; |
| 123 |
$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />'; |
| 124 |
$output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />'; |
| 125 |
} |
| 126 |
} |
| 127 |
|