Duplicate Post - Version 3.0

Version Description

Major redesign of the settings page + fine-tune options (what to copy, custom post types, etc.) + bugfixes and XSS prevention

Download this release

Release Info

Developer lopo
Plugin Icon 128x128 Duplicate Post
Version 3.0
Comparing to
See all releases

Code changes from version 2.6 to 3.0

duplicate-post-admin.php CHANGED
@@ -1,354 +1,528 @@
1
- <?php
2
- // Added by WarmStal
3
- if(!is_admin())
4
- return;
5
-
6
- require_once (dirname(__FILE__).'/duplicate-post-options.php');
7
-
8
- /**
9
- * Wrapper for the option 'duplicate_post_version'
10
- */
11
- function duplicate_post_get_installed_version() {
12
- return get_option( 'duplicate_post_version' );
13
- }
14
-
15
- /**
16
- * Wrapper for the defined constant DUPLICATE_POST_CURRENT_VERSION
17
- */
18
- function duplicate_post_get_current_version() {
19
- return DUPLICATE_POST_CURRENT_VERSION;
20
- }
21
-
22
- /**
23
- * Plugin upgrade
24
- */
25
- add_action('admin_init','duplicate_post_plugin_upgrade');
26
-
27
- function duplicate_post_plugin_upgrade() {
28
- $installed_version = duplicate_post_get_installed_version();
29
-
30
- if (empty($installed_version)) { // first install
31
-
32
- // Add capability to admin and editors
33
-
34
- // Get default roles
35
- $default_roles = array(
36
- 3 => 'editor',
37
- 8 => 'administrator',
38
- );
39
-
40
- // Cycle all roles and assign capability if its level >= duplicate_post_copy_user_level
41
- foreach ($default_roles as $level => $name){
42
- $role = get_role($name);
43
- if(!empty($role)) $role->add_cap( 'copy_posts' );
44
- }
45
-
46
- add_option('duplicate_post_copyexcerpt','1');
47
- add_option('duplicate_post_copyattachments','0');
48
- add_option('duplicate_post_copychildren','0');
49
- add_option('duplicate_post_copystatus','0');
50
- add_option('duplicate_post_taxonomies_blacklist',array());
51
- add_option('duplicate_post_show_row','1');
52
- add_option('duplicate_post_show_adminbar','1');
53
- add_option('duplicate_post_show_submitbox','1');
54
- } else if ( $installed_version==duplicate_post_get_current_version() ) { //re-install
55
- // do nothing
56
- } else { //upgrade form previous version
57
- // delete old, obsolete options
58
- delete_option('duplicate_post_admin_user_level');
59
- delete_option('duplicate_post_create_user_level');
60
- delete_option('duplicate_post_view_user_level');
61
- delete_option('dp_notice');
62
-
63
- /*
64
- * Convert old userlevel option to new capability scheme
65
- */
66
-
67
- // Get old duplicate_post_copy_user_level option
68
- $min_user_level = get_option('duplicate_post_copy_user_level');
69
-
70
- if (!empty($min_user_level)){
71
- // Get default roles
72
- $default_roles = array(
73
- 1 => 'contributor',
74
- 2 => 'author',
75
- 3 => 'editor',
76
- 8 => 'administrator',
77
- );
78
-
79
- // Cycle all roles and assign capability if its level >= duplicate_post_copy_user_level
80
- foreach ($default_roles as $level => $name){
81
- $role = get_role($name);
82
- if ($role && $min_user_level <= $level)
83
- $role->add_cap( 'copy_posts' );
84
- }
85
-
86
- // delete old option
87
- delete_option('duplicate_post_copy_user_level');
88
- }
89
-
90
- add_option('duplicate_post_copyexcerpt','1');
91
- add_option('duplicate_post_copyattachments','0');
92
- add_option('duplicate_post_copychildren','0');
93
- add_option('duplicate_post_copystatus','0');
94
- add_option('duplicate_post_taxonomies_blacklist',array());
95
- add_option('duplicate_post_show_row','1');
96
- add_option('duplicate_post_show_adminbar','1');
97
- add_option('duplicate_post_show_submitbox','1');
98
- }
99
- // Update version number
100
- update_option( 'duplicate_post_version', duplicate_post_get_current_version() );
101
-
102
- }
103
-
104
- if (get_option('duplicate_post_show_row') == 1){
105
- add_filter('post_row_actions', 'duplicate_post_make_duplicate_link_row',10,2);
106
- add_filter('page_row_actions', 'duplicate_post_make_duplicate_link_row',10,2);
107
- }
108
-
109
- /**
110
- * Add the link to action list for post_row_actions
111
- */
112
- function duplicate_post_make_duplicate_link_row($actions, $post) {
113
- if (duplicate_post_is_current_user_allowed_to_copy()) {
114
- $actions['clone'] = '<a href="'.duplicate_post_get_clone_post_link( $post->ID , 'display', false).'" title="'
115
- . esc_attr(__("Clone this item", DUPLICATE_POST_I18N_DOMAIN))
116
- . '">' . __('Clone', DUPLICATE_POST_I18N_DOMAIN) . '</a>';
117
- $actions['edit_as_new_draft'] = '<a href="'. duplicate_post_get_clone_post_link( $post->ID ) .'" title="'
118
- . esc_attr(__('Copy to a new draft', DUPLICATE_POST_I18N_DOMAIN))
119
- . '">' . __('New Draft', DUPLICATE_POST_I18N_DOMAIN) . '</a>';
120
- }
121
- return $actions;
122
- }
123
-
124
- /**
125
- * Add a button in the post/page edit screen to create a clone
126
- */
127
- if (get_option('duplicate_post_show_submitbox') == 1){
128
- add_action( 'post_submitbox_start', 'duplicate_post_add_duplicate_post_button' );
129
- }
130
-
131
- function duplicate_post_add_duplicate_post_button() {
132
- if ( isset( $_GET['post'] ) && duplicate_post_is_current_user_allowed_to_copy()) {
133
- ?>
134
- <div id="duplicate-action">
135
- <a class="submitduplicate duplication"
136
- href="<?php echo duplicate_post_get_clone_post_link( $_GET['post'] ) ?>"><?php _e('Copy to a new draft', DUPLICATE_POST_I18N_DOMAIN); ?>
137
- </a>
138
- </div>
139
- <?php
140
- }
141
- }
142
-
143
- /**
144
- * Connect actions to functions
145
- */
146
- add_action('admin_action_duplicate_post_save_as_new_post', 'duplicate_post_save_as_new_post');
147
- add_action('admin_action_duplicate_post_save_as_new_post_draft', 'duplicate_post_save_as_new_post_draft');
148
-
149
- /*
150
- * This function calls the creation of a new copy of the selected post (as a draft)
151
- * then redirects to the edit post screen
152
- */
153
- function duplicate_post_save_as_new_post_draft(){
154
- duplicate_post_save_as_new_post('draft');
155
- }
156
-
157
- /*
158
- * This function calls the creation of a new copy of the selected post (by default preserving the original publish status)
159
- * then redirects to the post list
160
- */
161
- function duplicate_post_save_as_new_post($status = ''){
162
- if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'duplicate_post_save_as_new_post' == $_REQUEST['action'] ) ) ) {
163
- wp_die(__('No post to duplicate has been supplied!', DUPLICATE_POST_I18N_DOMAIN));
164
- }
165
-
166
- // Get the original post
167
- $id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']);
168
- $post = get_post($id);
169
-
170
- // Copy the post and insert it
171
- if (isset($post) && $post!=null) {
172
- $new_id = duplicate_post_create_duplicate($post, $status);
173
-
174
- if ($status == ''){
175
- // Redirect to the post list screen
176
- wp_redirect( admin_url( 'edit.php?post_type='.$post->post_type) );
177
- } else {
178
- // Redirect to the edit screen for the new draft post
179
- wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_id ) );
180
- }
181
- exit;
182
-
183
- } else {
184
- $post_type_obj = get_post_type_object( $post->post_type );
185
- wp_die(esc_attr(__('Copy creation failed, could not find original:', DUPLICATE_POST_I18N_DOMAIN)) . ' ' . htmlspecialchars($id));
186
- }
187
- }
188
-
189
- /**
190
- * Get the currently registered user
191
- */
192
- function duplicate_post_get_current_user() {
193
- if (function_exists('wp_get_current_user')) {
194
- return wp_get_current_user();
195
- } else if (function_exists('get_currentuserinfo')) {
196
- global $userdata;
197
- get_currentuserinfo();
198
- return $userdata;
199
- } else {
200
- $user_login = $_COOKIE[USER_COOKIE];
201
- $sql = $wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_login=%s", $user_login);
202
- $current_user = $wpdb->get_results($sql);
203
- return $current_user;
204
- }
205
- }
206
-
207
- /**
208
- * Copy the taxonomies of a post to another post
209
- */
210
- function duplicate_post_copy_post_taxonomies($new_id, $post) {
211
- global $wpdb;
212
- if (isset($wpdb->terms)) {
213
- // Clear default category (added by wp_insert_post)
214
- wp_set_object_terms( $new_id, NULL, 'category' );
215
-
216
- $post_taxonomies = get_object_taxonomies($post->post_type);
217
- $taxonomies_blacklist = get_option('duplicate_post_taxonomies_blacklist');
218
- if ($taxonomies_blacklist == "") $taxonomies_blacklist = array();
219
- $taxonomies = array_diff($post_taxonomies, $taxonomies_blacklist);
220
- foreach ($taxonomies as $taxonomy) {
221
- $post_terms = wp_get_object_terms($post->ID, $taxonomy, array( 'orderby' => 'term_order' ));
222
- $terms = array();
223
- for ($i=0; $i<count($post_terms); $i++) {
224
- $terms[] = $post_terms[$i]->slug;
225
- }
226
- wp_set_object_terms($new_id, $terms, $taxonomy);
227
- }
228
- }
229
- }
230
-
231
- // Using our action hooks to copy taxonomies
232
- add_action('dp_duplicate_post', 'duplicate_post_copy_post_taxonomies', 10, 2);
233
- add_action('dp_duplicate_page', 'duplicate_post_copy_post_taxonomies', 10, 2);
234
-
235
- /**
236
- * Copy the meta information of a post to another post
237
- */
238
- function duplicate_post_copy_post_meta_info($new_id, $post) {
239
- $post_meta_keys = get_post_custom_keys($post->ID);
240
- if (empty($post_meta_keys)) return;
241
- $meta_blacklist = explode(",",get_option('duplicate_post_blacklist'));
242
- if ($meta_blacklist == "") $meta_blacklist = array();
243
- $meta_keys = array_diff($post_meta_keys, $meta_blacklist);
244
-
245
- foreach ($meta_keys as $meta_key) {
246
- $meta_values = get_post_custom_values($meta_key, $post->ID);
247
- foreach ($meta_values as $meta_value) {
248
- $meta_value = maybe_unserialize($meta_value);
249
- add_post_meta($new_id, $meta_key, $meta_value);
250
- }
251
- }
252
- }
253
-
254
- // Using our action hooks to copy meta fields
255
- add_action('dp_duplicate_post', 'duplicate_post_copy_post_meta_info', 10, 2);
256
- add_action('dp_duplicate_page', 'duplicate_post_copy_post_meta_info', 10, 2);
257
-
258
- /**
259
- * Copy the attachments
260
- * It simply copies the table entries, actual file won't be duplicated
261
- */
262
- function duplicate_post_copy_children($new_id, $post){
263
- $copy_attachments = get_option('duplicate_post_copyattachments');
264
- $copy_children = get_option('duplicate_post_copychildren');
265
-
266
- // get children
267
- $children = get_posts(array( 'post_type' => 'any', 'numberposts' => -1, 'post_status' => 'any', 'post_parent' => $post->ID ));
268
- // clone old attachments
269
- foreach($children as $child){
270
- if ($copy_attachments == 0 && $child->post_type == 'attachment') continue;
271
- if ($copy_children == 0 && $child->post_type != 'attachment') continue;
272
- duplicate_post_create_duplicate($child, '', $new_id);
273
- }
274
- }
275
- // Using our action hooks to copy attachments
276
- add_action('dp_duplicate_post', 'duplicate_post_copy_children', 10, 2);
277
- add_action('dp_duplicate_page', 'duplicate_post_copy_children', 10, 2);
278
-
279
-
280
- /**
281
- * Create a duplicate from a post
282
- */
283
- function duplicate_post_create_duplicate($post, $status = '', $parent_id = '') {
284
-
285
- // We don't want to clone revisions
286
- if ($post->post_type == 'revision') return;
287
-
288
- if ($post->post_type != 'attachment'){
289
- $prefix = get_option('duplicate_post_title_prefix');
290
- $suffix = get_option('duplicate_post_title_suffix');
291
- if (!empty($prefix)) $prefix.= " ";
292
- if (!empty($suffix)) $suffix = " ".$suffix;
293
- if (get_option('duplicate_post_copystatus') == 0) $status = 'draft';
294
- }
295
- $new_post_author = duplicate_post_get_current_user();
296
-
297
- $new_post = array(
298
- 'menu_order' => $post->menu_order,
299
- 'comment_status' => $post->comment_status,
300
- 'ping_status' => $post->ping_status,
301
- 'post_author' => $new_post_author->ID,
302
- 'post_content' => $post->post_content,
303
- 'post_excerpt' => (get_option('duplicate_post_copyexcerpt') == '1') ? $post->post_excerpt : "",
304
- 'post_mime_type' => $post->post_mime_type,
305
- 'post_parent' => $new_post_parent = empty($parent_id)? $post->post_parent : $parent_id,
306
- 'post_password' => $post->post_password,
307
- 'post_status' => $new_post_status = (empty($status))? $post->post_status: $status,
308
- 'post_title' => $prefix.$post->post_title.$suffix,
309
- 'post_type' => $post->post_type,
310
- );
311
-
312
- if(get_option('duplicate_post_copydate') == 1){
313
- $new_post['post_date'] = $new_post_date = $post->post_date ;
314
- $new_post['post_date_gmt'] = get_gmt_from_date($new_post_date);
315
- }
316
-
317
- $new_post_id = wp_insert_post($new_post);
318
-
319
- // If the copy is published or scheduled, we have to set a proper slug.
320
- if ($new_post_status == 'publish' || $new_post_status == 'future'){
321
- $post_name = wp_unique_post_slug($post->post_name, $new_post_id, $new_post_status, $post->post_type, $new_post_parent);
322
-
323
- $new_post = array();
324
- $new_post['ID'] = $new_post_id;
325
- $new_post['post_name'] = $post_name;
326
-
327
- // Update the post into the database
328
- wp_update_post( $new_post );
329
- }
330
-
331
- // If you have written a plugin which uses non-WP database tables to save
332
- // information about a post you can hook this action to dupe that data.
333
- if ($post->post_type == 'page' || (function_exists('is_post_type_hierarchical') && is_post_type_hierarchical( $post->post_type )))
334
- do_action( 'dp_duplicate_page', $new_post_id, $post );
335
- else
336
- do_action( 'dp_duplicate_post', $new_post_id, $post );
337
-
338
- delete_post_meta($new_post_id, '_dp_original');
339
- add_post_meta($new_post_id, '_dp_original', $post->ID);
340
-
341
- return $new_post_id;
342
- }
343
-
344
- //Add some links on the plugin page
345
- add_filter('plugin_row_meta', 'duplicate_post_add_plugin_links', 10, 2);
346
-
347
- function duplicate_post_add_plugin_links($links, $file) {
348
- if ( $file == plugin_basename(dirname(__FILE__).'/duplicate-post.php') ) {
349
- $links[] = '<a href="http://lopo.it/duplicate-post-plugin">' . __('Donate', DUPLICATE_POST_I18N_DOMAIN) . '</a>';
350
- $links[] = '<a href="http://lopo.it/duplicate-post-plugin">' . __('Translate', DUPLICATE_POST_I18N_DOMAIN) . '</a>';
351
- }
352
- return $links;
353
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  ?>
1
+ <?php
2
+ // Added by WarmStal
3
+ if(!is_admin())
4
+ return;
5
+
6
+ require_once (dirname(__FILE__).'/duplicate-post-options.php');
7
+
8
+ /**
9
+ * Wrapper for the option 'duplicate_post_version'
10
+ */
11
+ function duplicate_post_get_installed_version() {
12
+ return get_option( 'duplicate_post_version' );
13
+ }
14
+
15
+ /**
16
+ * Wrapper for the defined constant DUPLICATE_POST_CURRENT_VERSION
17
+ */
18
+ function duplicate_post_get_current_version() {
19
+ return DUPLICATE_POST_CURRENT_VERSION;
20
+ }
21
+
22
+ /**
23
+ * Plugin upgrade
24
+ */
25
+ //add_action('admin_init','duplicate_post_plugin_upgrade');
26
+
27
+ function duplicate_post_plugin_upgrade() {
28
+ $installed_version = duplicate_post_get_installed_version();
29
+
30
+ if (empty($installed_version)) { // first install
31
+
32
+ // Add capability to admin and editors
33
+
34
+ // Get default roles
35
+ $default_roles = array(
36
+ 3 => 'editor',
37
+ 8 => 'administrator',
38
+ );
39
+
40
+ // Cycle all roles and assign capability if its level >= duplicate_post_copy_user_level
41
+ foreach ($default_roles as $level => $name){
42
+ $role = get_role($name);
43
+ if(!empty($role)) $role->add_cap( 'copy_posts' );
44
+ }
45
+
46
+ add_option('duplicate_post_copytitle','1');
47
+ add_option('duplicate_post_copydate','0');
48
+ add_option('duplicate_post_copystatus','0');
49
+ add_option('duplicate_post_copyslug','1');
50
+ add_option('duplicate_post_copyexcerpt','1');
51
+ add_option('duplicate_post_copycontent','1');
52
+ add_option('duplicate_post_copypassword','0');
53
+ add_option('duplicate_post_copyattachments','0');
54
+ add_option('duplicate_post_copychildren','0');
55
+ add_option('duplicate_post_copycomments','0');
56
+ add_option('duplicate_post_taxonomies_blacklist',array());
57
+ add_option('duplicate_post_blacklist','');
58
+ add_option('duplicate_post_types_enabled',array('post', 'page'));
59
+ add_option('duplicate_post_show_row','1');
60
+ add_option('duplicate_post_show_adminbar','1');
61
+ add_option('duplicate_post_show_submitbox','1');
62
+ } else if ( $installed_version==duplicate_post_get_current_version() ) { //re-install
63
+ // do nothing
64
+ } else { //upgrade form previous version
65
+ // delete old, obsolete options
66
+ delete_option('duplicate_post_admin_user_level');
67
+ delete_option('duplicate_post_create_user_level');
68
+ delete_option('duplicate_post_view_user_level');
69
+ delete_option('dp_notice');
70
+
71
+ /*
72
+ * Convert old userlevel option to new capability scheme
73
+ */
74
+
75
+ // Get old duplicate_post_copy_user_level option
76
+ $min_user_level = get_option('duplicate_post_copy_user_level');
77
+
78
+ if (!empty($min_user_level)){
79
+ // Get default roles
80
+ $default_roles = array(
81
+ 1 => 'contributor',
82
+ 2 => 'author',
83
+ 3 => 'editor',
84
+ 8 => 'administrator',
85
+ );
86
+
87
+ // Cycle all roles and assign capability if its level >= duplicate_post_copy_user_level
88
+ foreach ($default_roles as $level => $name){
89
+ $role = get_role($name);
90
+ if ($role && $min_user_level <= $level)
91
+ $role->add_cap( 'copy_posts' );
92
+ }
93
+
94
+ // delete old option
95
+ delete_option('duplicate_post_copy_user_level');
96
+ }
97
+
98
+ add_option('duplicate_post_copytitle','1');
99
+ add_option('duplicate_post_copydate','0');
100
+ add_option('duplicate_post_copystatus','0');
101
+ add_option('duplicate_post_copyslug','1');
102
+ add_option('duplicate_post_copyexcerpt','1');
103
+ add_option('duplicate_post_copycontent','1');
104
+ add_option('duplicate_post_copypassword','0');
105
+ add_option('duplicate_post_copyattachments','0');
106
+ add_option('duplicate_post_copychildren','0');
107
+ add_option('duplicate_post_copycomments','0');
108
+ add_option('duplicate_post_taxonomies_blacklist',array());
109
+ add_option('duplicate_post_blacklist','');
110
+ add_option('duplicate_post_types_enabled',array('post', 'page'));
111
+ add_option('duplicate_post_show_row','1');
112
+ add_option('duplicate_post_show_adminbar','1');
113
+ add_option('duplicate_post_show_submitbox','1');
114
+
115
+ add_option('duplicate_post_show_notice','1');
116
+ }
117
+ // Update version number
118
+ update_option( 'duplicate_post_version', duplicate_post_get_current_version() );
119
+
120
+ }
121
+
122
+ if (get_option('duplicate_post_show_row') == 1){
123
+ add_filter('post_row_actions', 'duplicate_post_make_duplicate_link_row',10,2);
124
+ add_filter('page_row_actions', 'duplicate_post_make_duplicate_link_row',10,2);
125
+ }
126
+
127
+ /**
128
+ * Shows the update notice
129
+ */
130
+ function duplicate_post_show_update_notice() {
131
+ if(!current_user_can( 'manage_options')) return;
132
+ $class = 'notice is-dismissible';
133
+ $message = sprintf(__('<strong>Duplicate Post has been greatly redesigned in its options page.</strong> Please <a href="%s">review the settings</a> to make sure it works as you expect.', 'duplicate-post'), site_url('/wp-admin/options-general.php?page=duplicatepost'));
134
+ $message .= '<br/>';
135
+ $message .= '<a href="http://lopo.it/duplicate-post-plugin">'.__('Donate', 'duplicate-post').' (10¢) </a> | <a id="duplicate-post-dismiss-notice" href="javascript:duplicate_post_dismiss_notice();">'.__('Dismiss this notice.').'</a>';
136
+ echo '<div id="duplicate-post-notice" class="'.$class.'"><p>'.$message.'</p></div>';
137
+ echo "<script>
138
+ function duplicate_post_dismiss_notice(){
139
+ var data = {
140
+ 'action': 'duplicate_post_dismiss_notice',
141
+ };
142
+
143
+ jQuery.post(ajaxurl, data, function(response) {
144
+ jQuery('#duplicate-post-notice').hide();
145
+ });
146
+ }
147
+
148
+ jQuery(document).ready(function(){
149
+ jQuery('.notice-dismiss').click(function(){
150
+ duplicate_post_dismiss_notice();
151
+ });
152
+ });
153
+ </script>";
154
+ }
155
+ if (get_option('duplicate_post_show_notice') == 1){
156
+ add_action( 'admin_notices', 'duplicate_post_show_update_notice' );
157
+ }
158
+
159
+ add_action( 'wp_ajax_duplicate_post_dismiss_notice', 'duplicate_post_dismiss_notice' );
160
+
161
+ function duplicate_post_dismiss_notice() {
162
+ $result = update_option('duplicate_post_show_notice', 0);
163
+ return $result;
164
+
165
+ wp_die();
166
+ }
167
+
168
+
169
+ /**
170
+ * Add the link to action list for post_row_actions
171
+ */
172
+ function duplicate_post_make_duplicate_link_row($actions, $post) {
173
+ if (duplicate_post_is_current_user_allowed_to_copy() && duplicate_post_is_post_type_enabled($post->post_type)) {
174
+ $actions['clone'] = '<a href="'.duplicate_post_get_clone_post_link( $post->ID , 'display', false).'" title="'
175
+ . esc_attr(__("Clone this item", 'duplicate-post'))
176
+ . '">' . __('Clone', 'duplicate-post') . '</a>';
177
+ $actions['edit_as_new_draft'] = '<a href="'. duplicate_post_get_clone_post_link( $post->ID ) .'" title="'
178
+ . esc_attr(__('Copy to a new draft', 'duplicate-post'))
179
+ . '">' . __('New Draft', 'duplicate-post') . '</a>';
180
+ }
181
+ return $actions;
182
+ }
183
+
184
+ /**
185
+ * Add a button in the post/page edit screen to create a clone
186
+ */
187
+ if (get_option('duplicate_post_show_submitbox') == 1){
188
+ add_action( 'post_submitbox_start', 'duplicate_post_add_duplicate_post_button' );
189
+ }
190
+
191
+ function duplicate_post_add_duplicate_post_button() {
192
+ if ( isset( $_GET['post'] )){
193
+ $id = $_GET['post'];
194
+ $post = get_post($id);
195
+ if(duplicate_post_is_current_user_allowed_to_copy() && duplicate_post_is_post_type_enabled($post->post_type)) {
196
+ ?>
197
+ <div id="duplicate-action">
198
+ <a class="submitduplicate duplication"
199
+ href="<?php echo duplicate_post_get_clone_post_link( $_GET['post'] ) ?>"><?php _e('Copy to a new draft', 'duplicate-post'); ?>
200
+ </a>
201
+ </div>
202
+ <?php
203
+ }
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Connect actions to functions
209
+ */
210
+ add_action('admin_action_duplicate_post_save_as_new_post', 'duplicate_post_save_as_new_post');
211
+ add_action('admin_action_duplicate_post_save_as_new_post_draft', 'duplicate_post_save_as_new_post_draft');
212
+
213
+ /*
214
+ * This function calls the creation of a new copy of the selected post (as a draft)
215
+ * then redirects to the edit post screen
216
+ */
217
+ function duplicate_post_save_as_new_post_draft(){
218
+ duplicate_post_save_as_new_post('draft');
219
+ }
220
+
221
+ /*
222
+ * This function calls the creation of a new copy of the selected post (by default preserving the original publish status)
223
+ * then redirects to the post list
224
+ */
225
+ function duplicate_post_save_as_new_post($status = ''){
226
+ if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'duplicate_post_save_as_new_post' == $_REQUEST['action'] ) ) ) {
227
+ wp_die(__('No post to duplicate has been supplied!', 'duplicate-post'));
228
+ }
229
+
230
+ // Get the original post
231
+ $id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']);
232
+ $post = get_post($id);
233
+
234
+ // Copy the post and insert it
235
+ if (isset($post) && $post!=null) {
236
+ $new_id = duplicate_post_create_duplicate($post, $status);
237
+
238
+ if ($status == ''){
239
+ // Redirect to the post list screen
240
+ wp_redirect( admin_url( 'edit.php?post_type='.$post->post_type) );
241
+ } else {
242
+ // Redirect to the edit screen for the new draft post
243
+ wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_id ) );
244
+ }
245
+ exit;
246
+
247
+ } else {
248
+ $post_type_obj = get_post_type_object( $post->post_type );
249
+ wp_die(__('Copy creation failed, could not find original:', 'duplicate-post') . ' ' . htmlspecialchars($id));
250
+ }
251
+ }
252
+
253
+ /**
254
+ * Copy the taxonomies of a post to another post
255
+ */
256
+ function duplicate_post_copy_post_taxonomies($new_id, $post) {
257
+ global $wpdb;
258
+ if (isset($wpdb->terms)) {
259
+ // Clear default category (added by wp_insert_post)
260
+ wp_set_object_terms( $new_id, NULL, 'category' );
261
+
262
+ $post_taxonomies = get_object_taxonomies($post->post_type);
263
+ $taxonomies_blacklist = get_option('duplicate_post_taxonomies_blacklist');
264
+ if ($taxonomies_blacklist == "") $taxonomies_blacklist = array();
265
+ $taxonomies = array_diff($post_taxonomies, $taxonomies_blacklist);
266
+ foreach ($taxonomies as $taxonomy) {
267
+ $post_terms = wp_get_object_terms($post->ID, $taxonomy, array( 'orderby' => 'term_order' ));
268
+ $terms = array();
269
+ for ($i=0; $i<count($post_terms); $i++) {
270
+ $terms[] = $post_terms[$i]->slug;
271
+ }
272
+ wp_set_object_terms($new_id, $terms, $taxonomy);
273
+ }
274
+ }
275
+ }
276
+
277
+ /**
278
+ * Copy the meta information of a post to another post
279
+ */
280
+ function duplicate_post_copy_post_meta_info($new_id, $post) {
281
+ $post_meta_keys = get_post_custom_keys($post->ID);
282
+ if (empty($post_meta_keys)) return;
283
+ $meta_blacklist = explode(",",get_option('duplicate_post_blacklist'));
284
+ if ($meta_blacklist == "") $meta_blacklist = array();
285
+ $meta_blacklist = array_map('trim', $meta_blacklist);
286
+ $meta_blacklist[] = '_wpas_done_all'; //Jetpack Publicize
287
+ $meta_blacklist[] = '_wpas_done_'; //Jetpack Publicize
288
+ $meta_blacklist[] = '_wpas_mess'; //Jetpack Publicize
289
+ $meta_blacklist[] = '_edit_lock'; // edit lock
290
+ $meta_blacklist[] = '_edit_last'; // edit lock
291
+ $meta_keys = array_diff($post_meta_keys, $meta_blacklist);
292
+
293
+ foreach ($meta_keys as $meta_key) {
294
+ $meta_values = get_post_custom_values($meta_key, $post->ID);
295
+ foreach ($meta_values as $meta_value) {
296
+ $meta_value = maybe_unserialize($meta_value);
297
+ add_post_meta($new_id, $meta_key, $meta_value);
298
+ }
299
+ }
300
+ }
301
+
302
+ /**
303
+ * Copy the attachments
304
+ * It simply copies the table entries, actual file won't be duplicated
305
+ */
306
+ function duplicate_post_copy_attachments($new_id, $post){
307
+ // get thumbnail ID
308
+ $old_thumbnail_id = get_post_thumbnail_id($post->ID);
309
+ // get children
310
+ $children = get_posts(array( 'post_type' => 'any', 'numberposts' => -1, 'post_status' => 'any', 'post_parent' => $post->ID ));
311
+ // clone old attachments
312
+ foreach($children as $child){
313
+ if ($child->post_type != 'attachment') continue;
314
+ $url = wp_get_attachment_url($child->ID);
315
+ // Let's copy the actual file
316
+ $tmp = download_url( $url );
317
+ if( is_wp_error( $tmp ) ) {
318
+ @unlink($tmp);
319
+ continue;
320
+ }
321
+
322
+ $desc = addslashes($child->post_content);
323
+
324
+ $file_array = array();
325
+ $file_array['name'] = basename($url);
326
+ $file_array['tmp_name'] = $tmp;
327
+ // "Upload" to the media collection
328
+ $new_attachment_id = media_handle_sideload( $file_array, $new_id, $desc );
329
+
330
+ if ( is_wp_error($new_attachment_id) ) {
331
+ @unlink($file_array['tmp_name']);
332
+ continue;
333
+ }
334
+ $new_post_author = wp_get_current_user();
335
+ $cloned_child = array(
336
+ 'ID' => $new_attachment_id,
337
+ 'post_title' => addslashes($child->post_title),
338
+ 'post_exceprt' => addslashes($child->post_title),
339
+ 'post_author' => $new_post_author->ID
340
+ );
341
+ wp_update_post( $cloned_child );
342
+
343
+ $alt_title = get_post_meta($child->ID, '_wp_attachment_image_alt', true);
344
+ if($alt_title) update_post_meta($new_attachment_id, $meta_key, $alt_title);
345
+
346
+ // if we have cloned the post thumbnail, set the copy as the thumbnail for the new post
347
+ if($old_thumbnail_id == $child->ID){
348
+ set_post_thumbnail($new_id, $new_attachment_id);
349
+ }
350
+
351
+ }
352
+ }
353
+
354
+ /**
355
+ * Copy children posts
356
+ */
357
+ function duplicate_post_copy_children($new_id, $post){
358
+ // get children
359
+ $children = get_posts(array( 'post_type' => 'any', 'numberposts' => -1, 'post_status' => 'any', 'post_parent' => $post->ID ));
360
+ // clone old attachments
361
+ foreach($children as $child){
362
+ if ($child->post_type == 'attachment') continue;
363
+ duplicate_post_create_duplicate($child, '', $new_id);
364
+ }
365
+ }
366
+
367
+ /**
368
+ * Copy comments
369
+ */
370
+ function duplicate_post_copy_comments($new_id, $post){
371
+ $comments = get_comments(array(
372
+ 'post_id' => $post->ID,
373
+ 'order' => 'ASC',
374
+ 'orderby' => 'comment_date_gmt'
375
+ ));
376
+
377
+ $old_id_to_new = array();
378
+ foreach ($comments as $comment){
379
+ //do not copy pingbacks or trackbacks
380
+ if(!empty($comment->comment_type)) continue;
381
+ $parent = ($comment->comment_parent && $old_id_to_new[$comment->comment_parent])?$old_id_to_new[$comment->comment_parent]:0;
382
+ $commentdata = array(
383
+ 'comment_post_ID' => $new_id,
384
+ 'comment_author' => $comment->comment_author,
385
+ 'comment_author_email' => $comment->comment_author_email,
386
+ 'comment_author_url' => $comment->comment_author_url,
387
+ 'comment_content' => $comment->comment_content,
388
+ 'comment_type' => '',
389
+ 'comment_parent' => $parent,
390
+ 'user_id' => $comment->user_id,
391
+ 'comment_author_IP' => $comment->comment_author_IP,
392
+ 'comment_agent' => $comment->comment_agent,
393
+ 'comment_karma' => $comment->comment_karma,
394
+ 'comment_approved' => $comment->comment_approved,
395
+ );
396
+ if(get_option('duplicate_post_copydate') == 1){
397
+ $commentdata['comment_date'] = $comment->comment_date ;
398
+ $commentdata['comment_date_gmt'] = get_gmt_from_date($comment->comment_date);
399
+ }
400
+ $new_comment_id = wp_insert_comment($commentdata);
401
+ $old_id_to_new[$comment->comment_ID] = $new_comment_id;
402
+ }
403
+ }
404
+
405
+ // Using our action hooks
406
+
407
+ add_action('dp_duplicate_post', 'duplicate_post_copy_post_meta_info', 10, 2);
408
+ add_action('dp_duplicate_page', 'duplicate_post_copy_post_meta_info', 10, 2);
409
+
410
+ if(get_option('duplicate_post_copychildren') == 1){
411
+ add_action('dp_duplicate_post', 'duplicate_post_copy_children', 20, 2);
412
+ add_action('dp_duplicate_page', 'duplicate_post_copy_children', 20, 2);
413
+ }
414
+
415
+ if(get_option('duplicate_post_copyattachments') == 1){
416
+ add_action('dp_duplicate_post', 'duplicate_post_copy_attachments', 30, 2);
417
+ add_action('dp_duplicate_page', 'duplicate_post_copy_attachments', 30, 2);
418
+ }
419
+
420
+ if(get_option('duplicate_post_copycomments') == 1){
421
+ add_action('dp_duplicate_post', 'duplicate_post_copy_comments', 40, 2);
422
+ add_action('dp_duplicate_page', 'duplicate_post_copy_comments', 40, 2);
423
+ }
424
+
425
+ add_action('dp_duplicate_post', 'duplicate_post_copy_post_taxonomies', 50, 2);
426
+ add_action('dp_duplicate_page', 'duplicate_post_copy_post_taxonomies', 50, 2);
427
+
428
+ /**
429
+ * Create a duplicate from a post
430
+ */
431
+ function duplicate_post_create_duplicate($post, $status = '', $parent_id = '') {
432
+
433
+ $duplicate_post_types_enabled = get_option('duplicate_post_types_enabled');
434
+
435
+ if (!duplicate_post_is_post_type_enabled($post->post_type) && $post->post_type != 'attachment')
436
+ wp_die(__('Copy features for this post type are not enabled in options page', 'duplicate-post'));
437
+
438
+ if ($post->post_type != 'attachment'){
439
+ $prefix = sanitize_text_field(get_option('duplicate_post_title_prefix'));
440
+ $suffix = sanitize_text_field(get_option('duplicate_post_title_suffix'));
441
+ $title = ' ';
442
+ if (get_option('duplicate_post_copytitle') == 1) {
443
+ $title = $post->post_title;
444
+ if (!empty($prefix)) $prefix.= " ";
445
+ if (!empty($suffix)) $suffix = " ".$suffix;
446
+ } else {
447
+ $title = ' ';
448
+ }
449
+ $title = trim($prefix.$title.$suffix);
450
+
451
+ if ($title == ''){
452
+ // empty title
453
+ $title = __('Untitled');
454
+ };
455
+
456
+
457
+ if (get_option('duplicate_post_copystatus') == 0) $status = 'draft';
458
+ }
459
+ $new_post_author = wp_get_current_user();
460
+
461
+ $menu_order = $post->menu_order;
462
+ $increase_menu_order_by = get_option('duplicate_post_increase_menu_order_by');
463
+ if(!empty($increase_menu_order_by) && is_numeric($increase_menu_order_by)){
464
+ $menu_order += intval($increase_menu_order_by);
465
+ }
466
+
467
+ $new_post = array(
468
+ 'menu_order' => $menu_order,
469
+ 'comment_status' => $post->comment_status,
470
+ 'ping_status' => $post->ping_status,
471
+ 'post_author' => $new_post_author->ID,
472
+ 'post_content' => (get_option('duplicate_post_copycontent') == '1') ? addslashes($post->post_content) : "" ,
473
+ 'post_excerpt' => (get_option('duplicate_post_copyexcerpt') == '1') ? addslashes($post->post_excerpt) : "",
474
+ 'post_mime_type' => $post->post_mime_type,
475
+ 'post_parent' => $new_post_parent = empty($parent_id)? $post->post_parent : $parent_id,
476
+ 'post_password' => (get_option('duplicate_post_copypassword') == '1') ? $post->post_password: "",
477
+ 'post_status' => $new_post_status = (empty($status))? $post->post_status: $status,
478
+ 'post_title' => addslashes($title),
479
+ 'post_type' => $post->post_type,
480
+ );
481
+
482
+ if(get_option('duplicate_post_copydate') == 1){
483
+ $new_post['post_date'] = $new_post_date = $post->post_date ;
484
+ $new_post['post_date_gmt'] = get_gmt_from_date($new_post_date);
485
+ }
486
+
487
+ $new_post_id = wp_insert_post($new_post);
488
+
489
+ // If the copy is published or scheduled, we have to set a proper slug.
490
+ if ($new_post_status == 'publish' || $new_post_status == 'future'){
491
+ $post_name = $post->post_name;
492
+ if(get_option('duplicate_post_copyslug') != 1){
493
+ $post_name = '';
494
+ }
495
+ $post_name = wp_unique_post_slug($post_name, $new_post_id, $new_post_status, $post->post_type, $new_post_parent);
496
+
497
+ $new_post = array();
498
+ $new_post['ID'] = $new_post_id;
499
+ $new_post['post_name'] = $post_name;
500
+
501
+ // Update the post into the database
502
+ wp_update_post( $new_post );
503
+ }
504
+
505
+ // If you have written a plugin which uses non-WP database tables to save
506
+ // information about a post you can hook this action to dupe that data.
507
+ if ($post->post_type == 'page' || (function_exists('is_post_type_hierarchical') && is_post_type_hierarchical( $post->post_type )))
508
+ do_action( 'dp_duplicate_page', $new_post_id, $post );
509
+ else
510
+ do_action( 'dp_duplicate_post', $new_post_id, $post );
511
+
512
+ delete_post_meta($new_post_id, '_dp_original');
513
+ add_post_meta($new_post_id, '_dp_original', $post->ID);
514
+
515
+ return $new_post_id;
516
+ }
517
+
518
+ //Add some links on the plugin page
519
+ add_filter('plugin_row_meta', 'duplicate_post_add_plugin_links', 10, 2);
520
+
521
+ function duplicate_post_add_plugin_links($links, $file) {
522
+ if ( $file == plugin_basename(dirname(__FILE__).'/duplicate-post.php') ) {
523
+ $links[] = '<a href="http://lopo.it/duplicate-post-plugin">' . __('Donate', 'duplicate-post') . '</a>';
524
+ $links[] = '<a href="https://translate.wordpress.org/projects/wp-plugins/duplicate-post">' . __('Translate', 'duplicate-post') . '</a>';
525
+ }
526
+ return $links;
527
+ }
528
  ?>
duplicate-post-common.php CHANGED
@@ -1,112 +1,137 @@
1
- <?php
2
-
3
- /**
4
- * Test if the user is allowed to copy posts
5
- */
6
- function duplicate_post_is_current_user_allowed_to_copy() {
7
- return current_user_can('copy_posts');
8
- }
9
-
10
- /**
11
- * Wrapper for the option 'duplicate_post_create_user_level'
12
- */
13
- function duplicate_post_get_copy_user_level() {
14
- return get_option( 'duplicate_post_copy_user_level' );
15
- }
16
-
17
- // Template tag
18
- /**
19
- * Retrieve duplicate post link for post.
20
- *
21
- *
22
- * @param int $id Optional. Post ID.
23
- * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
24
- * @param string $draft Optional, default to true
25
- * @return string
26
- */
27
- function duplicate_post_get_clone_post_link( $id = 0, $context = 'display', $draft = true ) {
28
- if ( !duplicate_post_is_current_user_allowed_to_copy() )
29
- return;
30
-
31
- if ( !$post = get_post( $id ) )
32
- return;
33
-
34
- if ($draft)
35
- $action_name = "duplicate_post_save_as_new_post_draft";
36
- else
37
- $action_name = "duplicate_post_save_as_new_post";
38
-
39
- if ( 'display' == $context )
40
- $action = '?action='.$action_name.'&amp;post='.$post->ID;
41
- else
42
- $action = '?action='.$action_name.'&post='.$post->ID;
43
-
44
- $post_type_object = get_post_type_object( $post->post_type );
45
- if ( !$post_type_object )
46
- return;
47
-
48
- return apply_filters( 'duplicate_post_get_clone_post_link', admin_url( "admin.php". $action ), $post->ID, $context );
49
- }
50
- /**
51
- * Display duplicate post link for post.
52
- *
53
- * @param string $link Optional. Anchor text.
54
- * @param string $before Optional. Display before edit link.
55
- * @param string $after Optional. Display after edit link.
56
- * @param int $id Optional. Post ID.
57
- */
58
- function duplicate_post_clone_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
59
- if ( !$post = get_post( $id ) )
60
- return;
61
-
62
- if ( !$url = duplicate_post_get_clone_post_link( $post->ID ) )
63
- return;
64
-
65
- if ( null === $link )
66
- $link = __('Copy to a new draft', DUPLICATE_POST_I18N_DOMAIN);
67
-
68
- $post_type_obj = get_post_type_object( $post->post_type );
69
- $link = '<a class="post-clone-link" href="' . $url . '" title="'
70
- . esc_attr(__("Copy to a new draft", DUPLICATE_POST_I18N_DOMAIN))
71
- .'">' . $link . '</a>';
72
- echo $before . apply_filters( 'duplicate_post_clone_post_link', $link, $post->ID ) . $after;
73
- }
74
- /**
75
- * Get original post .
76
- *
77
- * @param int $id Optional. Post ID.
78
- * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N.
79
- * @return mixed Post data
80
- */
81
- function duplicate_post_get_original($id = 0 , $output = OBJECT){
82
- if ( !$post = get_post( $id ) )
83
- return;
84
- $original_ID = get_post_meta( $post->ID, '_dp_original');
85
- if (empty($original_ID)) return null;
86
- $original_post = get_post($original_ID[0], $output);
87
- return $original_post;
88
- }
89
- // Admin bar
90
- function duplicate_post_admin_bar_render() {
91
- global $wp_admin_bar;
92
- $current_object = get_queried_object();
93
- if ( empty($current_object) )
94
- return;
95
- if ( ! empty( $current_object->post_type )
96
- && ( $post_type_object = get_post_type_object( $current_object->post_type ) )
97
- && duplicate_post_is_current_user_allowed_to_copy()
98
- && ( $post_type_object->show_ui || 'attachment' == $current_object->post_type ) )
99
- {
100
- $wp_admin_bar->add_menu( array(
101
- 'parent' => 'edit',
102
- 'id' => 'new_draft',
103
- 'title' => __("Copy to a new draft", DUPLICATE_POST_I18N_DOMAIN),
104
- 'href' => duplicate_post_get_clone_post_link( $current_object->ID )
105
- ) );
106
- }
107
- }
108
-
109
- if (get_option('duplicate_post_show_adminbar') == 1){
110
- add_action( 'wp_before_admin_bar_render', 'duplicate_post_admin_bar_render' );
111
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * Test if the user is allowed to copy posts
5
+ */
6
+ function duplicate_post_is_current_user_allowed_to_copy() {
7
+ return current_user_can('copy_posts');
8
+ }
9
+
10
+ /**
11
+ * Test if post type is enable to be copied
12
+ */
13
+ function duplicate_post_is_post_type_enabled($post_type){
14
+ $duplicate_post_types_enabled = get_option('duplicate_post_types_enabled', array ('post', 'page'));
15
+ return in_array($post_type, $duplicate_post_types_enabled);
16
+ }
17
+
18
+ /**
19
+ * Wrapper for the option 'duplicate_post_create_user_level'
20
+ */
21
+ function duplicate_post_get_copy_user_level() {
22
+ return get_option( 'duplicate_post_copy_user_level' );
23
+ }
24
+
25
+ // Template tag
26
+ /**
27
+ * Retrieve duplicate post link for post.
28
+ *
29
+ *
30
+ * @param int $id Optional. Post ID.
31
+ * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
32
+ * @param string $draft Optional, default to true
33
+ * @return string
34
+ */
35
+ function duplicate_post_get_clone_post_link( $id = 0, $context = 'display', $draft = true ) {
36
+ if ( !duplicate_post_is_current_user_allowed_to_copy() )
37
+ return;
38
+
39
+ if ( !$post = get_post( $id ) )
40
+ return;
41
+
42
+ if(!duplicate_post_is_post_type_enabled($post->post_type))
43
+ return;
44
+
45
+ if ($draft)
46
+ $action_name = "duplicate_post_save_as_new_post_draft";
47
+ else
48
+ $action_name = "duplicate_post_save_as_new_post";
49
+
50
+ if ( 'display' == $context )
51
+ $action = '?action='.$action_name.'&amp;post='.$post->ID;
52
+ else
53
+ $action = '?action='.$action_name.'&post='.$post->ID;
54
+
55
+ $post_type_object = get_post_type_object( $post->post_type );
56
+ if ( !$post_type_object )
57
+ return;
58
+
59
+ return apply_filters( 'duplicate_post_get_clone_post_link', admin_url( "admin.php". $action ), $post->ID, $context );
60
+ }
61
+ /**
62
+ * Display duplicate post link for post.
63
+ *
64
+ * @param string $link Optional. Anchor text.
65
+ * @param string $before Optional. Display before edit link.
66
+ * @param string $after Optional. Display after edit link.
67
+ * @param int $id Optional. Post ID.
68
+ */
69
+ function duplicate_post_clone_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
70
+ if ( !$post = get_post( $id ) )
71
+ return;
72
+
73
+ if ( !$url = duplicate_post_get_clone_post_link( $post->ID ) )
74
+ return;
75
+
76
+ if ( null === $link )
77
+ $link = __('Copy to a new draft', 'duplicate-post');
78
+
79
+ $post_type_obj = get_post_type_object( $post->post_type );
80
+ $link = '<a class="post-clone-link" href="' . $url . '" title="'
81
+ . esc_attr(__("Copy to a new draft", 'duplicate-post'))
82
+ .'">' . $link . '</a>';
83
+ echo $before . apply_filters( 'duplicate_post_clone_post_link', $link, $post->ID ) . $after;
84
+ }
85
+ /**
86
+ * Get original post .
87
+ *
88
+ * @param int $id Optional. Post ID.
89
+ * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N.
90
+ * @return mixed Post data
91
+ */
92
+ function duplicate_post_get_original($id = 0 , $output = OBJECT){
93
+ if ( !$post = get_post( $id ) )
94
+ return;
95
+ $original_ID = get_post_meta( $post->ID, '_dp_original');
96
+ if (empty($original_ID)) return null;
97
+ $original_post = get_post($original_ID[0], $output);
98
+ return $original_post;
99
+ }
100
+
101
+ // Admin bar
102
+ function duplicate_post_admin_bar_render() {
103
+ global $wp_admin_bar;
104
+ $current_object = get_queried_object();
105
+ if ( empty($current_object) )
106
+ return;
107
+ if ( ! empty( $current_object->post_type )
108
+ && ( $post_type_object = get_post_type_object( $current_object->post_type ) )
109
+ && duplicate_post_is_current_user_allowed_to_copy()
110
+ && ( $post_type_object->show_ui || 'attachment' == $current_object->post_type )
111
+ && (duplicate_post_is_post_type_enabled($current_object->post_type) ) )
112
+ {
113
+ $wp_admin_bar->add_menu( array(
114
+ 'id' => 'new_draft',
115
+ 'title' => __("Copy to a new draft", 'duplicate-post'),
116
+ 'href' => duplicate_post_get_clone_post_link( $current_object->ID )
117
+ ) );
118
+ }
119
+ }
120
+
121
+ function duplicate_post_add_css() {
122
+ wp_enqueue_style ( 'duplicate-post', plugins_url('/duplicate-post.css', __FILE__));
123
+ }
124
+
125
+ if (get_option('duplicate_post_show_adminbar') == 1){
126
+ add_action( 'wp_before_admin_bar_render', 'duplicate_post_admin_bar_render' );
127
+ add_action( 'wp_enqueue_scripts', 'duplicate_post_add_css');
128
+ }
129
+
130
+ /**
131
+ * Sort taxonomy objects: first public, then private
132
+ */
133
+ function duplicate_post_tax_obj_cmp($a, $b) {
134
+ return ($a->public < $b->public);
135
+ }
136
+
137
  ?>
duplicate-post-options.php CHANGED
@@ -1,215 +1,361 @@
1
- <?php
2
- /**
3
- * Add an option page
4
- */
5
- if ( is_admin() ){ // admin actions
6
- add_action('admin_menu', 'duplicate_post_menu');
7
- add_action( 'admin_init', 'duplicate_post_register_settings');
8
- }
9
-
10
- function duplicate_post_register_settings() { // whitelist options
11
- register_setting( 'duplicate_post_group', 'duplicate_post_copydate');
12
- register_setting( 'duplicate_post_group', 'duplicate_post_copyexcerpt');
13
- register_setting( 'duplicate_post_group', 'duplicate_post_copyattachments');
14
- register_setting( 'duplicate_post_group', 'duplicate_post_copychildren');
15
- register_setting( 'duplicate_post_group', 'duplicate_post_copystatus');
16
- register_setting( 'duplicate_post_group', 'duplicate_post_blacklist');
17
- register_setting( 'duplicate_post_group', 'duplicate_post_taxonomies_blacklist');
18
- register_setting( 'duplicate_post_group', 'duplicate_post_title_prefix');
19
- register_setting( 'duplicate_post_group', 'duplicate_post_title_suffix');
20
- register_setting( 'duplicate_post_group', 'duplicate_post_roles');
21
- register_setting( 'duplicate_post_group', 'duplicate_post_show_row');
22
- register_setting( 'duplicate_post_group', 'duplicate_post_show_adminbar');
23
- register_setting( 'duplicate_post_group', 'duplicate_post_show_submitbox');
24
- }
25
-
26
-
27
- function duplicate_post_menu() {
28
- add_options_page(__("Duplicate Post Options", DUPLICATE_POST_I18N_DOMAIN), __("Duplicate Post", DUPLICATE_POST_I18N_DOMAIN), 'manage_options', 'duplicatepost', 'duplicate_post_options');
29
- }
30
-
31
- function duplicate_post_options() {
32
-
33
- if ( current_user_can( 'edit_users' ) && (isset($_GET['settings-updated']) && $_GET['settings-updated'] == true)){
34
- global $wp_roles;
35
- $roles = $wp_roles->get_names();
36
-
37
- $dp_roles = get_option('duplicate_post_roles');
38
- if ( $dp_roles == "" ) $dp_roles = array();
39
-
40
- foreach ($roles as $name => $display_name){
41
- $role = get_role($name);
42
-
43
- // role should have at least edit_posts capability
44
- if ( !$role->has_cap('edit_posts') ) continue;
45
-
46
- /* If the role doesn't have the capability and it was selected, add it. */
47
- if ( !$role->has_cap( 'copy_posts' ) && in_array($name, $dp_roles) )
48
- $role->add_cap( 'copy_posts' );
49
-
50
- /* If the role has the capability and it wasn't selected, remove it. */
51
- elseif ( $role->has_cap( 'copy_posts' ) && !in_array($name, $dp_roles) )
52
- $role->remove_cap( 'copy_posts' );
53
- }
54
- }
55
-
56
- ?>
57
- <div class="wrap">
58
- <div id="icon-options-general" class="icon32">
59
- <br>
60
- </div>
61
- <h2>
62
- <?php _e("Duplicate Post Options", DUPLICATE_POST_I18N_DOMAIN); ?>
63
- </h2>
64
-
65
- <div
66
- style="border: solid 1px #aaaaaa; background-color: #eeeeee; margin: 9px 15px 4px 0; padding: 5px; text-align: center; font-weight: bold; float: left;">
67
- <a href="http://lopo.it/duplicate-post-plugin"><?php _e('Visit plugin site'); ?>
68
- </a> - <a href="http://lopo.it/duplicate-post-plugin"><?php _e('Translate', DUPLICATE_POST_I18N_DOMAIN); ?>
69
- </a> - <a href="http://lopo.it/duplicate-post-plugin"><?php _e('Donate', DUPLICATE_POST_I18N_DOMAIN); ?> (10¢)
70
- </a> <form style="display: inline-block; vertical-align: middle;" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"><input type="hidden" name="cmd" value="_s-xclick">
71
- <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----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-----END PKCS7-----
72
- "><input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
73
- <img alt="" border="0" src="https://www.paypalobjects.com/it_IT/i/scr/pixel.gif" width="1" height="1"></form>
74
-
75
-
76
- </div>
77
-
78
- <form method="post" action="options.php">
79
- <?php settings_fields('duplicate_post_group'); ?>
80
-
81
- <table class="form-table">
82
-
83
- <tr valign="top">
84
- <th scope="row"><?php _e("Copy post/page date also", DUPLICATE_POST_I18N_DOMAIN); ?>
85
- </th>
86
- <td><input type="checkbox" name="duplicate_post_copydate" value="1" <?php if(get_option('duplicate_post_copydate') == 1) echo 'checked="checked"'; ?>"/>
87
- <span class="description"><?php _e("Normally, the new copy has its publication date set to current time: check the box to copy the original post/page date", DUPLICATE_POST_I18N_DOMAIN); ?>
88
- </span>
89
- </td>
90
- </tr>
91
- <tr valign="top">
92
- <th scope="row"><?php _e("Copy post/page status", DUPLICATE_POST_I18N_DOMAIN); ?>
93
- </th>
94
- <td><input type="checkbox" name="duplicate_post_copystatus"
95
- value="1" <?php if(get_option('duplicate_post_copystatus') == 1) echo 'checked="checked"'; ?>"/>
96
- <span class="description"><?php _e("Copy the original post status (draft, published, pending) when cloning from the post list.", DUPLICATE_POST_I18N_DOMAIN); ?>
97
- </span>
98
- </td>
99
- </tr>
100
- <tr valign="top">
101
- <th scope="row"><?php _e("Copy excerpt", DUPLICATE_POST_I18N_DOMAIN); ?>
102
- </th>
103
- <td><input type="checkbox" name="duplicate_post_copyexcerpt"
104
- value="1" <?php if(get_option('duplicate_post_copyexcerpt') == 1) echo 'checked="checked"'; ?>"/>
105
- <span class="description"><?php _e("Copy the excerpt from the original post/page", DUPLICATE_POST_I18N_DOMAIN); ?>
106
- </span>
107
- </td>
108
- </tr>
109
- <tr valign="top">
110
- <th scope="row"><?php _e("Copy attachments", DUPLICATE_POST_I18N_DOMAIN); ?>
111
- </th>
112
- <td><input type="checkbox" name="duplicate_post_copyattachments"
113
- value="1" <?php if(get_option('duplicate_post_copyattachments') == 1) echo 'checked="checked"'; ?>"/>
114
- <span class="description"><?php _e("Copy the attachments from the original post/page", DUPLICATE_POST_I18N_DOMAIN); ?>
115
- </span>
116
- </td>
117
- </tr>
118
- <tr valign="top">
119
- <th scope="row"><?php _e("Copy children", DUPLICATE_POST_I18N_DOMAIN); ?>
120
- </th>
121
- <td><input type="checkbox" name="duplicate_post_copychildren"
122
- value="1" <?php if(get_option('duplicate_post_copychildren') == 1) echo 'checked="checked"'; ?>"/>
123
- <span class="description"><?php _e("Copy the children from the original post/page", DUPLICATE_POST_I18N_DOMAIN); ?>
124
- </span>
125
- </td>
126
- </tr>
127
- <tr valign="top">
128
- <th scope="row"><?php _e("Do not copy these fields", DUPLICATE_POST_I18N_DOMAIN); ?>
129
- </th>
130
- <td><input type="text" name="duplicate_post_blacklist"
131
- value="<?php echo get_option('duplicate_post_blacklist'); ?>" /> <span
132
- class="description"><?php _e("Comma-separated list of meta fields that must not be copied", DUPLICATE_POST_I18N_DOMAIN); ?>
133
- </span>
134
- </td>
135
- </tr>
136
- <tr valign="top">
137
- <th scope="row"><?php _e("Do not copy these taxonomies", DUPLICATE_POST_I18N_DOMAIN); ?>
138
- </th>
139
- <td><div
140
- style="height: 100px; width: 300px; padding: 5px; overflow: auto; border: 1px solid #ccc">
141
- <?php $taxonomies=get_taxonomies(array('public' => true),'objects');
142
- $taxonomies_blacklist = get_option('duplicate_post_taxonomies_blacklist');
143
- if ($taxonomies_blacklist == "") $taxonomies_blacklist = array();
144
- foreach ($taxonomies as $taxonomy ) : ?>
145
- <label style="display: block;"> <input type="checkbox"
146
- name="duplicate_post_taxonomies_blacklist[]"
147
- value="<?php echo $taxonomy->name?>"
148
- <?php if(in_array($taxonomy->name,$taxonomies_blacklist)) echo 'checked="checked"'?> />
149
- <?php echo $taxonomy->labels->name?> </label>
150
- <?php endforeach; ?>
151
- </div> <span class="description"><?php _e("Select the taxonomies you don't want to be copied", DUPLICATE_POST_I18N_DOMAIN); ?>
152
- </span>
153
- </td>
154
- </tr>
155
- <tr valign="top">
156
- <th scope="row"><?php _e("Title prefix", DUPLICATE_POST_I18N_DOMAIN); ?>
157
- </th>
158
- <td><input type="text" name="duplicate_post_title_prefix"
159
- value="<?php echo get_option('duplicate_post_title_prefix'); ?>" />
160
- <span class="description"><?php _e("Prefix to be added before the original title, e.g. \"Copy of\" (blank for no prefix)", DUPLICATE_POST_I18N_DOMAIN); ?>
161
- </span>
162
- </td>
163
- </tr>
164
- <tr valign="top">
165
- <th scope="row"><?php _e("Title suffix", DUPLICATE_POST_I18N_DOMAIN); ?>
166
- </th>
167
- <td><input type="text" name="duplicate_post_title_suffix"
168
- value="<?php echo get_option('duplicate_post_title_suffix'); ?>" />
169
- <span class="description"><?php _e("Suffix to be added after the original title, e.g. \"(dup)\" (blank for no suffix)", DUPLICATE_POST_I18N_DOMAIN); ?>
170
- </span>
171
- </td>
172
- </tr>
173
- <tr valign="top">
174
- <th scope="row"><?php _e("Roles allowed to copy", DUPLICATE_POST_I18N_DOMAIN); ?>
175
- </th>
176
- <td><div
177
- style="height: 100px; width: 300px; padding: 5px; overflow: auto; border: 1px solid #ccc">
178
- <?php global $wp_roles;
179
- $roles = $wp_roles->get_names();
180
- foreach ($roles as $name => $display_name): $role = get_role($name);
181
- if ( !$role->has_cap('edit_posts') ) continue; ?>
182
- <label style="display: block;"> <input type="checkbox"
183
- name="duplicate_post_roles[]" value="<?php echo $name ?>"
184
- <?php if($role->has_cap('copy_posts')) echo 'checked="checked"'?> />
185
- <?php echo translate_user_role($display_name); ?> </label>
186
- <?php endforeach; ?>
187
- </div> <span class="description"><?php _e("Warning: users will be able to copy all posts, even those of other users", DUPLICATE_POST_I18N_DOMAIN); ?>
188
- </span>
189
- </td>
190
- </tr>
191
- <tr valign="top">
192
- <th scope="row"><?php _e("Show links in", DUPLICATE_POST_I18N_DOMAIN); ?>
193
- </th>
194
- <td><label style="display: block"><input type="checkbox"
195
- name="duplicate_post_show_row" value="1" <?php if(get_option('duplicate_post_show_row') == 1) echo 'checked="checked"'; ?>"/>
196
- <?php _e("Post list", DUPLICATE_POST_I18N_DOMAIN); ?> </label> <label
197
- style="display: block"><input type="checkbox"
198
- name="duplicate_post_show_submitbox" value="1" <?php if(get_option('duplicate_post_show_submitbox') == 1) echo 'checked="checked"'; ?>"/>
199
- <?php _e("Edit screen", DUPLICATE_POST_I18N_DOMAIN); ?> </label> <label
200
- style="display: block"><input type="checkbox"
201
- name="duplicate_post_show_adminbar" value="1" <?php if(get_option('duplicate_post_show_adminbar') == 1) echo 'checked="checked"'; ?>"/>
202
- <?php _e("Admin bar", DUPLICATE_POST_I18N_DOMAIN); ?> (WP 3.1+)</label>
203
- </td>
204
- </tr>
205
- </table>
206
- <p class="submit">
207
- <input type="submit" class="button-primary"
208
- value="<?php _e('Save Changes', DUPLICATE_POST_I18N_DOMAIN) ?>" />
209
- </p>
210
-
211
- </form>
212
- </div>
213
- <?php
214
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  ?>
1
+ <?php
2
+ /**
3
+ * Add an option page
4
+ */
5
+ if ( !defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ if ( is_admin() ){ // admin actions
10
+ add_action('admin_menu', 'duplicate_post_menu');
11
+ add_action( 'admin_init', 'duplicate_post_register_settings');
12
+ }
13
+
14
+ function duplicate_post_register_settings() { // whitelist options
15
+ register_setting( 'duplicate_post_group', 'duplicate_post_copytitle');
16
+ register_setting( 'duplicate_post_group', 'duplicate_post_copydate');
17
+ register_setting( 'duplicate_post_group', 'duplicate_post_copystatus');
18
+ register_setting( 'duplicate_post_group', 'duplicate_post_copyslug');
19
+ register_setting( 'duplicate_post_group', 'duplicate_post_copyexcerpt');
20
+ register_setting( 'duplicate_post_group', 'duplicate_post_copycontent');
21
+ register_setting( 'duplicate_post_group', 'duplicate_post_copypassword');
22
+ register_setting( 'duplicate_post_group', 'duplicate_post_copyattachments');
23
+ register_setting( 'duplicate_post_group', 'duplicate_post_copychildren');
24
+ register_setting( 'duplicate_post_group', 'duplicate_post_copycomments');
25
+ register_setting( 'duplicate_post_group', 'duplicate_post_blacklist');
26
+ register_setting( 'duplicate_post_group', 'duplicate_post_taxonomies_blacklist');
27
+ register_setting( 'duplicate_post_group', 'duplicate_post_title_prefix');
28
+ register_setting( 'duplicate_post_group', 'duplicate_post_title_suffix');
29
+ register_setting( 'duplicate_post_group', 'duplicate_post_increase_menu_order_by');
30
+ register_setting( 'duplicate_post_group', 'duplicate_post_roles');
31
+ register_setting( 'duplicate_post_group', 'duplicate_post_types_enabled');
32
+ register_setting( 'duplicate_post_group', 'duplicate_post_show_row');
33
+ register_setting( 'duplicate_post_group', 'duplicate_post_show_adminbar');
34
+ register_setting( 'duplicate_post_group', 'duplicate_post_show_submitbox');
35
+ }
36
+
37
+
38
+ function duplicate_post_menu() {
39
+ add_options_page(__("Duplicate Post Options", 'duplicate-post'), __("Duplicate Post", 'duplicate-post'), 'manage_options', 'duplicatepost', 'duplicate_post_options');
40
+ }
41
+
42
+ function duplicate_post_options() {
43
+
44
+ if ( current_user_can( 'promote_users' ) && (isset($_GET['settings-updated']) && $_GET['settings-updated'] == true)){
45
+ global $wp_roles;
46
+ $roles = $wp_roles->get_names();
47
+
48
+ $dp_roles = get_option('duplicate_post_roles');
49
+ if ( $dp_roles == "" ) $dp_roles = array();
50
+
51
+ foreach ($roles as $name => $display_name){
52
+ $role = get_role($name);
53
+
54
+ // role should have at least edit_posts capability
55
+ if ( !$role->has_cap('edit_posts') ) continue;
56
+
57
+ /* If the role doesn't have the capability and it was selected, add it. */
58
+ if ( !$role->has_cap( 'copy_posts' ) && in_array($name, $dp_roles) )
59
+ $role->add_cap( 'copy_posts' );
60
+
61
+ /* If the role has the capability and it wasn't selected, remove it. */
62
+ elseif ( $role->has_cap( 'copy_posts' ) && !in_array($name, $dp_roles) )
63
+ $role->remove_cap( 'copy_posts' );
64
+ }
65
+ }
66
+ ?>
67
+ <div class="wrap">
68
+ <div id="icon-options-general" class="icon32">
69
+ <br>
70
+ </div>
71
+ <h1>
72
+ <?php _e("Duplicate Post Options", 'duplicate-post'); ?>
73
+ </h1>
74
+
75
+ <div
76
+ style="margin: 9px 15px 4px 0; padding: 5px; text-align: center; font-weight: bold; float: left;">
77
+ <a href="http://lopo.it/duplicate-post-plugin"><?php _e('Visit plugin site'); ?>
78
+ </a> - <a
79
+ href="https://translate.wordpress.org/projects/wp-plugins/duplicate-post"><?php _e('Translate', 'duplicate-post'); ?>
80
+ </a> - <a href="https://wordpress.org/plugins/duplicate-post/faq/"><?php _e('FAQ', 'duplicate-post'); ?>
81
+ </a> - <a href="http://lopo.it/duplicate-post-plugin"><?php _e('Donate', 'duplicate-post'); ?>
82
+ (10¢) </a>
83
+ <form style="display: inline-block; vertical-align: middle;"
84
+ action="https://www.paypal.com/cgi-bin/webscr" method="post"
85
+ target="_top">
86
+ <input type="hidden" name="cmd" value="_s-xclick"> <input
87
+ type="hidden" name="encrypted"
88
+ value="-----BEGIN PKCS7-----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-----END PKCS7-----
89
+ "><input type="image"
90
+ src="https://www.paypalobjects.com/en_GB/i/btn/btn_donate_SM.gif"
91
+ border="0" name="submit"
92
+ alt="PayPal The safer, easier way to pay online."> <img alt=""
93
+ border="0" src="https://www.paypalobjects.com/it_IT/i/scr/pixel.gif"
94
+ width="1" height="1">
95
+ </form>
96
+
97
+
98
+ </div>
99
+
100
+ <script>
101
+ jQuery(document).on( 'click', '.nav-tab-wrapper a', function() {
102
+ jQuery('.nav-tab').removeClass('nav-tab-active');
103
+ jQuery(this).addClass('nav-tab-active');
104
+ jQuery('section').hide();
105
+ jQuery('section').eq(jQuery(this).index()).show();
106
+ return false;
107
+ })
108
+
109
+ function toggle_private_taxonomies(){
110
+ jQuery('.taxonomy_private').toggle();
111
+ }
112
+ jQuery(function(){
113
+ jQuery('.taxonomy_private').hide();
114
+ });
115
+
116
+ </script>
117
+
118
+ <style>
119
+ h2.nav-tab-wrapper {
120
+ margin: 22px 0 0 0;
121
+ }
122
+
123
+ h2 .nav-tab:focus {
124
+ color: #555;
125
+ box-shadow: none;
126
+ }
127
+
128
+ #sections {
129
+ padding: 22px;
130
+ background: #fff;
131
+ border: 1px solid #ccc;
132
+ border-top: 0px;
133
+ }
134
+
135
+ section {
136
+ display: none;
137
+ }
138
+
139
+ section:first-of-type {
140
+ display: block;
141
+ }
142
+
143
+ .no-js h2.nav-tab-wrapper {
144
+ display: none;
145
+ }
146
+
147
+ .no-js #sections {
148
+ border-top: 1px solid #ccc;
149
+ margin-top: 22px;
150
+ }
151
+
152
+ .no-js section {
153
+ border-top: 1px dashed #aaa;
154
+ margin-top: 22px;
155
+ padding-top: 22px;
156
+ }
157
+
158
+ .no-js section:first-child {
159
+ margin: 0px;
160
+ padding: 0px;
161
+ border: 0px;
162
+ }
163
+
164
+ label {
165
+ display: block;
166
+ }
167
+
168
+ label.taxonomy_private {
169
+ font-style: italic;
170
+ }
171
+
172
+ a.toggle_link {
173
+ font-size: small;
174
+ }
175
+ </style>
176
+
177
+
178
+ <form method="post" action="options.php" style="clear: both">
179
+ <?php settings_fields('duplicate_post_group'); ?>
180
+
181
+ <h2 class="nav-tab-wrapper">
182
+ <a class="nav-tab nav-tab-active"
183
+ href="<?php echo admin_url() ?>/index.php?page=duplicate-post-what"><?php _e('What to copy', 'duplicate-post'); ?>
184
+ </a> <a class="nav-tab"
185
+ href="<?php echo admin_url() ?>/index.php?page=duplicate-post-who"><?php _e('Permissions', 'duplicate-post'); ?>
186
+ </a> <a class="nav-tab"
187
+ href="<?php echo admin_url() ?>/index.php?page=duplicate-post-where"><?php _e('Display', 'duplicate-post'); ?>
188
+ </a>
189
+ </h2>
190
+
191
+ <section>
192
+
193
+ <table class="form-table">
194
+ <tr valign="top">
195
+ <th scope="row"><?php _e('Post/page elements to copy', 'duplicate-post'); ?>
196
+ </th>
197
+ <td colspan="2"><label> <input type="checkbox"
198
+ name="duplicate_post_copytitle" value="1" <?php if(get_option('duplicate_post_copytitle') == 1) echo 'checked="checked"'; ?>"/>
199
+ <?php _e("Title", 'default'); ?>
200
+ </label> <label> <input type="checkbox"
201
+ name="duplicate_post_copydate" value="1" <?php if(get_option('duplicate_post_copydate') == 1) echo 'checked="checked"'; ?>"/>
202
+ <?php _e("Date", 'default'); ?>
203
+ </label> <label> <input type="checkbox"
204
+ name="duplicate_post_copystatus" value="1" <?php if(get_option('duplicate_post_copystatus') == 1) echo 'checked="checked"'; ?>"/>
205
+ <?php _e("Status", 'default'); ?>
206
+ </label> <label> <input type="checkbox"
207
+ name="duplicate_post_copyslug" value="1" <?php if(get_option('duplicate_post_copyslug') == 1) echo 'checked="checked"'; ?>"/>
208
+ <?php _e("Slug", 'default'); ?>
209
+ </label> <label> <input type="checkbox"
210
+ name="duplicate_post_copyexcerpt" value="1" <?php if(get_option('duplicate_post_copyexcerpt') == 1) echo 'checked="checked"'; ?>"/>
211
+ <?php _e("Excerpt", 'default'); ?>
212
+ </label> <label> <input type="checkbox"
213
+ name="duplicate_post_copycontent" value="1" <?php if(get_option('duplicate_post_copycontent') == 1) echo 'checked="checked"'; ?>"/>
214
+ <?php _e("Content", 'default'); ?>
215
+ </label> <label> <input type="checkbox"
216
+ name="duplicate_post_copypassword" value="1" <?php if(get_option('duplicate_post_copypassword') == 1) echo 'checked="checked"'; ?>"/>
217
+ <?php _e("Password", 'default'); ?>
218
+ </label> <label> <input type="checkbox"
219
+ name="duplicate_post_copyattachments" value="1" <?php if(get_option('duplicate_post_copyattachments') == 1) echo 'checked="checked"'; ?>"/>
220
+ <?php _e("Attachments", 'duplicate-post'); ?>
221
+ </label> <label> <input type="checkbox"
222
+ name="duplicate_post_copychildren" value="1" <?php if(get_option('duplicate_post_copychildren') == 1) echo 'checked="checked"'; ?>"/>
223
+ <?php _e("Children", 'duplicate-post'); ?>
224
+ </label> <label> <input type="checkbox"
225
+ name="duplicate_post_copycomments" value="1" <?php if(get_option('duplicate_post_copycomments') == 1) echo 'checked="checked"'; ?>"/>
226
+ <?php _e("Comments", 'default'); ?> (<?php _e("except pingbacks and trackbacks", 'duplicate-post'); ?>)
227
+ </label>
228
+ </td>
229
+ </tr>
230
+ <tr valign="top">
231
+ <th scope="row"><?php _e("Title prefix", 'duplicate-post'); ?>
232
+ </th>
233
+ <td><input type="text" name="duplicate_post_title_prefix"
234
+ value="<?php echo get_option('duplicate_post_title_prefix'); ?>" />
235
+ </td>
236
+ <td><span class="description"><?php _e("Prefix to be added before the title, e.g. \"Copy of\" (blank for no prefix)", 'duplicate-post'); ?>
237
+ </span>
238
+ </td>
239
+ </tr>
240
+ <tr valign="top">
241
+ <th scope="row"><?php _e("Title suffix", 'duplicate-post'); ?>
242
+ </th>
243
+ <td><input type="text" name="duplicate_post_title_suffix"
244
+ value="<?php echo get_option('duplicate_post_title_suffix'); ?>" />
245
+ </td>
246
+ <td><span class="description"><?php _e("Suffix to be added after the title, e.g. \"(dup)\" (blank for no suffix)", 'duplicate-post'); ?>
247
+ </span>
248
+ </td>
249
+ </tr>
250
+ <tr valign="top">
251
+ <th scope="row"><?php _e("Increase menu order by", 'duplicate-post'); ?>
252
+ </th>
253
+ <td><input type="text" name="duplicate_post_increase_menu_order_by"
254
+ value="<?php echo get_option('duplicate_post_increase_menu_order_by'); ?>" />
255
+ </td>
256
+ <td><span class="description"><?php _e("Add this number to the original menu order (blank or zero to retain the value)", 'duplicate-post'); ?>
257
+ </span>
258
+ </td>
259
+ </tr>
260
+ <tr valign="top">
261
+ <th scope="row"><?php _e("Do not copy these fields", 'duplicate-post'); ?>
262
+ </th>
263
+ <td id="textfield"><input type="text"
264
+ name="duplicate_post_blacklist"
265
+ value="<?php echo get_option('duplicate_post_blacklist'); ?>" /></td>
266
+ <td><span class="description"><?php _e("Comma-separated list of meta fields that must not be copied", 'duplicate-post'); ?><br />
267
+ <small><?php _e("Add <code>_thumbnail_id</code> to prevent featured images to be copied", 'duplicate-post'); ?>
268
+ </small> </span>
269
+ </td>
270
+ </tr>
271
+ <tr valign="top">
272
+ <th scope="row"><?php _e("Do not copy these taxonomies", 'duplicate-post'); ?><br />
273
+ <a class="toggle_link" href="#"
274
+ onclick="toggle_private_taxonomies();return false;"><?php _e('Show/hide private taxonomies', 'duplicate-post');?>
275
+ </a>
276
+ </th>
277
+ <td colspan="2"><?php $taxonomies=get_taxonomies(array(),'objects'); usort($taxonomies, 'duplicate_post_tax_obj_cmp');
278
+ $taxonomies_blacklist = get_option('duplicate_post_taxonomies_blacklist');
279
+ if ($taxonomies_blacklist == "") $taxonomies_blacklist = array();
280
+ foreach ($taxonomies as $taxonomy ) : ?> <label
281
+ class="taxonomy_<?php echo ($taxonomy->public)?'public':'private';?>">
282
+ <input type="checkbox"
283
+ name="duplicate_post_taxonomies_blacklist[]"
284
+ value="<?php echo $taxonomy->name?>"
285
+ <?php if(in_array($taxonomy->name, $taxonomies_blacklist)) echo 'checked="checked"'?> />
286
+ <?php echo $taxonomy->labels->name.' ['.$taxonomy->name.']'; ?>
287
+ </label> <?php endforeach; ?> <span class="description"><?php _e("Select the taxonomies you don't want to be copied", 'duplicate-post'); ?>
288
+ </span>
289
+ </td>
290
+ </tr>
291
+ </table>
292
+ </section>
293
+ <section>
294
+ <table class="form-table">
295
+ <?php if ( current_user_can( 'promote_users' ) ){ ?>
296
+ <tr valign="top">
297
+ <th scope="row"><?php _e("Roles allowed to copy", 'duplicate-post'); ?>
298
+ </th>
299
+ <td><?php global $wp_roles;
300
+ $roles = $wp_roles->get_names();
301
+ foreach ($roles as $name => $display_name): $role = get_role($name);
302
+ if ( !$role->has_cap('edit_posts') ) continue; ?> <label> <input
303
+ type="checkbox" name="duplicate_post_roles[]"
304
+ value="<?php echo $name ?>"
305
+ <?php if($role->has_cap('copy_posts')) echo 'checked="checked"'?> />
306
+ <?php echo translate_user_role($display_name); ?>
307
+ </label> <?php endforeach; ?> <span class="description"><?php _e("Warning: users will be able to copy all posts, even those of other users", 'duplicate-post'); ?><br />
308
+ <?php _e("Passwords and contents of password-protected posts may become visible to undesired users and visitors", 'duplicate-post'); ?>
309
+ </span>
310
+ </td>
311
+ </tr>
312
+ <?php } ?>
313
+ <tr valign="top">
314
+ <th scope="row"><?php _e("Enable for these post types", 'duplicate-post'); ?>
315
+ </th>
316
+ <td><?php $post_types = get_post_types(array('public' => true),'objects');
317
+ foreach ($post_types as $post_type_object ) :
318
+ if ($post_type_object->name == 'attachment') continue; ?> <label> <input
319
+ type="checkbox" name="duplicate_post_types_enabled[]"
320
+ value="<?php echo $post_type_object->name?>"
321
+ <?php if(duplicate_post_is_post_type_enabled($post_type_object->name)) echo 'checked="checked"'?> />
322
+ <?php echo $post_type_object->labels->name?>
323
+ </label> <?php endforeach; ?> <span class="description"><?php _e("Select the post types you want the plugin to be enabled", 'duplicate-post'); ?>
324
+ <br /> <?php _e("Whether the links are displayed for custom post types registered by themes or plugins depends on their use of standard WordPress UI elements", 'duplicate-post'); ?>
325
+ </span>
326
+ </td>
327
+ </tr>
328
+ </table>
329
+ </section>
330
+ <section>
331
+ <table class="form-table">
332
+ <tr valign="top">
333
+ <th scope="row"><?php _e("Show links in", 'duplicate-post'); ?>
334
+ </th>
335
+ <td><label><input type="checkbox" name="duplicate_post_show_row"
336
+ value="1" <?php if(get_option('duplicate_post_show_row') == 1) echo 'checked="checked"'; ?>"/>
337
+ <?php _e("Post list", 'duplicate-post'); ?> </label> <label><input
338
+ type="checkbox" name="duplicate_post_show_submitbox" value="1" <?php if(get_option('duplicate_post_show_submitbox') == 1) echo 'checked="checked"'; ?>"/>
339
+ <?php _e("Edit screen", 'duplicate-post'); ?> </label> <label><input
340
+ type="checkbox" name="duplicate_post_show_adminbar" value="1" <?php if(get_option('duplicate_post_show_adminbar') == 1) echo 'checked="checked"'; ?>"/>
341
+ <?php _e("Admin bar", 'duplicate-post'); ?> </label>
342
+ </td>
343
+ </tr>
344
+ <tr valign="top">
345
+ <td colspan="2"><span class="description"><?php _e("Whether the links are displayed for custom post types registered by themes or plugins depends on their use of standard WordPress UI elements", 'duplicate-post'); ?>
346
+ <br /> <?php printf(__('You can also use the template tag duplicate_post_clone_post_link( $link, $before, $after, $id ). More info <a href="%s">here</a>', 'duplicate-post'), 'https://wordpress.org/plugins/duplicate-post/other_notes/'); ?>
347
+ </span>
348
+ </td>
349
+ </tr>
350
+ </table>
351
+ </section>
352
+ <p class="submit">
353
+ <input type="submit" class="button-primary"
354
+ value="<?php _e('Save Changes', 'duplicate-post') ?>" />
355
+ </p>
356
+
357
+ </form>
358
+ </div>
359
+ <?php
360
+ }
361
  ?>
duplicate-post.css ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #wpadminbar #wp-admin-bar-new_draft > .ab-item::before {
2
+ content: "\f498\f344\f498";
3
+ top: 2px;
4
+ }
5
+
6
+ @media screen and (max-width: 782px){
7
+ #wpadminbar li#wp-admin-bar-new_draft{
8
+ display: block;
9
+ }
10
+
11
+ #wpadminbar #wp-admin-bar-new_draft > .ab-item {
12
+ text-indent: 100%;
13
+ white-space: nowrap;
14
+ overflow: hidden;
15
+ width: 95px;
16
+ padding: 0;
17
+ color: #999;
18
+ position: relative;
19
+ }
20
+
21
+ #wpadminbar #wp-admin-bar-new_draft > .ab-item::before {
22
+ display: block;
23
+ text-indent: 0;
24
+ font: 400 32px/1 dashicons;
25
+ speak: none;
26
+ top: 7px;
27
+ width: 95px;
28
+ text-align: center;
29
+ -webkit-font-smoothing: antialiased;
30
+ -moz-osx-font-smoothing: grayscale;
31
+ }
32
+ }
duplicate-post.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Duplicate Post
4
  Plugin URI: http://lopo.it/duplicate-post-plugin/
5
  Description: Clone posts and pages.
6
- Version: 2.6
7
  Author: Enrico Battocchi
8
  Author URI: http://lopo.it
9
  Text Domain: duplicate-post
@@ -26,17 +26,22 @@ 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
- // i18n plugin domain
30
- define('DUPLICATE_POST_I18N_DOMAIN', 'duplicate-post');
 
31
 
32
  // Version of the plugin
33
- define('DUPLICATE_POST_CURRENT_VERSION', '2.6' );
 
34
 
35
  /**
36
  * Initialise the internationalisation domain
37
  */
38
- load_plugin_textdomain(DUPLICATE_POST_I18N_DOMAIN,
39
- 'wp-content/plugins/duplicate-post/languages','duplicate-post/languages');
 
 
 
40
 
41
  add_filter("plugin_action_links_".plugin_basename(__FILE__), "duplicate_post_plugin_actions", 10, 4);
42
 
@@ -50,4 +55,6 @@ require_once (dirname(__FILE__).'/duplicate-post-common.php');
50
  if (is_admin()){
51
  require_once (dirname(__FILE__).'/duplicate-post-admin.php');
52
  }
 
 
53
  ?>
3
  Plugin Name: Duplicate Post
4
  Plugin URI: http://lopo.it/duplicate-post-plugin/
5
  Description: Clone posts and pages.
6
+ Version: 3.0
7
  Author: Enrico Battocchi
8
  Author URI: http://lopo.it
9
  Text Domain: duplicate-post
26
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
  */
28
 
29
+ if ( ! defined( 'ABSPATH' ) ) {
30
+ exit;
31
+ }
32
 
33
  // Version of the plugin
34
+ define('DUPLICATE_POST_CURRENT_VERSION', '3.0' );
35
+
36
 
37
  /**
38
  * Initialise the internationalisation domain
39
  */
40
+ function duplicate_post_load_plugin_textdomain() {
41
+ load_plugin_textdomain( 'duplicate-post', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
42
+ }
43
+ add_action( 'plugins_loaded', 'duplicate_post_load_plugin_textdomain' );
44
+
45
 
46
  add_filter("plugin_action_links_".plugin_basename(__FILE__), "duplicate_post_plugin_actions", 10, 4);
47
 
55
  if (is_admin()){
56
  require_once (dirname(__FILE__).'/duplicate-post-admin.php');
57
  }
58
+
59
+ register_activation_hook( __FILE__, 'duplicate_post_plugin_upgrade' );
60
  ?>
languages/duplicate-post-ca.mo DELETED
Binary file
languages/duplicate-post-cs_CZ.mo DELETED
Binary file
languages/duplicate-post-da_DK.mo DELETED
Binary file
languages/duplicate-post-de_DE.mo DELETED
Binary file
languages/duplicate-post-es.mo DELETED
Binary file
languages/duplicate-post-fi.mo DELETED
Binary file
languages/duplicate-post-fr_FR.mo DELETED
Binary file
languages/duplicate-post-he_IL.mo DELETED
Binary file
languages/duplicate-post-hr.mo DELETED
Binary file
languages/duplicate-post-it_IT.mo DELETED
Binary file
languages/duplicate-post-ja.mo DELETED
Binary file
languages/duplicate-post-nl_NL.mo DELETED
Binary file
languages/duplicate-post-pl_PL.mo DELETED
Binary file
languages/duplicate-post-pt_BR.mo DELETED
Binary file
languages/duplicate-post-ro_RO.mo DELETED
Binary file
languages/duplicate-post-sv_SE.mo DELETED
Binary file
languages/duplicate-post-tr.mo DELETED
Binary file
languages/duplicate-post-zh_CN.mo DELETED
Binary file
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: lopo
3
  Donate link: http://lopo.it/duplicate-post-plugin/
4
  Tags: duplicate post, copy, clone
5
- Requires at least: 3.0
6
- Tested up to: 4.5
7
- Stable tag: 2.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -28,22 +28,13 @@ How it works:
28
 
29
  2, 3 and 4 will lead to the edit page for the new draft: change what you want, click on 'Publish' and you're done.
30
 
31
- **Pay attention to the new behaviour!** The first way now allows you to clone a post with a single click, speeding up your work if you have many posts to duplicate.
32
-
33
  There is also a **template tag**, so you can put it in your templates and clone your posts/pages from the front-end. Clicking on the link will lead you to the edit page for the new draft, just like the admin bar link.
34
 
35
- In the Options page under Settings it is now possible to choose what to copy:
36
-
37
- * the original post/page date
38
- * the original post/page status (draft, published, pending), when cloning from the posts list
39
- * the original post/page excerpt
40
- * the original post/page attachments (actual files won't be copied)
41
- * all the children of the original page
42
- * which taxonomies and custom fields
43
 
44
- You can also set a prefix (or a suffix) to place before (or after) the title of the cloned post/page, and the roles allowed to clone posts or pages.
45
 
46
- If you want to contribute to translate the plugin in languages other than English, there is a [GlotPress translation project](http://lopo.it/glotpress/projects/duplicate-post) available (no registration required! — You can also send me an e-mail using [the form on my website](http://lopo.it/contatti/)).
47
 
48
  **If you're a plugin developer**, I suggest to read the section made just for you under "Other Notes", to ensure compatibility between your plugin(s) and mine.
49
 
@@ -72,8 +63,17 @@ Then try to deactivate and re-activate it, some user have reported that this fix
72
 
73
  Pay also attention to the new "Roles allowed to copy" option: it should convert the former "user level" option to the new standard, but unknown problems may arise. Make sure that your role is enabled.
74
 
 
 
75
  If not, maybe there is some kind of conflict with other plugins: feel free [to write me](http://lopo.it/contatti/) and we'll try to discover a solution (it will be *really* helpful if you try to deactivate all your other plugins one by one to see which one conflicts with mine... But do it only if you know what you're doing, I will not be responsible of any problem you may experience).
76
 
 
 
 
 
 
 
 
77
  = Can you add it to the bulk actions in the post/page list? =
78
 
79
  I can't. There is no way to do it without hacking the core code of WordPress.
@@ -90,6 +90,9 @@ There is an open ticket in WordPress Trac, as other plugin developers too are in
90
 
91
  == Upgrade Notice ==
92
 
 
 
 
93
  = 2.6 =
94
  PHP 5.4 (Strict Standards) compatible + Fixed possible XSS and SQL injections + other bugs
95
 
@@ -128,6 +131,16 @@ New features and customization, WP 3.0 compatibility: you should upgrade if you
128
 
129
  == Changelog ==
130
 
 
 
 
 
 
 
 
 
 
 
131
  = 2.6 =
132
  * PHP 5.4 (Strict Standards) compatible
133
  * Fixed possible XSS and SQL injections
@@ -247,9 +260,9 @@ Another available template tag is `duplicate_post_get_original($id, $output)` wh
247
  `duplicate_post_get_original()` relies on the `_dp_original` custom field.
248
 
249
 
250
- == For plugin developers ==
251
 
252
- From version 1.0 onwards, thanks to [Simon Wheatley](http://www.simonwheatley.co.uk/)'s suggestion, Duplicate Post adds two actions (*dp_duplicate_post* and *dp_duplicate_page*) which can be used by other developers if their plugins store extra data for posts in non-standard WP tables.
253
  Since Duplicate Post knows only of standard WP tables, it can't copy other data relevant to the post which is being copied if this information is stored elsewhere. So, if you're a plugin developer which acts this way, and you want to ensure compatibility with Duplicate Post, you can hook your functions to those actions to make sure that they will be called when a post (or page) is cloned.
254
 
255
  It's very simple. Just write your function that copies post metadata to a new row of your table:
@@ -269,6 +282,6 @@ Please refer to the [Plugin API](http://codex.wordpress.org/Plugin_API) for ever
269
  If you find this useful and you if you want to contribute, there are three ways:
270
 
271
  1. You can [write me](http://lopo.it/contatti/) and submit your bug reports, suggestions and requests for features;
272
- 2. If you want to translate it to your language (there are just a few lines of text), you can use the [GlotPress translation project](http://lopo.it/glotpress/projects/duplicate-post), or [contact me](http://lopo.it/contatti/) and I’ll send you the .pot catalogue; your translation could be featured in next releases;
273
- 3. Using the plugin is free, but if you want you can send me some money with PayPal [here](http://lopo.it/duplicate-post-plugin/)
274
 
2
  Contributors: lopo
3
  Donate link: http://lopo.it/duplicate-post-plugin/
4
  Tags: duplicate post, copy, clone
5
+ Requires at least: 3.4
6
+ Tested up to: 4.6
7
+ Stable tag: 3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
28
 
29
  2, 3 and 4 will lead to the edit page for the new draft: change what you want, click on 'Publish' and you're done.
30
 
 
 
31
  There is also a **template tag**, so you can put it in your templates and clone your posts/pages from the front-end. Clicking on the link will lead you to the edit page for the new draft, just like the admin bar link.
32
 
33
+ In the Options page under Settings it is now possible to choose what to copy, and you can also set a prefix (or a suffix) to place before (or after) the title of the cloned post/page.
 
 
 
 
 
 
 
34
 
35
+ You can also restrict the plugin to certain post types, and allow only some roles to clone posts or pages.
36
 
37
+ If you want to contribute to translate the plugin in languages other than English, there is a [translation project](https://translate.wordpress.org/projects/wp-plugins/duplicate-post) available: [contact me](http://lopo.it/contatti/) if you wish to become an editor for your language.
38
 
39
  **If you're a plugin developer**, I suggest to read the section made just for you under "Other Notes", to ensure compatibility between your plugin(s) and mine.
40
 
63
 
64
  Pay also attention to the new "Roles allowed to copy" option: it should convert the former "user level" option to the new standard, but unknown problems may arise. Make sure that your role is enabled.
65
 
66
+ From version 3.0 onwards, post types must be enabled in the Options: check them as well.
67
+
68
  If not, maybe there is some kind of conflict with other plugins: feel free [to write me](http://lopo.it/contatti/) and we'll try to discover a solution (it will be *really* helpful if you try to deactivate all your other plugins one by one to see which one conflicts with mine... But do it only if you know what you're doing, I will not be responsible of any problem you may experience).
69
 
70
+ = The plugin is not translated in my language! =
71
+
72
+ From version 3.0 the plugin's translations are managed by the WordPress.org platform and the plugin si shipped without language files, so first of all update translations under Dashboard->Updates.
73
+
74
+ If Duplicate Post is still in English, or if there are some untraslated strings, you can help traslating to your language [here](https://translate.wordpress.org/projects/wp-plugins/duplicate-post): you only need a WordPress.org account.
75
+ [Contact me](http://lopo.it/contatti/) if you wish to become an editor for your language.
76
+
77
  = Can you add it to the bulk actions in the post/page list? =
78
 
79
  I can't. There is no way to do it without hacking the core code of WordPress.
90
 
91
  == Upgrade Notice ==
92
 
93
+ = 3.0 =
94
+ Major redesign of the settings page + fine-tune options (what to copy, custom post types, etc.) + bugfixes and XSS prevention
95
+
96
  = 2.6 =
97
  PHP 5.4 (Strict Standards) compatible + Fixed possible XSS and SQL injections + other bugs
98
 
131
 
132
  == Changelog ==
133
 
134
+ = 3.0 =
135
+ * Settings page redesigned
136
+ * More options to enable/disable copy of every part of a post
137
+ * Enable/disable cloning for every custom post type
138
+ * Jetpack Publicize compatibility
139
+ * Fixed a possible XSS
140
+ * Fixed other little bugs
141
+ * Translations removed to use WP.org's official translation project
142
+ * Checked PHP 7 compatibility
143
+
144
  = 2.6 =
145
  * PHP 5.4 (Strict Standards) compatible
146
  * Fixed possible XSS and SQL injections
260
  `duplicate_post_get_original()` relies on the `_dp_original` custom field.
261
 
262
 
263
+ == Action hooks ==
264
 
265
+ From version 1.0 onwards, thanks to [Simon Wheatley](http://www.simonwheatley.co.uk/)'s suggestion, Duplicate Post adds two action hooks (*dp_duplicate_post* and *dp_duplicate_page*) which can be used by other developers if their plugins store extra data for posts in non-standard WP tables.
266
  Since Duplicate Post knows only of standard WP tables, it can't copy other data relevant to the post which is being copied if this information is stored elsewhere. So, if you're a plugin developer which acts this way, and you want to ensure compatibility with Duplicate Post, you can hook your functions to those actions to make sure that they will be called when a post (or page) is cloned.
267
 
268
  It's very simple. Just write your function that copies post metadata to a new row of your table:
282
  If you find this useful and you if you want to contribute, there are three ways:
283
 
284
  1. You can [write me](http://lopo.it/contatti/) and submit your bug reports, suggestions and requests for features;
285
+ 2. If you want to translate it to your language (there are just a few lines of text), you can use the [translation project](https://translate.wordpress.org/projects/wp-plugins/duplicate-post);
286
+ 3. Using the plugin is free, but if you want you can support my efforts by donating with PayPal [here](http://lopo.it/duplicate-post-plugin/)
287