*/ class Atr_Advanced_Menu_Walker_Edit_Fields { // Load API for media loader function atr_am_load_wp_media_files() { // Check if wp_enqueue_media is already loaded. (Otherwise, media will not worl on posts/pages edit) if ( did_action( 'wp_enqueue_media' ) ) { return; } else { wp_enqueue_media(); } } //$this->loader->add_action('load_wp_media_files', $plugin_edit_menu_fields, 'atr_am_load_wp_media_files', 11, 4); //add_action('load_wp_media_files', array($this->atr_am_load_wp_media_files()) 'atr_am_load_wp_media_files', 11, 4); /** * Add fields to hook added in Walker * This will allow us to play nicely with any other plugin that is adding the same hook * @params obj $item - the menu item * @params array $args * @since 1.0.0 */ public function custom_fields($item_id, $item, $depth, $args) { /* New fields insertion starts here */ ?>

 





* to validate both fa fa-info, * Because sanitize_html_class doesn't allow spaces. * * @uses sanitize_html_class * @param (mixed: string/array) $class "blue hedgehog goes shopping" or array("blue", "hedgehog", "goes", "shopping") * @param (mixed) $fallback Anything you want returned in case of a failure * @return (mixed: string / $fallback ) */ public function sanitize_html_classes($class, $fallback = null) { // Explode it, if it's a string if (is_string($class)) { $class = explode(" ", $class); } if (is_array($class) && count($class) > 0) { $class = array_map("sanitize_html_class", $class); return implode(" ", $class); } else { return sanitize_html_class($class, $fallback); } } /** * Add custom fields to $item nav object * in order to be used in custom Walker * * @access public * @since 1.0 * @return void */ function atr_am_add_custom_nav_fields($menu_item) { $menu_item->subtitle = sanitize_text_field(get_post_meta($menu_item->ID, '_menu_item_subtitle', true)); $menu_item->customimage = esc_url(get_post_meta($menu_item->ID, '_menu_item_customimage', true)); $menu_item->chooseimage = esc_attr(get_post_meta($menu_item->ID, '_menu_item_chooseimage', true)); $menu_item->panelclass = sanitize_html_classes(get_post_meta($menu_item->ID, '_menu_item_panelclass', true)); $menu_item->iconclass = sanitize_html_classes(get_post_meta($menu_item->ID, '_menu_item_iconclass', true)); $menu_item->content_from_post = intval(get_post_meta($menu_item->ID, '_menu_item_content_from_post', true)); $menu_item->remttl = get_post_meta($menu_item->ID, '_menu_item_remttl', true); $menu_item->postexcerpt = get_post_meta($menu_item->ID, '_menu_item_postexcerpt', true); $menu_item->postfeatimg = get_post_meta($menu_item->ID, '_menu_item_postfeatimg', true); return $menu_item; } /** * Save menu custom fields * * @access public * @since 1.0 * @return void */ function atr_am_update_custom_nav_fields($menu_id, $menu_item_db_id, $args) { // Check if we are in wp customizer mod. // When in customizer mod, we do not want to update any custom field because it will set wrong values (the fields are not present in this mode). // See http://wordpress.stackexchange.com/questions/58731/way-to-check-if-we-are-in-theme-customizer-mode // And http://wordpress.stackexchange.com/questions/55227/how-to-execute-conditional-script-when-on-new-customize-php-theme-customize-sc global $wp_customize; if (!isset($wp_customize)) { // Update menu custom fields if (isset($_POST['menu-item-subtitle' . $menu_item_db_id])) { if (is_array($_POST['menu-item-subtitle'])) { $subtitle_value = sanitize_text_field($_POST['menu-item-subtitle'][$menu_item_db_id]); update_post_meta($menu_item_db_id, '_menu_item_subtitle', $subtitle_value); } } if (isset($_POST['menu-item-customimage' . $menu_item_db_id])) { if (is_array($_POST[''])) { $customimage_value = esc_url_raw($_POST['menu-item-customimage'][$menu_item_db_id]); update_post_meta($menu_item_db_id, '_menu_item_customimage', $customimage_value); } } $chooseimage_value = ''; if (isset($_POST['menu-item-chooseimage' . $menu_item_db_id])) { if (is_array($_POST['menu-item-chooseimage' . $menu_item_db_id])) { $chooseimage_value = implode(",", $_POST['menu-item-chooseimage' . $menu_item_db_id]); } } else { $chooseimage_value = "0"; } update_post_meta($menu_item_db_id, '_menu_item_chooseimage', intval($chooseimage_value)); if (isset($_POST['menu-item-panelclass' . $menu_item_db_id])) { if (is_array($_POST['menu-item-panelclass'])) { $panelclass_value = sanitize_html_classes($_POST['menu-item-panelclass'][$menu_item_db_id]); update_post_meta($menu_item_db_id, '_menu_item_panelclass', $panelclass_value); } } if (isset($_POST['menu-item-iconclass' . $menu_item_db_id])) { if (is_array($_POST['menu-item-iconclass'])) { $iconclass_value = sanitize_html_classes($_POST['menu-item-iconclass'][$menu_item_db_id]); update_post_meta($menu_item_db_id, '_menu_item_iconclass', $iconclass_value); } } if (isset($_POST['menu-item-content-from-post' . $menu_item_db_id])) { if (is_array($_POST['menu-item-content-from-post'])) { //$content_from_post_value = $_POST['menu-item-content-from-post'][$menu_item_db_id]; $content_from_post_value = (!empty($_POST['menu-item-content-from-post'][$menu_item_db_id])) ? intval($_POST['menu-item-content-from-post'][$menu_item_db_id]) : ''; update_post_meta($menu_item_db_id, '_menu_item_content_from_post', $content_from_post_value); } } if (isset($_POST['menu-item-remttl' . $menu_item_db_id])) { if (is_array($_POST['menu-item-remttl'])) { $remttl_value = $_POST['menu-item-remttl'][$menu_item_db_id]; // $_POST['menu-item-remttl'] = 'remove-title' update_post_meta($menu_item_db_id, '_menu_item_remttl', sanitize_text_field($remttl_value)); } } if (isset($_POST['menu-item-postexcerpt' . $menu_item_db_id])) { if (is_array($_POST['menu-item-postexcerpt'])) { $postexcerpt_value = $_POST['menu-item-postexcerpt'][$menu_item_db_id]; // $_POST['menu-item-postexcerpt'] = 'use-excerpt' update_post_meta($menu_item_db_id, '_menu_item_postexcerpt', $postexcerpt_value); } } if (isset($_POST['menu-item-postfeatimg' . $menu_item_db_id])) { if (is_array($_POST['menu-item-postfeatimg'])) { $postfeatimg_value = $_POST['menu-item-postfeatimg'][$menu_item_db_id];// $_POST['menu-item-postfeatimg'] = 'use-post-feat' update_post_meta($menu_item_db_id, '_menu_item_postfeatimg', $postfeatimg_value); } } } } /** * Define new Walker edit * * @access public * @since 1.0 * @return void */ function atr_am_edit_walker($walker, $menu_id) { return 'Walker_Nav_Menu_Edit_Custom'; } }