Duplicate Post - Version 3.2.1

Version Description

Fixes some problems with Multisite, WPML, revisions

Download this release

Release Info

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

Code changes from version 3.2 to 3.2.1

compat/duplicate-post-wpml.php CHANGED
@@ -5,15 +5,20 @@ function duplicate_post_wpml_init() {
5
  if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
6
  add_action('dp_duplicate_page', 'duplicate_post_wpml_copy_translations', 10, 3);
7
  add_action('dp_duplicate_post', 'duplicate_post_wpml_copy_translations', 10, 3);
 
8
  }
9
  }
10
 
 
 
 
11
  function duplicate_post_wpml_copy_translations($post_id, $post, $status = '') {
12
  global $sitepress;
13
-
 
14
  remove_action('dp_duplicate_page', 'duplicate_post_wpml_copy_translations', 10);
15
  remove_action('dp_duplicate_post', 'duplicate_post_wpml_copy_translations', 10);
16
-
17
  $current_language = $sitepress->get_current_language();
18
  $trid = $sitepress->get_element_trid($post->ID);
19
  if (!empty($trid)) {
@@ -21,11 +26,56 @@ function duplicate_post_wpml_copy_translations($post_id, $post, $status = '') {
21
  $new_trid = $sitepress->get_element_trid($post_id);
22
  foreach ($translations as $code => $details) {
23
  if ($code != $current_language) {
24
- $translation = get_post($details->element_id);
25
- $new_post_id = duplicate_post_create_duplicate($translation, $status);
26
- $sitepress->set_element_language_details($new_post_id, 'post_' . $translation->post_type, $new_trid, $code, $current_language);
 
 
 
27
  }
28
  }
 
29
  }
30
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  ?>
5
  if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
6
  add_action('dp_duplicate_page', 'duplicate_post_wpml_copy_translations', 10, 3);
7
  add_action('dp_duplicate_post', 'duplicate_post_wpml_copy_translations', 10, 3);
8
+ add_action('shutdown', 'duplicate_wpml_string_packages', 11 );
9
  }
10
  }
11
 
12
+ global $duplicated_posts;
13
+ $duplicated_posts = array();
14
+
15
  function duplicate_post_wpml_copy_translations($post_id, $post, $status = '') {
16
  global $sitepress;
17
+ global $duplicated_posts;
18
+
19
  remove_action('dp_duplicate_page', 'duplicate_post_wpml_copy_translations', 10);
20
  remove_action('dp_duplicate_post', 'duplicate_post_wpml_copy_translations', 10);
21
+
22
  $current_language = $sitepress->get_current_language();
23
  $trid = $sitepress->get_element_trid($post->ID);
24
  if (!empty($trid)) {
26
  $new_trid = $sitepress->get_element_trid($post_id);
27
  foreach ($translations as $code => $details) {
28
  if ($code != $current_language) {
29
+ if ( $details->element_id ) {
30
+ $translation = get_post( $details->element_id );
31
+ if (!$translation) continue;
32
+ $new_post_id = duplicate_post_create_duplicate( $translation, $status );
33
+ $sitepress->set_element_language_details( $new_post_id, 'post_' . $translation->post_type, $new_trid, $code, $current_language );
34
+ }
35
  }
36
  }
37
+ $duplicated_posts[ $post->ID ] = $post_id;
38
  }
39
  }
40
+
41
+ function duplicate_wpml_string_packages() {
42
+ global $duplicated_posts;
43
+
44
+ foreach ( $duplicated_posts as $original_post_id => $duplicate_post_id ) {
45
+
46
+ $original_string_packages = apply_filters( 'wpml_st_get_post_string_packages', false, $original_post_id );
47
+ $new_string_packages = apply_filters( 'wpml_st_get_post_string_packages', false, $duplicate_post_id );
48
+ if ( is_array( $original_string_packages ) ) {
49
+ foreach ( $original_string_packages as $original_string_package ) {
50
+ $translated_original_strings = $original_string_package->get_translated_strings( array() );
51
+
52
+ foreach ( $new_string_packages as $new_string_package ) {
53
+ $cache = new WPML_WP_Cache( 'WPML_Package' );
54
+ $cache->flush_group_cache();
55
+ $new_strings = $new_string_package->get_package_strings();
56
+ foreach ( $new_strings as $new_string ) {
57
+
58
+ if ( isset( $translated_original_strings[ $new_string->name ] ) ) {
59
+ foreach ( $translated_original_strings[ $new_string->name ] as $language => $translated_string ) {
60
+
61
+ do_action(
62
+ 'wpml_add_string_translation',
63
+ $new_string->id,
64
+ $language,
65
+ $translated_string['value'],
66
+ $translated_string['status']
67
+ );
68
+
69
+ }
70
+ }
71
+
72
+ }
73
+
74
+ }
75
+
76
+ }
77
+ }
78
+ }
79
+ }
80
+
81
  ?>
duplicate-post-admin.php CHANGED
@@ -12,7 +12,7 @@ require_once (dirname(__FILE__).'/compat/duplicate-post-jetpack.php');
12
  * Wrapper for the option 'duplicate_post_version'
13
  */
14
  function duplicate_post_get_installed_version() {
15
- return get_site_option( 'duplicate_post_version' );
16
  }
17
 
18
  /**
@@ -89,7 +89,7 @@ function duplicate_post_admin_init(){
89
  function duplicate_post_plugin_upgrade() {
90
  $installed_version = duplicate_post_get_installed_version();
91
 
92
- if ( $installed_version==duplicate_post_get_current_version() )
93
  return;
94
 
95
 
@@ -177,8 +177,8 @@ function duplicate_post_plugin_upgrade() {
177
  delete_option('duplicate_post_view_user_level');
178
  delete_option('dp_notice');
179
 
180
- delete_option('duplicate_post_version');
181
- update_site_option( 'duplicate_post_version', duplicate_post_get_current_version() );
182
 
183
  delete_option('duplicate_post_show_notice', 0);
184
  update_site_option('duplicate_post_show_notice', 1);
@@ -191,8 +191,8 @@ function duplicate_post_plugin_upgrade() {
191
  function duplicate_post_show_update_notice() {
192
  if(!current_user_can( 'manage_options')) return;
193
  $class = 'notice is-dismissible';
194
- $message = '<strong><a href="https://duplicate-post.lopo.it/">'.esc_html__('Check out the new documentation for Duplicate Post!', 'duplicate-post').'</a></strong><br/>';
195
- $message .= '<em>'.esc_html__('Duplicate Post is now also compatible with WPML!', 'duplicate-post').'</em><br/>';
196
  $message .= '<strong>'.sprintf(wp_kses(__('Help me develop the plugin and provide support by <a href="%s">donating even a small sum</a>.', 'duplicate-post'), array( 'a' => array( 'href' => array() ) ) ), "https://duplicate-post.lopo.it/donate").'</strong>';
197
  global $wp_version;
198
  if( version_compare($wp_version, '4.2') < 0 ){
@@ -276,6 +276,10 @@ function duplicate_post_add_removable_query_arg( $removable_query_args ){
276
  * then redirects to the post list
277
  */
278
  function duplicate_post_save_as_new_post($status = ''){
 
 
 
 
279
  if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'duplicate_post_save_as_new_post' == $_REQUEST['action'] ) ) ) {
280
  wp_die(esc_html__('No post to duplicate has been supplied!', 'duplicate-post'));
281
  }
@@ -592,6 +596,11 @@ function duplicate_post_create_duplicate($post, $status = '', $parent_id = '') {
592
  if(!empty($increase_menu_order_by) && is_numeric($increase_menu_order_by)){
593
  $menu_order += intval($increase_menu_order_by);
594
  }
 
 
 
 
 
595
 
596
  $new_post = array(
597
  'menu_order' => $menu_order,
@@ -607,6 +616,7 @@ function duplicate_post_create_duplicate($post, $status = '', $parent_id = '') {
607
  'post_status' => $new_post_status,
608
  'post_title' => $title,
609
  'post_type' => $post->post_type,
 
610
  );
611
 
612
  if(get_option('duplicate_post_copydate') == 1){
@@ -616,33 +626,22 @@ function duplicate_post_create_duplicate($post, $status = '', $parent_id = '') {
616
 
617
  $new_post_id = wp_insert_post(wp_slash($new_post));
618
 
619
- // If the copy is published or scheduled, we have to set a proper slug.
620
- if ($new_post_status == 'publish' || $new_post_status == 'future'){
621
- $post_name = $post->post_name;
622
- if(get_option('duplicate_post_copyslug') != 1){
623
- $post_name = '';
624
- }
625
- $post_name = wp_unique_post_slug($post_name, $new_post_id, $new_post_status, $post->post_type, $new_post_parent);
626
-
627
- $new_post = array();
628
- $new_post['ID'] = $new_post_id;
629
- $new_post['post_name'] = $post_name;
630
-
631
- // Update the post into the database
632
- wp_update_post( wp_slash($new_post) );
633
- }
634
-
635
  // If you have written a plugin which uses non-WP database tables to save
636
  // information about a post you can hook this action to dupe that data.
637
- if ($post->post_type == 'page' || is_post_type_hierarchical( $post->post_type ))
638
- do_action( 'dp_duplicate_page', $new_post_id, $post, $status );
639
- else
640
- do_action( 'dp_duplicate_post', $new_post_id, $post, $status );
641
-
642
- delete_post_meta($new_post_id, '_dp_original');
643
- add_post_meta($new_post_id, '_dp_original', $post->ID);
644
-
645
- do_action('duplicate_post_post_copy');
 
 
 
 
 
646
 
647
  return $new_post_id;
648
  }
12
  * Wrapper for the option 'duplicate_post_version'
13
  */
14
  function duplicate_post_get_installed_version() {
15
+ return get_option( 'duplicate_post_version' );
16
  }
17
 
18
  /**
89
  function duplicate_post_plugin_upgrade() {
90
  $installed_version = duplicate_post_get_installed_version();
91
 
92
+ if ( $installed_version == duplicate_post_get_current_version() )
93
  return;
94
 
95
 
177
  delete_option('duplicate_post_view_user_level');
178
  delete_option('dp_notice');
179
 
180
+ delete_site_option('duplicate_post_version');
181
+ update_option( 'duplicate_post_version', duplicate_post_get_current_version() );
182
 
183
  delete_option('duplicate_post_show_notice', 0);
184
  update_site_option('duplicate_post_show_notice', 1);
191
  function duplicate_post_show_update_notice() {
192
  if(!current_user_can( 'manage_options')) return;
193
  $class = 'notice is-dismissible';
194
+ $message = '<strong>'.esc_html__('Duplicate Post turns 10!', 'duplicate-post').'</strong> '.esc_html__('Serving the WordPress community since November 2007.', 'duplicate-post').'<br/>';
195
+ $message .= '<em><a href="https://duplicate-post.lopo.it/">'.esc_html__('Check out the new documentation', 'duplicate-post').'</a> - '.sprintf(__('Please <a href="%s">review the settings</a> to make sure it works as you expect.', 'duplicate-post'), admin_url('options-general.php?page=duplicatepost')).'</em><br/>';
196
  $message .= '<strong>'.sprintf(wp_kses(__('Help me develop the plugin and provide support by <a href="%s">donating even a small sum</a>.', 'duplicate-post'), array( 'a' => array( 'href' => array() ) ) ), "https://duplicate-post.lopo.it/donate").'</strong>';
197
  global $wp_version;
198
  if( version_compare($wp_version, '4.2') < 0 ){
276
  * then redirects to the post list
277
  */
278
  function duplicate_post_save_as_new_post($status = ''){
279
+ if(!duplicate_post_is_current_user_allowed_to_copy()){
280
+ wp_die(esc_html__('Current user is not allowed to copy posts.', 'duplicate-post'));
281
+ }
282
+
283
  if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'duplicate_post_save_as_new_post' == $_REQUEST['action'] ) ) ) {
284
  wp_die(esc_html__('No post to duplicate has been supplied!', 'duplicate-post'));
285
  }
596
  if(!empty($increase_menu_order_by) && is_numeric($increase_menu_order_by)){
597
  $menu_order += intval($increase_menu_order_by);
598
  }
599
+
600
+ $post_name = $post->post_name;
601
+ if(get_option('duplicate_post_copyslug') != 1){
602
+ $post_name = '';
603
+ }
604
 
605
  $new_post = array(
606
  'menu_order' => $menu_order,
616
  'post_status' => $new_post_status,
617
  'post_title' => $title,
618
  'post_type' => $post->post_type,
619
+ 'post_name' => $post_name
620
  );
621
 
622
  if(get_option('duplicate_post_copydate') == 1){
626
 
627
  $new_post_id = wp_insert_post(wp_slash($new_post));
628
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
629
  // If you have written a plugin which uses non-WP database tables to save
630
  // information about a post you can hook this action to dupe that data.
631
+
632
+ if($new_post_id !== 0 && !is_wp_error($new_post_id)){
633
+
634
+ if ($post->post_type == 'page' || is_post_type_hierarchical( $post->post_type ))
635
+ do_action( 'dp_duplicate_page', $new_post_id, $post, $status );
636
+ else
637
+ do_action( 'dp_duplicate_post', $new_post_id, $post, $status );
638
+
639
+ delete_post_meta($new_post_id, '_dp_original');
640
+ add_post_meta($new_post_id, '_dp_original', $post->ID);
641
+
642
+ do_action('duplicate_post_post_copy');
643
+
644
+ }
645
 
646
  return $new_post_id;
647
  }
duplicate-post-options.php CHANGED
@@ -370,7 +370,7 @@ img#donate-button{
370
  </tr>
371
  <tr valign="top">
372
  <td colspan="2"><span class="description"><?php esc_html_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'); ?>
373
- <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/'); ?>
374
  </span>
375
  </td>
376
  </tr>
370
  </tr>
371
  <tr valign="top">
372
  <td colspan="2"><span class="description"><?php esc_html_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'); ?>
373
+ <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://duplicate-post.lopo.it/docs/developers-guide/functions-template-tags/duplicate_post_clone_post_link/'); ?>
374
  </span>
375
  </td>
376
  </tr>
duplicate-post.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Duplicate Post
4
  Plugin URI: https://duplicate-post.lopo.it/
5
  Description: Clone posts and pages.
6
- Version: 3.2
7
  Author: Enrico Battocchi
8
  Author URI: https://lopo.it
9
  Text Domain: duplicate-post
@@ -31,7 +31,7 @@ if ( ! defined( 'ABSPATH' ) ) {
31
  }
32
 
33
  // Version of the plugin
34
- define('DUPLICATE_POST_CURRENT_VERSION', '3.2' );
35
 
36
 
37
  /**
3
  Plugin Name: Duplicate Post
4
  Plugin URI: https://duplicate-post.lopo.it/
5
  Description: Clone posts and pages.
6
+ Version: 3.2.1
7
  Author: Enrico Battocchi
8
  Author URI: https://lopo.it
9
  Text Domain: duplicate-post
31
  }
32
 
33
  // Version of the plugin
34
+ define('DUPLICATE_POST_CURRENT_VERSION', '3.2.1' );
35
 
36
 
37
  /**
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://duplicate-post.lopo.it/
4
  Tags: duplicate post, copy, clone
5
  Requires at least: 3.6
6
  Tested up to: 4.9
7
- Stable tag: 3.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -19,13 +19,13 @@ How it works:
19
 
20
  1. In 'Edit Posts'/'Edit Pages', you can click on 'Clone' link below the post/page title: this will immediately create a copy and return to the list.
21
 
22
- 2. NEW! In 'Edit Posts'/'Edit Pages', you can select one or more items, then choose 'Clone' in the 'Bulk Actions' dropdown to copy them all at once.
23
 
24
  3. In 'Edit Posts'/'Edit Pages', you can click on 'New Draft' link below the post/page title.
25
 
26
  4. On the post edit screen, you can click on 'Copy to a new draft' above "Cancel"/"Move to trash".
27
 
28
- 5. While viewing a post as a logged in user, you can click on 'Copy to a new draft' as a dropdown link under "Edit Post" in the admin bar.
29
 
30
  3, 4 and 5 will lead to the edit page for the new draft: change what you want, click on 'Publish' and you're done.
31
 
@@ -76,6 +76,9 @@ If Duplicate Post is still in English, or if there are some untraslated strings,
76
 
77
  == Upgrade Notice ==
78
 
 
 
 
79
  = 3.2 =
80
  new website + WPML compatibility + various fixes
81
 
@@ -138,6 +141,12 @@ New features and customization, WP 3.0 compatibility: you should upgrade if you
138
 
139
  == Changelog ==
140
 
 
 
 
 
 
 
141
  = 3.2 (2017-04-04) =
142
  * new website with extensive documentation
143
  * WPML compatibility, thanks to WPML team
@@ -291,4 +300,3 @@ If you find this useful and if you want to contribute, there are three ways:
291
  1. You can [write me](https://duplicate-post.lopo.it/contact) and submit your bug reports, suggestions and requests for features;
292
  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);
293
  3. Using the plugin is free, but if you want you can support my efforts by donating with PayPal [here](https://duplicate-post.lopo.it/donate)
294
-
4
  Tags: duplicate post, copy, clone
5
  Requires at least: 3.6
6
  Tested up to: 4.9
7
+ Stable tag: 3.2.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
19
 
20
  1. In 'Edit Posts'/'Edit Pages', you can click on 'Clone' link below the post/page title: this will immediately create a copy and return to the list.
21
 
22
+ 2. In 'Edit Posts'/'Edit Pages', you can select one or more items, then choose 'Clone' in the 'Bulk Actions' dropdown to copy them all at once.
23
 
24
  3. In 'Edit Posts'/'Edit Pages', you can click on 'New Draft' link below the post/page title.
25
 
26
  4. On the post edit screen, you can click on 'Copy to a new draft' above "Cancel"/"Move to trash".
27
 
28
+ 5. While viewing a post as a logged in user, you can click on 'Copy to a new draft' in the admin bar.
29
 
30
  3, 4 and 5 will lead to the edit page for the new draft: change what you want, click on 'Publish' and you're done.
31
 
76
 
77
  == Upgrade Notice ==
78
 
79
+ = 3.2.1 =
80
+ Fixes some problems with Multisite, WPML, revisions
81
+
82
  = 3.2 =
83
  new website + WPML compatibility + various fixes
84
 
141
 
142
  == Changelog ==
143
 
144
+ = 3.2.1 (2017-11-25) =
145
+ * Fixing some issues of the 3.* trunk before major redesign
146
+ * Fixes issue when upgrading on multisite
147
+ * Improved compatibility with WPML + page builders, thanks to WPML team
148
+ * Prevents creating a revision immediately after the cloning
149
+
150
  = 3.2 (2017-04-04) =
151
  * new website with extensive documentation
152
  * WPML compatibility, thanks to WPML team
300
  1. You can [write me](https://duplicate-post.lopo.it/contact) and submit your bug reports, suggestions and requests for features;
301
  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);
302
  3. Using the plugin is free, but if you want you can support my efforts by donating with PayPal [here](https://duplicate-post.lopo.it/donate)