Changeset 2480114
- Timestamp:
- 02/23/2021 07:15:06 PM (5 years ago)
- Location:
- bcm-duplicate-menu
- Files:
-
- 9 added
- 2 edited
-
tags/1.0.3 (added)
-
tags/1.0.3/bcm-duplicate-menu.php (added)
-
tags/1.0.3/languages (added)
-
tags/1.0.3/languages/bcm-duplicate-menu-nl_NL.mo (added)
-
tags/1.0.3/languages/bcm-duplicate-menu-nl_NL.po (added)
-
tags/1.0.3/languages/bcm-duplicate-menu-nl_NL_formal.mo (added)
-
tags/1.0.3/languages/bcm-duplicate-menu-nl_NL_formal.po (added)
-
tags/1.0.3/languages/bcm-duplicate-menu.pot (added)
-
tags/1.0.3/readme.txt (added)
-
trunk/bcm-duplicate-menu.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bcm-duplicate-menu/trunk/bcm-duplicate-menu.php
r2329531 r2480114 5 5 Description: The easiest way to duplicate your menu 6 6 Author: BCM.dev 7 Version: 1.0. 27 Version: 1.0.3 8 8 Author URI: http://bcmdev.nl/ 9 9 License: GPLv2 … … 47 47 { 48 48 $current_screen = get_current_screen(); 49 $current_menu = get_user_option ( 'nav_menu_recently_edited');49 $current_menu = get_user_option ('nav_menu_recently_edited'); 50 50 if ($current_screen->id == 'nav-menus' && $_GET['menu'] != '0') { 51 51 $return = ''; … … 75 75 ?> 76 76 <script type="text/javascript"> 77 window.location.replace("<?php echo admin_url( 'nav-menus.php?action=edit&menu='.$duplicate); ?>");77 window.location.replace("<?php echo admin_url('nav-menus.php?action=edit&menu='.$duplicate); ?>"); 78 78 </script> 79 79 <?php … … 81 81 ?> 82 82 <script type="text/javascript"> 83 window.location.replace("<?php echo admin_url( 'nav-menus.php'); ?>");83 window.location.replace("<?php echo admin_url('nav-menus.php'); ?>"); 84 84 </script> 85 85 <?php … … 89 89 } 90 90 91 function duplicate( $id = null, $name = null)91 function duplicate($id = null, $name = null) 92 92 { 93 93 94 // sanity check95 if ( empty( $id ) || empty( $name) ) {94 // Sanity check 95 if ( empty($id) || empty($name) ) { 96 96 return false; 97 97 } 98 98 99 $id = intval( $id ); 100 $name = sanitize_text_field( $name ); 101 $source = wp_get_nav_menu_object( $id ); 102 $source_items = wp_get_nav_menu_items( $id ); 103 $new_id = wp_create_nav_menu( $name ); 99 $id = intval($id); 100 $name = sanitize_text_field($name); 101 $source = wp_get_nav_menu_object($id); 102 $source_items = wp_get_nav_menu_items($id); 103 104 $menu_exists = wp_get_nav_menu_object($name); 105 106 if (!$menu_exists) { 107 $new_id = wp_create_nav_menu($name); 108 } else { 109 $new_id = $this->duplicate($id, $name . ' ' . __('(Copy)', 'bcm-duplicate-menu')); 110 } 104 111 105 if ( ! $new_id) {112 if (!$new_id || is_array($new_id)) { 106 113 return false; 107 114 } 108 115 109 // key is the original db ID, val is the new116 // Key is the original db ID, val is the new 110 117 $rel = array(); 111 118 112 119 $i = 1; 113 foreach ( $source_items as $menu_item) {120 foreach ($source_items as $menu_item) { 114 121 $args = array( 115 122 'menu-item-db-id' => $menu_item->db_id, … … 128 135 ); 129 136 130 $parent_id = wp_update_nav_menu_item( $new_id, 0, $args);137 $parent_id = wp_update_nav_menu_item($new_id, 0, $args); 131 138 132 139 $rel[$menu_item->db_id] = $parent_id; 133 140 134 141 // did it have a parent? if so, we need to update with the NEW ID 135 if ( $menu_item->menu_item_parent) {142 if ($menu_item->menu_item_parent) { 136 143 $args['menu-item-parent-id'] = $rel[$menu_item->menu_item_parent]; 137 $parent_id = wp_update_nav_menu_item( $new_id, $parent_id, $args);144 $parent_id = wp_update_nav_menu_item($new_id, $parent_id, $args); 138 145 } 139 146 140 147 // allow developers to run any custom functionality they'd like 141 do_action( 'duplicate_menu_item', $menu_item, $args);148 do_action('duplicate_menu_item', $menu_item, $args); 142 149 143 150 $i++; -
bcm-duplicate-menu/trunk/readme.txt
r2329519 r2480114 1 1 === Plugin Name === 2 2 Contributors: bcmdev 3 Donate link: http://bcmdev.nl/donate.html 3 4 Tags: duplicate, menu, ClassicPress 4 5 Requires at least: 4.0 5 Tested up to: 5.4 6 Stable tag: 1.0.2 6 Tested up to: 5.7 7 Requires PHP: 5.4 8 Stable tag: 1.0.3 7 9 License: GPLv2 8 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 11 10 Th e easiest way to duplicate your menu12 This is the easiest way to duplicate your menu 11 13 12 14 == Description == … … 37 39 == Changelog == 38 40 41 = 1.0.3 (2021-02-23) = 42 * Bugfix: An error could occur when you try to duplicate a menu that was already duplicated before. 43 39 44 = 1.0.2 (2020-06-23) = 40 45 * Improvement: When you click the Duplicate Menu button, a loading icon is now visible.
Note: See TracChangeset
for help on using the changeset viewer.