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