Plugin Directory

Changeset 2480114


Ignore:
Timestamp:
02/23/2021 07:15:06 PM (5 years ago)
Author:
bcmdev
Message:

Release 1.0.3

Location:
bcm-duplicate-menu
Files:
9 added
2 edited

Legend:

Unmodified
Added
Removed
  • bcm-duplicate-menu/trunk/bcm-duplicate-menu.php

    r2329531 r2480114  
    55    Description:    The easiest way to duplicate your menu
    66    Author:         BCM.dev
    7     Version:        1.0.2
     7    Version:        1.0.3
    88    Author URI:     http://bcmdev.nl/
    99    License:        GPLv2
     
    4747        {
    4848            $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');
    5050            if ($current_screen->id == 'nav-menus' && $_GET['menu'] != '0') {
    5151                $return = '';
     
    7575                        ?>
    7676                        <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); ?>");
    7878                        </script>
    7979                        <?php
     
    8181                        ?>
    8282                        <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'); ?>");
    8484                        </script>
    8585                        <?php
     
    8989        }
    9090
    91         function duplicate( $id = null, $name = null )
     91        function duplicate($id = null, $name = null)
    9292        {
    9393           
    94             // sanity check
    95             if ( empty( $id ) || empty( $name ) ) {
     94            // Sanity check
     95            if ( empty($id) || empty($name) ) {
    9696                return false;
    9797            }
    9898   
    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            }
    104111 
    105             if ( ! $new_id ) {
     112            if (!$new_id || is_array($new_id)) {
    106113                return false;
    107114            }
    108115   
    109             // key is the original db ID, val is the new
     116            // Key is the original db ID, val is the new
    110117            $rel = array();
    111118   
    112119            $i = 1;
    113             foreach ( $source_items as $menu_item ) {
     120            foreach ($source_items as $menu_item) {
    114121                $args = array(
    115122                    'menu-item-db-id'       => $menu_item->db_id,
     
    128135                );
    129136   
    130                 $parent_id = wp_update_nav_menu_item( $new_id, 0, $args );
     137                $parent_id = wp_update_nav_menu_item($new_id, 0, $args);
    131138   
    132139                $rel[$menu_item->db_id] = $parent_id;
    133140   
    134141                // 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) {
    136143                    $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);
    138145                }
    139146   
    140147                // 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);
    142149   
    143150                $i++;
  • bcm-duplicate-menu/trunk/readme.txt

    r2329519 r2480114  
    11=== Plugin Name ===
    22Contributors: bcmdev
     3Donate link: http://bcmdev.nl/donate.html
    34Tags: duplicate, menu, ClassicPress
    45Requires at least: 4.0
    5 Tested up to: 5.4
    6 Stable tag: 1.0.2
     6Tested up to: 5.7
     7Requires PHP: 5.4
     8Stable tag: 1.0.3
    79License: GPLv2
    810License URI: http://www.gnu.org/licenses/gpl-2.0.html
    911
    10 The easiest way to duplicate your menu
     12This is the easiest way to duplicate your menu
    1113
    1214== Description ==
     
    3739== Changelog ==
    3840
     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
    3944= 1.0.2 (2020-06-23) =
    4045* Improvement: When you click the Duplicate Menu button, a loading icon is now visible.
Note: See TracChangeset for help on using the changeset viewer.