Version Description
- Added
duplicate_menu_itemaction, allowing devs to bolt on custom functionality
Download this release
Release Info
| Developer | jchristopher |
| Plugin | |
| Version | 0.2 |
| Comparing to | |
| See all releases | |
Code changes from version 0.1.1 to 0.2
- duplicate-menu.php +29 -42
- readme.md +14 -7
- readme.txt +6 -3
duplicate-menu.php
CHANGED
|
@@ -5,11 +5,11 @@ Plugin Name: Duplicate Menu
|
|
| 5 |
Plugin URI: https://github.com/jchristopher/duplicate-menu
|
| 6 |
Description: Easily duplicate your WordPress Menus
|
| 7 |
Author: Jonathan Christopher
|
| 8 |
-
Version: 0.
|
| 9 |
Author URI: http://mondaybynoon.com
|
| 10 |
*/
|
| 11 |
|
| 12 |
-
/* Copyright 2011
|
| 13 |
|
| 14 |
This program is free software; you can redistribute it and/or modify
|
| 15 |
it under the terms of the GNU General Public License as published by
|
|
@@ -26,57 +26,43 @@ Author URI: http://mondaybynoon.com
|
|
| 26 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 27 |
*/
|
| 28 |
|
| 29 |
-
|
| 30 |
-
// constant definitions
|
| 31 |
-
if( !defined( 'IS_ADMIN' ) )
|
| 32 |
-
define( 'IS_ADMIN', is_admin() );
|
| 33 |
-
|
| 34 |
-
define( 'DUPLICATE_MENU_VERSION', '0.1.1' );
|
| 35 |
define( 'DUPLICATE_MENU_DIR', plugin_dir_path( __FILE__ ) );
|
| 36 |
define( 'DUPLICATE_MENU_URL', plugin_dir_url( __FILE__ ) );
|
| 37 |
|
| 38 |
-
function duplicate_menu_options_page()
|
| 39 |
-
{
|
| 40 |
add_theme_page( 'Duplicate Menu', 'Duplicate Menu', 'manage_options', 'duplicate-menu', array( 'DuplicateMenu', 'options_screen' ) );
|
| 41 |
}
|
| 42 |
|
| 43 |
-
|
| 44 |
-
if( IS_ADMIN )
|
| 45 |
-
{
|
| 46 |
-
add_action( 'admin_menu', 'duplicate_menu_options_page' );
|
| 47 |
-
|
| 48 |
-
}
|
| 49 |
|
| 50 |
/**
|
| 51 |
* Duplicate Menu
|
| 52 |
*/
|
| 53 |
-
class DuplicateMenu
|
| 54 |
-
{
|
| 55 |
-
|
| 56 |
-
function duplicate( $id = null, $name = null )
|
| 57 |
-
{
|
| 58 |
-
// sanity check
|
| 59 |
-
if( empty( $id ) || empty( $name ) )
|
| 60 |
-
return false;
|
| 61 |
|
| 62 |
-
|
| 63 |
-
$name = sanitize_text_field( $name );
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
$new_id = wp_create_nav_menu( $name );
|
| 69 |
|
| 70 |
-
if(
|
| 71 |
return false;
|
|
|
|
| 72 |
|
| 73 |
// key is the original db ID, val is the new
|
| 74 |
$rel = array();
|
| 75 |
|
| 76 |
$i = 1;
|
| 77 |
-
foreach( $source_items as $menu_item )
|
| 78 |
-
{
|
| 79 |
-
|
| 80 |
$args = array(
|
| 81 |
'menu-item-db-id' => $menu_item->db_id,
|
| 82 |
'menu-item-object-id' => $menu_item->object_id,
|
|
@@ -98,27 +84,28 @@ class DuplicateMenu
|
|
| 98 |
$rel[$menu_item->db_id] = $parent_id;
|
| 99 |
|
| 100 |
// did it have a parent? if so, we need to update with the NEW ID
|
| 101 |
-
if( $menu_item->menu_item_parent )
|
| 102 |
-
{
|
| 103 |
$args['menu-item-parent-id'] = $rel[$menu_item->menu_item_parent];
|
| 104 |
$parent_id = wp_update_nav_menu_item( $new_id, $parent_id, $args );
|
| 105 |
}
|
| 106 |
|
|
|
|
|
|
|
|
|
|
| 107 |
$i++;
|
| 108 |
}
|
| 109 |
|
| 110 |
return $new_id;
|
| 111 |
}
|
| 112 |
|
| 113 |
-
function options_screen()
|
| 114 |
-
{
|
| 115 |
$nav_menus = wp_get_nav_menus();
|
| 116 |
?>
|
| 117 |
<div class="wrap">
|
| 118 |
<div id="icon-options-general" class="icon32"><br /></div>
|
| 119 |
<h2><?php _e( 'Duplicate Menu' ); ?></h2>
|
| 120 |
|
| 121 |
-
<?php if( !empty( $_POST ) && wp_verify_nonce( $_POST['duplicate_menu_nonce'], 'duplicate_menu' ) ) : ?>
|
| 122 |
<?php
|
| 123 |
$source = intval( $_POST['source'] );
|
| 124 |
$destination = sanitize_text_field( $_POST['new_menu_name'] );
|
|
@@ -129,8 +116,8 @@ class DuplicateMenu
|
|
| 129 |
?>
|
| 130 |
|
| 131 |
<div id="message" class="updated"><p>
|
| 132 |
-
<?php if( $new_menu_id ) : ?>
|
| 133 |
-
<?php _e( 'Menu Duplicated' ) ?>. <a href="nav-menus.php?action=edit&menu=<?php echo $new_menu_id; ?>"><?php _e( 'View' ) ?></a>
|
| 134 |
<?php else: ?>
|
| 135 |
<?php _e( 'There was a problem duplicating your menu. No action was taken.' ) ?>.
|
| 136 |
<?php endif; ?>
|
|
@@ -139,7 +126,7 @@ class DuplicateMenu
|
|
| 139 |
<?php endif; ?>
|
| 140 |
|
| 141 |
|
| 142 |
-
<?php if( empty( $nav_menus ) ) : ?>
|
| 143 |
<p><?php _e( "You haven't created any Menus yet." ); ?></p>
|
| 144 |
<?php else: ?>
|
| 145 |
<form method="post" action="">
|
|
@@ -151,7 +138,7 @@ class DuplicateMenu
|
|
| 151 |
</th>
|
| 152 |
<td>
|
| 153 |
<select name="source">
|
| 154 |
-
<?php foreach( (array) $nav_menus as $_nav_menu ) : ?>
|
| 155 |
<option value="<?php echo esc_attr($_nav_menu->term_id) ?>">
|
| 156 |
<?php echo esc_html( $_nav_menu->name ); ?>
|
| 157 |
</option>
|
|
@@ -168,4 +155,4 @@ class DuplicateMenu
|
|
| 168 |
<?php endif; ?>
|
| 169 |
</div>
|
| 170 |
<?php }
|
| 171 |
-
}
|
| 5 |
Plugin URI: https://github.com/jchristopher/duplicate-menu
|
| 6 |
Description: Easily duplicate your WordPress Menus
|
| 7 |
Author: Jonathan Christopher
|
| 8 |
+
Version: 0.2
|
| 9 |
Author URI: http://mondaybynoon.com
|
| 10 |
*/
|
| 11 |
|
| 12 |
+
/* Copyright 2011-2014 Jonathan Christopher (email : jonathan@mondaybynoon.com)
|
| 13 |
|
| 14 |
This program is free software; you can redistribute it and/or modify
|
| 15 |
it under the terms of the GNU General Public License as published by
|
| 26 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 27 |
*/
|
| 28 |
|
| 29 |
+
define( 'DUPLICATE_MENU_VERSION', '0.2' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
define( 'DUPLICATE_MENU_DIR', plugin_dir_path( __FILE__ ) );
|
| 31 |
define( 'DUPLICATE_MENU_URL', plugin_dir_url( __FILE__ ) );
|
| 32 |
|
| 33 |
+
function duplicate_menu_options_page() {
|
|
|
|
| 34 |
add_theme_page( 'Duplicate Menu', 'Duplicate Menu', 'manage_options', 'duplicate-menu', array( 'DuplicateMenu', 'options_screen' ) );
|
| 35 |
}
|
| 36 |
|
| 37 |
+
add_action( 'admin_menu', 'duplicate_menu_options_page' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
/**
|
| 40 |
* Duplicate Menu
|
| 41 |
*/
|
| 42 |
+
class DuplicateMenu {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
function duplicate( $id = null, $name = null ) {
|
|
|
|
| 45 |
|
| 46 |
+
// sanity check
|
| 47 |
+
if ( empty( $id ) || empty( $name ) ) {
|
| 48 |
+
return false;
|
| 49 |
+
}
|
| 50 |
|
| 51 |
+
$id = intval( $id );
|
| 52 |
+
$name = sanitize_text_field( $name );
|
| 53 |
+
$source = wp_get_nav_menu_object( $id );
|
| 54 |
+
$source_items = wp_get_nav_menu_items( $id );
|
| 55 |
$new_id = wp_create_nav_menu( $name );
|
| 56 |
|
| 57 |
+
if ( ! $new_id ) {
|
| 58 |
return false;
|
| 59 |
+
}
|
| 60 |
|
| 61 |
// key is the original db ID, val is the new
|
| 62 |
$rel = array();
|
| 63 |
|
| 64 |
$i = 1;
|
| 65 |
+
foreach ( $source_items as $menu_item ) {
|
|
|
|
|
|
|
| 66 |
$args = array(
|
| 67 |
'menu-item-db-id' => $menu_item->db_id,
|
| 68 |
'menu-item-object-id' => $menu_item->object_id,
|
| 84 |
$rel[$menu_item->db_id] = $parent_id;
|
| 85 |
|
| 86 |
// did it have a parent? if so, we need to update with the NEW ID
|
| 87 |
+
if ( $menu_item->menu_item_parent ) {
|
|
|
|
| 88 |
$args['menu-item-parent-id'] = $rel[$menu_item->menu_item_parent];
|
| 89 |
$parent_id = wp_update_nav_menu_item( $new_id, $parent_id, $args );
|
| 90 |
}
|
| 91 |
|
| 92 |
+
// allow developers to run any custom functionality they'd like
|
| 93 |
+
do_action( 'duplicate_menu_item', $menu_item, $args );
|
| 94 |
+
|
| 95 |
$i++;
|
| 96 |
}
|
| 97 |
|
| 98 |
return $new_id;
|
| 99 |
}
|
| 100 |
|
| 101 |
+
function options_screen() {
|
|
|
|
| 102 |
$nav_menus = wp_get_nav_menus();
|
| 103 |
?>
|
| 104 |
<div class="wrap">
|
| 105 |
<div id="icon-options-general" class="icon32"><br /></div>
|
| 106 |
<h2><?php _e( 'Duplicate Menu' ); ?></h2>
|
| 107 |
|
| 108 |
+
<?php if ( ! empty( $_POST ) && wp_verify_nonce( $_POST['duplicate_menu_nonce'], 'duplicate_menu' ) ) : ?>
|
| 109 |
<?php
|
| 110 |
$source = intval( $_POST['source'] );
|
| 111 |
$destination = sanitize_text_field( $_POST['new_menu_name'] );
|
| 116 |
?>
|
| 117 |
|
| 118 |
<div id="message" class="updated"><p>
|
| 119 |
+
<?php if ( $new_menu_id ) : ?>
|
| 120 |
+
<?php _e( 'Menu Duplicated' ) ?>. <a href="nav-menus.php?action=edit&menu=<?php echo absint( $new_menu_id ); ?>"><?php _e( 'View' ) ?></a>
|
| 121 |
<?php else: ?>
|
| 122 |
<?php _e( 'There was a problem duplicating your menu. No action was taken.' ) ?>.
|
| 123 |
<?php endif; ?>
|
| 126 |
<?php endif; ?>
|
| 127 |
|
| 128 |
|
| 129 |
+
<?php if ( empty( $nav_menus ) ) : ?>
|
| 130 |
<p><?php _e( "You haven't created any Menus yet." ); ?></p>
|
| 131 |
<?php else: ?>
|
| 132 |
<form method="post" action="">
|
| 138 |
</th>
|
| 139 |
<td>
|
| 140 |
<select name="source">
|
| 141 |
+
<?php foreach ( (array) $nav_menus as $_nav_menu ) : ?>
|
| 142 |
<option value="<?php echo esc_attr($_nav_menu->term_id) ?>">
|
| 143 |
<?php echo esc_html( $_nav_menu->name ); ?>
|
| 144 |
</option>
|
| 155 |
<?php endif; ?>
|
| 156 |
</div>
|
| 157 |
<?php }
|
| 158 |
+
}
|
readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
# Duplicate Menu
|
| 4 |
|
|
@@ -15,7 +15,7 @@ Find out more information in my [explanatory article on Duplicate Menu](http://m
|
|
| 15 |
## Installation
|
| 16 |
|
| 17 |
1. Download the plugin and extract the files
|
| 18 |
-
1. Upload `duplicate-
|
| 19 |
1. Activate the plugin through the 'Plugins' menu in WordPress
|
| 20 |
|
| 21 |
## Usage
|
|
@@ -26,9 +26,16 @@ After activation, navigate to Appearance > Duplicate Menu to create a copy of an
|
|
| 26 |
|
| 27 |
### Changelog
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
: Initial release
|
| 1 |
+
This is a WordPress plugin. [Official download available on wordpress.org](http://wordpress.org/extend/plugins/duplicate-menu/).
|
| 2 |
|
| 3 |
# Duplicate Menu
|
| 4 |
|
| 15 |
## Installation
|
| 16 |
|
| 17 |
1. Download the plugin and extract the files
|
| 18 |
+
1. Upload `duplicate-menu` to your `~/wp-content/plugins/` directory
|
| 19 |
1. Activate the plugin through the 'Plugins' menu in WordPress
|
| 20 |
|
| 21 |
## Usage
|
| 26 |
|
| 27 |
### Changelog
|
| 28 |
|
| 29 |
+
<dl>
|
| 30 |
+
|
| 31 |
+
<dt>0.2</dt>
|
| 32 |
+
<dd>Added <code>duplicate_menu_item</code> action, allowing devs to bolt on custom functionality</dd>
|
| 33 |
+
|
| 34 |
+
<dt>0.1.1</dt>
|
| 35 |
+
<dd>Removed anonymous function call to support PHP <5.3 installs</dd>
|
| 36 |
+
<dd>Added link to GitHub, please contribute!</dd>
|
| 37 |
+
|
| 38 |
+
<dt>0.1</dt>
|
| 39 |
+
<dd>Initial release</dd>
|
| 40 |
|
| 41 |
+
</dl>
|
|
|
readme.txt
CHANGED
|
@@ -3,8 +3,8 @@ Contributors: jchristopher
|
|
| 3 |
Donate link: http://mondaybynoon.com/donate/
|
| 4 |
Tags: menu, duplicate, copy, clone
|
| 5 |
Requires at least: 3.4.2
|
| 6 |
-
Tested up to:
|
| 7 |
-
Stable tag: 0.
|
| 8 |
License: GPLv2 or later
|
| 9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 10 |
|
|
@@ -30,9 +30,12 @@ Find out more information in my [explanatory article on Duplicate Menu](http://m
|
|
| 30 |
|
| 31 |
== Changelog ==
|
| 32 |
|
|
|
|
|
|
|
|
|
|
| 33 |
= 0.1.1 =
|
| 34 |
* Removed anonymous function call to support PHP <5.3 installs
|
| 35 |
* Added link to GitHub, please contribute!
|
| 36 |
|
| 37 |
= 0.1 =
|
| 38 |
-
* Initial release
|
| 3 |
Donate link: http://mondaybynoon.com/donate/
|
| 4 |
Tags: menu, duplicate, copy, clone
|
| 5 |
Requires at least: 3.4.2
|
| 6 |
+
Tested up to: 4.8
|
| 7 |
+
Stable tag: 0.2
|
| 8 |
License: GPLv2 or later
|
| 9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 10 |
|
| 30 |
|
| 31 |
== Changelog ==
|
| 32 |
|
| 33 |
+
= 0.2 =
|
| 34 |
+
* Added `duplicate_menu_item` action, allowing devs to bolt on custom functionality
|
| 35 |
+
|
| 36 |
= 0.1.1 =
|
| 37 |
* Removed anonymous function call to support PHP <5.3 installs
|
| 38 |
* Added link to GitHub, please contribute!
|
| 39 |
|
| 40 |
= 0.1 =
|
| 41 |
+
* Initial release
|
