*/ /** * Nav menu admin */ final class Menu_Icons_Picker { /** * Initialize class * * @since 0.1.0 */ public static function init() { add_action( 'load-nav-menus.php', array( __CLASS__, '_load_nav_menus' ) ); add_filter( 'wp_edit_nav_menu_walker', array( __CLASS__, '_filter_wp_edit_nav_menu_walker' ), 99 ); add_filter( 'wp_nav_menu_item_custom_fields', array( __CLASS__, '_fields' ), 10, 4 ); add_filter( 'manage_nav-menus_columns', array( __CLASS__, '_columns' ), 99 ); add_action( 'wp_update_nav_menu_item', array( __CLASS__, '_save' ), 10, 3 ); add_filter( 'icon_picker_type_props', array( __CLASS__, '_add_extra_type_props_data' ), 10, 3 ); } /** * Load Icon Picker * * @since 0.9.0 * @wp_hook action load-nav-menus.php */ public static function _load_nav_menus() { Icon_Picker::instance()->load(); add_action( 'print_media_templates', array( __CLASS__, '_media_templates' ) ); } /** * Custom walker * * @since 0.3.0 * @access protected * @wp_hook filter wp_edit_nav_menu_walker */ public static function _filter_wp_edit_nav_menu_walker( $walker ) { // Load menu item custom fields plugin if ( ! class_exists( 'Menu_Item_Custom_Fields_Walker' ) ) { require_once Menu_Icons::get( 'dir' ) . 'includes/library/menu-item-custom-fields/walker-nav-menu-edit.php'; } $walker = 'Menu_Item_Custom_Fields_Walker'; return $walker; } /** * Get menu item setting fields * * @since 0.9.0 * @access protected * @param array $meta Menu item meta value. * @return array */ protected static function _get_menu_item_fields( $meta ) { $fields = array_merge( array( array( 'id' => 'type', 'label' => __( 'Type', 'menu-icons' ), 'value' => $meta['type'], ), array( 'id' => 'icon', 'label' => __( 'Icon', 'menu-icons' ), 'value' => $meta['icon'], ), ), Menu_Icons_Settings::get_settings_fields( $meta ) ); return $fields; } /** * Print fields * * @since 0.1.0 * @access protected * @uses add_action() Calls 'menu_icons_before_fields' hook * @uses add_action() Calls 'menu_icons_after_fields' hook * @wp_hook action menu_item_custom_fields * * @param object $item Menu item data object. * @param int $depth Nav menu depth. * @param array $args Menu item args. * @param int $id Nav menu ID. * * @return string Form fields */ public static function _fields( $id, $item, $depth, $args ) { $input_id = sprintf( 'menu-icons-%d', $item->ID ); $input_name = sprintf( 'menu-icons[%d]', $item->ID ); $menu_settings = Menu_Icons_Settings::get_menu_settings( Menu_Icons_Settings::get_current_menu_id() ); $meta = Menu_Icons_Meta::get( $item->ID, $menu_settings ); $fields = self::_get_menu_item_fields( $meta ); ?>
id ) { return; } check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); // Sanitize if ( ! empty( $_POST['menu-icons'][ $menu_item_db_id ] ) ) { $value = array_map( 'sanitize_text_field', wp_unslash( (array) $_POST['menu-icons'][ $menu_item_db_id ] ) ); } else { $value = array(); } Menu_Icons_Meta::update( $menu_item_db_id, $value ); } /** * Get and print media templates from all types * * @since 0.2.0 * @since 0.9.0 Deprecate menu_icons_media_templates filter. * @wp_hook action print_media_templates */ public static function _media_templates() { $id_prefix = 'tmpl-menu-icons'; // Deprecated. $templates = apply_filters( 'menu_icons_media_templates', array() ); if ( ! empty( $templates ) ) { if ( WP_DEBUG ) { _deprecated_function( 'menu_icons_media_templates', '0.9.0', 'menu_icons_js_templates' ); } foreach ( $templates as $key => $template ) { $id = sprintf( '%s-%s', $id_prefix, $key ); self::_print_tempate( $id, $template ); } } require_once dirname( __FILE__ ) . '/media-template.php'; } /** * Print media template * * @since 0.2.0 * @param string $id Template ID. * @param string $template Media template HTML. */ protected static function _print_tempate( $id, $template ) { ?>