-
Notifications
You must be signed in to change notification settings - Fork 35
/
menu-item-custom-fields.php
61 lines (54 loc) · 1.57 KB
/
menu-item-custom-fields.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Menu Item Custom Fields
*
* @package Menu_Item_Custom_Fields
* @version 1.0.0
* @author Dzikri Aziz <[email protected]>
*
* Plugin name: Menu Item Custom Fields
* Plugin URI: https://github.com/kucrut/wp-menu-item-custom-fields
* Description: Easily add custom fields to nav menu items.
* Version: 1.0.0
* Author: Dzikri Aziz
* Author URI: https://kucrut.org/
* License: GPLv2
* Text Domain: menu-item-custom-fields
*/
if ( ! class_exists( 'Menu_Item_Custom_Fields' ) ) :
/**
* Menu Item Custom Fields Loader
*/
class Menu_Item_Custom_Fields {
/**
* Add filter
*
* @wp_hook action wp_loaded
*/
public static function load() {
add_filter( 'wp_edit_nav_menu_walker', array( __CLASS__, '_filter_walker' ), 99 );
}
/**
* Replace default menu editor walker with ours
*
* We don't actually replace the default walker. We're still using it and
* only injecting some HTMLs.
*
* @since 0.1.0
* @access private
* @wp_hook filter wp_edit_nav_menu_walker
* @param string $walker Walker class name
* @return string Walker class name
*/
public static function _filter_walker( $walker ) {
$walker = 'Menu_Item_Custom_Fields_Walker';
if ( ! class_exists( $walker ) ) {
require_once dirname( __FILE__ ) . '/walker-nav-menu-edit.php';
}
return $walker;
}
}
add_action( 'wp_loaded', array( 'Menu_Item_Custom_Fields', 'load' ), 9 );
endif; // class_exists( 'Menu_Item_Custom_Fields' )
// Uncomment the following line to test this plugin
#require_once dirname( __FILE__ ) . '/doc/menu-item-custom-fields-example.php';