*/ class md_admin_interface { private static $depth_count_var = ''; /** * This function runs when plugin activates. (use period) * * This function executes when plugin activates and object initialised. * * @since 1.0.0 */ /** * wordpress hook called in twise that whay we have made custom logic * */ private $past_revision = true; /* function __construct() {} */ /** * This function runs when menu deleted from the admin page. (use period) * * This function executes when menu deleted from the admin page. * * @since 1.0.0 */ function my_action_ajax_for_delete_menu() { global $wpdb; // this is how you get access to the database $delete_menu_id = intval($_POST['delete_menu_id']); $delete_menu_obj = wp_delete_nav_menu($delete_menu_id); if ($delete_menu_obj) { $nav_menus = wp_get_nav_menus(); if (isset($nav_menus[0]->term_id)) { update_user_meta(get_current_user_id(), 'nav_menu_recently_edited', $nav_menus[0]->term_id); } echo $delete_menu_obj; } wp_die(); // this is required to terminate immediately and return a proper response } /** * amm_save_existing_menu function * * This function is used to save existing menu items. * * @version 1.0.0 * @author Multidots * */ function amm_save_existing_menu($menu_items) { // menu name and setting update check_ajax_referer( 'amm-ajax-nonce', 'amm-ajax-nonce', false ); if (empty($_POST['menu-name'])) { return $messages = '

' . __('Please enter menu name.') . '

'; } /** * get location, menu id, current menu location for save location on menu */ global $wpdb; $current_edit_menu_id = sanitize_text_field( $_REQUEST['current_edit_menu_id'] ); $locations = get_registered_nav_menus(); $menu_locations = get_nav_menu_locations(); $messages = ''; // Remove menu locations that have been unchecked. foreach ($locations as $location => $description) { if (( empty($_POST['menu-locations']) || empty($_POST['menu-locations'][$location]) ) && isset($menu_locations[$location]) && $menu_locations[$location] == $current_edit_menu_id) unset($menu_locations[$location]); } // Merge new and existing menu locations if any new ones are set. if (isset($_POST['menu-locations'])) { $new_menu_locations = array_map('absint', wp_unslash( $_POST['menu-locations'] ) ); $menu_locations = array_merge($menu_locations, $new_menu_locations); } // Set menu locations. set_theme_mod('nav_menu_locations', $menu_locations); //menu title and menu related other option will update $_menu_object = wp_get_nav_menu_object($current_edit_menu_id); $menu_title = trim(sanitize_text_field($_POST['menu-name'])); if (!$menu_title) { $messages = '

' . __('Please enter a valid menu name.') . '

'; $menu_title = $_menu_object->name; } if (!is_wp_error($_menu_object)) { $old_menu_name = sanitize_text_field(( $_POST['old-menu-name'] ) ); if ($old_menu_name != $menu_title) { $menu_exists = wp_get_nav_menu_object($menu_title); if (empty($menu_exists)) { $current_edit_menu_id = wp_update_nav_menu_object($current_edit_menu_id, array('menu-name' => $menu_title)); if (is_wp_error($current_edit_menu_id)) { $_menu_object = $current_edit_menu_id; $messages = '

Please try again later.

'; } else { $nav_menu_selected_title = $_menu_object->name; } } else { return $messages = '

' . $menu_title . ' is already registered.

'; } } else { $nav_menu_selected_title = $_menu_object->name; } } // Update menu items. if (!is_wp_error($_menu_object) && !empty($nav_menu_selected_title)) { $messages_wp = array(); $messages_wp = array_merge($messages_wp, wp_nav_menu_update_menu_items($current_edit_menu_id, $nav_menu_selected_title)); if (!empty($messages_wp)) { foreach ($messages_wp as $mesg) $messages .= $mesg; } } if (!is_wp_error($current_edit_menu_id)) { update_user_meta(get_current_user_id(), 'nav_menu_recently_edited', $current_edit_menu_id); } // End menu name and setting update code $elements = array('menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type'); $menu_items_obj = explode(',', $menu_items); array_pop($menu_items_obj); $menu_item_db_id = ''; if (!empty($_REQUEST['menu-item-db-id'])) $menu_item_db_id = array_values(array_map( 'absint', wp_unslash( $_REQUEST['menu-item-db-id'] ) ) ); $menu_item_db_id_count = is_array($menu_item_db_id) ? count($menu_item_db_id) : '0'; $end = (1 + $menu_item_db_id_count) - 1; $keys = range(1, $end); $deleted_nodes = explode(',', sanitize_text_field( $_REQUEST['delete_menu_items'])); if (!empty($menu_item_db_id)) $menu_item_db_id = array_combine($keys, $menu_item_db_id); $defaults = array( 'menu-item-db-id' => 0, 'menu-item-object-id' => 0, 'menu-item-object' => '', 'menu-item-parent-id' => 0, 'menu-item-position' => 0, 'menu-item-type' => 'custom', 'menu-item-title' => '', 'menu-item-url' => '', 'menu-item-description' => '', 'menu-item-attr-title' => '', 'menu-item-target' => '', 'menu-item-classes' => '', 'menu-item-xfn' => '', 'menu-item-status' => '', ); $args = wp_parse_args($_REQUEST, $defaults); $menu_order_node = 1; $loop_count = 0; if (!empty($args['menu-item-object-id'])) { foreach ($args['menu-item-object-id'] as $key => $value) { $current_post_id = $menu_item_db_id[$menu_order_node]; if (in_array($current_post_id, $deleted_nodes)) { wp_delete_post($current_post_id); delete_post_meta($current_post_id, '_menu_item_type', sanitize_key($args['menu-item-type'][$key])); delete_post_meta($current_post_id, '_menu_item_menu_item_parent', strval((int) $args['menu-item-parent-id'][$key])); delete_post_meta($current_post_id, '_menu_item_object_id', strval((int) $args['menu-item-object-id'][$key])); delete_post_meta($current_post_id, '_menu_item_object', sanitize_key($args['menu-item-object'][$key])); } else { if (isset($args['menu-item-attr-title'][$loop_count])) { $update_my_nav_post = array('ID' => $current_post_id, 'menu_order' => sanitize_key($menu_order_node), 'post_excerpt' => sanitize_key($args['menu-item-attr-title'][$loop_count])); } else { $update_my_nav_post = array('ID' => $current_post_id, 'menu_order' => sanitize_key($menu_order_node)); } wp_update_post($update_my_nav_post); update_post_meta($current_post_id, '_menu_item_type', sanitize_key($args['menu-item-type'][$key])); update_post_meta($current_post_id, '_menu_item_menu_item_parent', strval((int) $args['menu-item-parent-id'][$key])); update_post_meta($current_post_id, '_menu_item_object_id', strval((int) $args['menu-item-object-id'][$key])); update_post_meta($current_post_id, '_menu_item_object', sanitize_key($args['menu-item-object'][$key])); if (!empty($args['menu-item-target'][$key])) update_post_meta($current_post_id, '_menu_item_target', $args['menu-item-target'][$key]); } $menu_order_node++; $loop_count++; } // Foreach close } unset($deleted_nodes); return $messages; } // Function close /** * my_action_ajax_for_create_menu function * * This function will add your newly entered menu name in textbox. * * @version 1.0.0 * @author Multidots */ function my_action_ajax_for_create_menu() { // Check if the menu exists $menu_name = sanitize_text_field( $_POST['new_menu_name'] ); $menu_exists = wp_get_nav_menu_object($menu_name); // If it doesn't exist, let's create it. if (!$menu_exists) { $menu_id = wp_create_nav_menu($menu_name); $user_details = wp_get_current_user(); update_user_meta($user_details->ID, 'nav_menu_recently_edited', $menu_id); echo 1; } else { /* New menu allreday there */ echo 2; } exit(); } // function for dotstore function menu_container_print_custom() { global $gloable_all_author_array; global $gloable_all_template_array; global $gloable_all_category_array; global $gloable_all_current_menu_id; //set all author globally $allUsers = get_users('orderby=ID&order=ASC'); foreach ($allUsers as $currentUser) { if (!in_array('subscriber', $currentUser->roles)) { $gloable_all_author_array[] = $currentUser; } } // set all template globaly $get_templates_all = get_page_templates(); foreach ($get_templates_all as $template_name => $template_filename) { $gloable_all_template_array[$template_name] = $template_filename; } // set all category by globaly $all_category = get_categories('orderby=name&hide_empty=0'); foreach ($all_category as $cat_data) { $gloable_all_category_array[$cat_data->cat_ID] = $cat_data->cat_name; } $form_submited_messages = isset($_REQUEST ['save_menu']) ? md_admin_interface::amm_save_existing_menu($_REQUEST ['total_menu_items']) : false; wp_nav_menu_post_type_meta_boxes(); wp_nav_menu_taxonomy_meta_boxes(); wp_enqueue_script('nav-menu'); if (wp_is_mobile()) wp_enqueue_script('jquery-touch-punch'); $nav_menu_selected_id = isset($_REQUEST['menu']) ? (int) $_REQUEST['menu'] : 0; // Get recently edited nav menu. $recently_edited = absint(get_user_option('nav_menu_recently_edited')); if (empty($recently_edited) && is_nav_menu($nav_menu_selected_id)) $recently_edited = $nav_menu_selected_id; // Use $recently_edited if none are selected. if (empty($nav_menu_selected_id) && !isset($_GET['menu']) && is_nav_menu($recently_edited)) $nav_menu_selected_id = $recently_edited; if (empty($nav_menu_selected_id) && !empty($nav_menus) && !$add_new_screen) { // if we have no selection yet, and we have menus, set to the first one in the list. $nav_menu_selected_id = $nav_menus[0]->term_id; } // Update the user's setting. if ($nav_menu_selected_id != $recently_edited && is_nav_menu($nav_menu_selected_id)) update_user_meta(get_current_user_id(), 'nav_menu_recently_edited', $nav_menu_selected_id); //if menu hase change on dropdwon and save menu than recently menu option will update if (!empty($_POST['page_on_front'])) { $nav_menu_selected_id = (int) $_POST['page_on_front']; $user_id = get_current_user_id(); update_user_meta($user_id, 'nav_menu_recently_edited', $nav_menu_selected_id); } $locations = get_registered_nav_menus(); $menu_locations = get_nav_menu_locations(); $num_locations = count(array_keys($locations)); //submit themes location form if (isset($_GET['action']) && 'locations' == $_GET['action'] && isset($_POST['menu-locations'])) { if (isset($_POST['menu-locations'])) { check_admin_referer('save-menu-locations'); $new_menu_locations = array_map('absint', $_POST['menu-locations']); $menu_locations = array_merge($menu_locations, $new_menu_locations); // Set menu locations set_theme_mod('nav_menu_locations', $menu_locations); $messages[] = '

' . __('Menu locations updated.') . '

'; } } $menu_revision_tab = ''; if (isset($_GET['action']) && 'locations' == $_GET['action']) { $menu_location_flag = sanitize_text_field( $_GET['action'] ); } else { $menu_location_flag = ''; } $locations_screen = ( isset($_GET['action']) && 'locations' == $_GET['action'] ) ? true : false; // Get all nav menus. $nav_menus = wp_get_nav_menus(); $menu_count = count($nav_menus); wp_nav_menu_setup(); wp_initial_nav_menu_meta_boxes(); wp_enqueue_script('fancy-alert', esc_url( PLUGIN_PATH . 'js/fancy_alert.js' ), array('jquery'), false); wp_enqueue_script('md-pagination', esc_url( PLUGIN_PATH . 'js/md_pagination.js' ), array('jquery'), false); ?>
' . __('Your theme supports one menu. Select which menu you would like to use.') . '

'; } else { echo '

' . sprintf(_n('Your theme supports %s menu. Select which menu appears in each location.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations), number_format_i18n($num_locations)) . '

'; } ?>
>
>