Version Description
- Initial release
Download this release
Release Info
Developer | jchristopher |
Plugin | Duplicate Menu |
Version | 0.1 |
Comparing to | |
See all releases |
Version 0.1
- duplicate-menu.php +173 -0
- readme.txt +24 -0
duplicate-menu.php
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
Plugin Name: Duplicate Menu
|
5 |
+
Plugin URI: http://wordpress.org/extend/plugins/duplicate-menu/
|
6 |
+
Description: Easily duplicate your WordPress Menus
|
7 |
+
Author: Jonathan Christopher
|
8 |
+
Version: 0.1
|
9 |
+
Author URI: http://mondaybynoon.com
|
10 |
+
*/
|
11 |
+
|
12 |
+
/* Copyright 2011 - 2012 Jonathan Christopher (email : jonathan@irontoiron.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
|
16 |
+
the Free Software Foundation; either version 2 of the License, or
|
17 |
+
(at your option) any later version.
|
18 |
+
|
19 |
+
This program is distributed in the hope that it will be useful,
|
20 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
+
GNU General Public License for more details.
|
23 |
+
|
24 |
+
You should have received a copy of the GNU General Public License
|
25 |
+
along with this program; if not, write to the Free Software
|
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' );
|
35 |
+
define( 'DUPLICATE_MENU_DIR', plugin_dir_path( __FILE__ ) );
|
36 |
+
define( 'DUPLICATE_MENU_URL', plugin_dir_url( __FILE__ ) );
|
37 |
+
|
38 |
+
// WordPress actions
|
39 |
+
if( IS_ADMIN )
|
40 |
+
{
|
41 |
+
add_action( 'admin_menu', function(){
|
42 |
+
add_theme_page( 'Duplicate Menu', 'Duplicate Menu', 'manage_options', 'duplicate-menu', array( 'DuplicateMenu', 'options_screen' ) );
|
43 |
+
} );
|
44 |
+
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Duplicate Menu
|
49 |
+
*/
|
50 |
+
class DuplicateMenu
|
51 |
+
{
|
52 |
+
|
53 |
+
function duplicate( $id = null, $name = null )
|
54 |
+
{
|
55 |
+
// sanity check
|
56 |
+
if( empty( $id ) || empty( $name ) )
|
57 |
+
return false;
|
58 |
+
|
59 |
+
$id = intval( $id );
|
60 |
+
$name = sanitize_text_field( $name );
|
61 |
+
|
62 |
+
$source = wp_get_nav_menu_object( $id );
|
63 |
+
$source_items = wp_get_nav_menu_items( $id );
|
64 |
+
|
65 |
+
$new_id = wp_create_nav_menu( $name );
|
66 |
+
|
67 |
+
if( !$new_id )
|
68 |
+
return false;
|
69 |
+
|
70 |
+
// key is the original db ID, val is the new
|
71 |
+
$rel = array();
|
72 |
+
|
73 |
+
$i = 1;
|
74 |
+
foreach( $source_items as $menu_item )
|
75 |
+
{
|
76 |
+
|
77 |
+
$args = array(
|
78 |
+
'menu-item-db-id' => $menu_item->db_id,
|
79 |
+
'menu-item-object-id' => $menu_item->object_id,
|
80 |
+
'menu-item-object' => $menu_item->object,
|
81 |
+
'menu-item-position' => $i,
|
82 |
+
'menu-item-type' => $menu_item->type,
|
83 |
+
'menu-item-title' => $menu_item->title,
|
84 |
+
'menu-item-url' => $menu_item->url,
|
85 |
+
'menu-item-description' => $menu_item->description,
|
86 |
+
'menu-item-attr-title' => $menu_item->attr_title,
|
87 |
+
'menu-item-target' => $menu_item->target,
|
88 |
+
'menu-item-classes' => implode( ' ', $menu_item->classes ),
|
89 |
+
'menu-item-xfn' => $menu_item->xfn,
|
90 |
+
'menu-item-status' => $menu_item->post_status
|
91 |
+
);
|
92 |
+
|
93 |
+
$parent_id = wp_update_nav_menu_item( $new_id, 0, $args );
|
94 |
+
|
95 |
+
$rel[$menu_item->db_id] = $parent_id;
|
96 |
+
|
97 |
+
// did it have a parent? if so, we need to update with the NEW ID
|
98 |
+
if( $menu_item->menu_item_parent )
|
99 |
+
{
|
100 |
+
$args['menu-item-parent-id'] = $rel[$menu_item->menu_item_parent];
|
101 |
+
$parent_id = wp_update_nav_menu_item( $new_id, $parent_id, $args );
|
102 |
+
}
|
103 |
+
|
104 |
+
$i++;
|
105 |
+
}
|
106 |
+
|
107 |
+
foreach( $source_items as $menu_item )
|
108 |
+
{
|
109 |
+
|
110 |
+
}
|
111 |
+
|
112 |
+
return $new_id;
|
113 |
+
}
|
114 |
+
|
115 |
+
function options_screen()
|
116 |
+
{
|
117 |
+
$nav_menus = wp_get_nav_menus();
|
118 |
+
?>
|
119 |
+
<div class="wrap">
|
120 |
+
<div id="icon-options-general" class="icon32"><br /></div>
|
121 |
+
<h2><?php _e( 'Duplicate Menu' ); ?></h2>
|
122 |
+
|
123 |
+
<?php if( !empty( $_POST ) && wp_verify_nonce( $_POST['duplicate_menu_nonce'], 'duplicate_menu' ) ) : ?>
|
124 |
+
<?php
|
125 |
+
$source = intval( $_POST['source'] );
|
126 |
+
$destination = sanitize_text_field( $_POST['new_menu_name'] );
|
127 |
+
|
128 |
+
// go ahead and duplicate our menu
|
129 |
+
$duplicator = new DuplicateMenu();
|
130 |
+
$new_menu_id = $duplicator->duplicate( $source, $destination );
|
131 |
+
?>
|
132 |
+
|
133 |
+
<div id="message" class="updated"><p>
|
134 |
+
<?php if( $new_menu_id ) : ?>
|
135 |
+
<?php _e( 'Menu Duplicated' ) ?>. <a href="nav-menus.php?action=edit&menu=<?php echo $new_menu_id; ?>"><?php _e( 'View' ) ?></a>
|
136 |
+
<?php else: ?>
|
137 |
+
<?php _e( 'There was a problem duplicating your menu. No action was taken.' ) ?>.
|
138 |
+
<?php endif; ?>
|
139 |
+
</p></div>
|
140 |
+
|
141 |
+
<?php endif; ?>
|
142 |
+
|
143 |
+
|
144 |
+
<?php if( empty( $nav_menus ) ) : ?>
|
145 |
+
<p><?php _e( "You haven't created any Menus yet." ); ?></p>
|
146 |
+
<?php else: ?>
|
147 |
+
<form method="post" action="">
|
148 |
+
<?php wp_nonce_field( 'duplicate_menu','duplicate_menu_nonce' ); ?>
|
149 |
+
<table class="form-table">
|
150 |
+
<tr valign="top">
|
151 |
+
<th scope="row">
|
152 |
+
<label for="source"><?php _e( 'Duplicate this menu' ); ?>:</label>
|
153 |
+
</th>
|
154 |
+
<td>
|
155 |
+
<select name="source">
|
156 |
+
<?php foreach( (array) $nav_menus as $_nav_menu ) : ?>
|
157 |
+
<option value="<?php echo esc_attr($_nav_menu->term_id) ?>">
|
158 |
+
<?php echo esc_html( $_nav_menu->name ); ?>
|
159 |
+
</option>
|
160 |
+
<?php endforeach; ?>
|
161 |
+
</select>
|
162 |
+
<span style="display:inline-block; padding:0 10px;"><?php _e( 'and call it' ); ?></span>
|
163 |
+
<input name="new_menu_name" type="text" id="new_menu_name" value="" class="regular-text" />
|
164 |
+
</td>
|
165 |
+
</table>
|
166 |
+
<p class="submit">
|
167 |
+
<input type="submit" name="submit" id="submit" class="button-primary" value="Duplicate Menu" />
|
168 |
+
</p>
|
169 |
+
</form>
|
170 |
+
<?php endif; ?>
|
171 |
+
</div>
|
172 |
+
<?php }
|
173 |
+
}
|
readme.txt
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Duplicate Menu ===
|
2 |
+
Contributors: jchristopher
|
3 |
+
Donate link: http://mondaybynoon.com/donate/
|
4 |
+
Tags: menu, duplicate
|
5 |
+
Requires at least: 3.4.1
|
6 |
+
Tested up to: 3.4.1
|
7 |
+
Stable tag: 0.1
|
8 |
+
|
9 |
+
Easily duplicate your WordPress menus with one click
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
|
13 |
+
Easily duplicate your WordPress menus with one click
|
14 |
+
|
15 |
+
== Installation ==
|
16 |
+
|
17 |
+
1. Download the plugin and extract the files
|
18 |
+
1. Upload `duplicate-posts` to your `~/wp-content/plugins/` directory
|
19 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress
|
20 |
+
|
21 |
+
== Changelog ==
|
22 |
+
|
23 |
+
= 0.1 =
|
24 |
+
* Initial release
|