Duplicate Post - Version 4.0.2

Version Description

(2021-01-14) =

Bugfixes:

  • Fixes a bug where errors or notices could be triggered when using the plugin with some other plugins or custom code.
Download this release

Release Info

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

Code changes from version 4.0.1 to 4.0.2

duplicate-post.php CHANGED
@@ -2,8 +2,8 @@
2
  /**
3
  * Plugin Name: Yoast Duplicate Post
4
  * Plugin URI: https://yoast.com/wordpress/plugins/duplicate-post/
5
- * Description: Clone posts and pages.
6
- * Version: 4.0.1
7
  * Author: Enrico Battocchi & Team Yoast
8
  * Author URI: https://yoast.com
9
  * Text Domain: duplicate-post
@@ -42,7 +42,7 @@ if ( ! defined( 'DUPLICATE_POST_PATH' ) ) {
42
  define( 'DUPLICATE_POST_PATH', plugin_dir_path( __FILE__ ) );
43
  }
44
 
45
- define( 'DUPLICATE_POST_CURRENT_VERSION', '4.0.1' );
46
 
47
  $duplicate_post_autoload_file = __DIR__ . '/vendor/autoload.php';
48
 
2
  /**
3
  * Plugin Name: Yoast Duplicate Post
4
  * Plugin URI: https://yoast.com/wordpress/plugins/duplicate-post/
5
+ * Description: The go-to tool for cloning post and pages, including easy Rewrite & Republish feature.
6
+ * Version: 4.0.2
7
  * Author: Enrico Battocchi & Team Yoast
8
  * Author URI: https://yoast.com
9
  * Text Domain: duplicate-post
42
  define( 'DUPLICATE_POST_PATH', plugin_dir_path( __FILE__ ) );
43
  }
44
 
45
+ define( 'DUPLICATE_POST_CURRENT_VERSION', '4.0.2' );
46
 
47
  $duplicate_post_autoload_file = __DIR__ . '/vendor/autoload.php';
48
 
js/dist/{duplicate-post-edit-401.js → duplicate-post-edit-402.js} RENAMED
File without changes
js/dist/{duplicate-post-options-401.js → duplicate-post-options-402.js} RENAMED
File without changes
js/dist/{duplicate-post-quick-edit-401.js → duplicate-post-quick-edit-402.js} RENAMED
File without changes
js/dist/{duplicate-post-strings-401.js → duplicate-post-strings-402.js} RENAMED
File without changes
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://yoast.com/wordpress/plugins/duplicate-post/
4
  Tags: duplicate post, copy, clone
5
  Requires at least: 5.5
6
  Tested up to: 5.6
7
- Stable tag: 4.0.1
8
  Requires PHP: 5.6.20
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -151,6 +151,12 @@ New features and customization, WP 3.0 compatibility: you should upgrade if you
151
 
152
  == Changelog ==
153
 
 
 
 
 
 
 
154
  = 4.0.1 (2021-01-12) =
155
 
156
  Bugfixes:
4
  Tags: duplicate post, copy, clone
5
  Requires at least: 5.5
6
  Tested up to: 5.6
7
+ Stable tag: 4.0.2
8
  Requires PHP: 5.6.20
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
151
 
152
  == Changelog ==
153
 
154
+ = 4.0.2 (2021-01-14) =
155
+
156
+ Bugfixes:
157
+
158
+ * Fixes a bug where errors or notices could be triggered when using the plugin with some other plugins or custom code.
159
+
160
  = 4.0.1 (2021-01-12) =
161
 
162
  Bugfixes:
src/ui/class-admin-bar.php CHANGED
@@ -7,6 +7,7 @@
7
 
8
  namespace Yoast\WP\Duplicate_Post\UI;
9
 
 
10
  use Yoast\WP\Duplicate_Post\Permissions_Helper;
11
  use Yoast\WP\Duplicate_Post\Utils;
12
 
@@ -159,7 +160,7 @@ class Admin_Bar {
159
  *
160
  * @global \WP_Query $wp_the_query
161
  *
162
- * @return false|\WP_Post The Post object, false if we are not on a post.
163
  */
164
  public function get_current_post() {
165
  global $wp_the_query;
@@ -170,7 +171,7 @@ class Admin_Bar {
170
  $post = $wp_the_query->get_queried_object();
171
  }
172
 
173
- if ( empty( $post ) || ! \is_a( $post, '\WP_Post' ) ) {
174
  return false;
175
  }
176
 
7
 
8
  namespace Yoast\WP\Duplicate_Post\UI;
9
 
10
+ use WP_Post;
11
  use Yoast\WP\Duplicate_Post\Permissions_Helper;
12
  use Yoast\WP\Duplicate_Post\Utils;
13
 
160
  *
161
  * @global \WP_Query $wp_the_query
162
  *
163
+ * @return false|WP_Post The Post object, false if we are not on a post.
164
  */
165
  public function get_current_post() {
166
  global $wp_the_query;
171
  $post = $wp_the_query->get_queried_object();
172
  }
173
 
174
+ if ( empty( $post ) || ! $post instanceof WP_Post ) {
175
  return false;
176
  }
177
 
src/ui/class-block-editor.php CHANGED
@@ -7,6 +7,7 @@
7
 
8
  namespace Yoast\WP\Duplicate_Post\UI;
9
 
 
10
  use Yoast\WP\Duplicate_Post\Permissions_Helper;
11
  use Yoast\WP\Duplicate_Post\Utils;
12
 
@@ -70,7 +71,7 @@ class Block_Editor {
70
  $post = \get_post();
71
 
72
  if (
73
- ! \is_null( $post )
74
  && (
75
  $this->permissions_helper->is_rewrite_and_republish_copy( $post )
76
  || $this->permissions_helper->has_rewrite_and_republish_copy( $post )
@@ -89,7 +90,7 @@ class Block_Editor {
89
  public function enqueue_block_editor_scripts() {
90
  $post = \get_post();
91
 
92
- if ( ! $post ) {
93
  return;
94
  }
95
 
@@ -121,7 +122,7 @@ class Block_Editor {
121
  public function get_new_draft_permalink() {
122
  $post = \get_post();
123
 
124
- if ( ! $this->permissions_helper->should_links_be_displayed( $post ) ) {
125
  return '';
126
  }
127
 
@@ -137,7 +138,8 @@ class Block_Editor {
137
  $post = \get_post();
138
 
139
  if (
140
- $this->permissions_helper->is_rewrite_and_republish_copy( $post )
 
141
  || $this->permissions_helper->has_rewrite_and_republish_copy( $post )
142
  || ! $this->permissions_helper->should_links_be_displayed( $post )
143
  || $this->permissions_helper->is_elementor_active()
@@ -156,7 +158,7 @@ class Block_Editor {
156
  public function get_check_permalink() {
157
  $post = \get_post();
158
 
159
- if ( ! $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
160
  return '';
161
  }
162
 
@@ -171,7 +173,7 @@ class Block_Editor {
171
  public function get_original_post_edit_url() {
172
  $post = \get_post();
173
 
174
- if ( \is_null( $post ) ) {
175
  return '';
176
  }
177
 
7
 
8
  namespace Yoast\WP\Duplicate_Post\UI;
9
 
10
+ use WP_Post;
11
  use Yoast\WP\Duplicate_Post\Permissions_Helper;
12
  use Yoast\WP\Duplicate_Post\Utils;
13
 
71
  $post = \get_post();
72
 
73
  if (
74
+ $post instanceof WP_Post
75
  && (
76
  $this->permissions_helper->is_rewrite_and_republish_copy( $post )
77
  || $this->permissions_helper->has_rewrite_and_republish_copy( $post )
90
  public function enqueue_block_editor_scripts() {
91
  $post = \get_post();
92
 
93
+ if ( ! $post instanceof WP_Post ) {
94
  return;
95
  }
96
 
122
  public function get_new_draft_permalink() {
123
  $post = \get_post();
124
 
125
+ if ( ! $post instanceof WP_Post || ! $this->permissions_helper->should_links_be_displayed( $post ) ) {
126
  return '';
127
  }
128
 
138
  $post = \get_post();
139
 
140
  if (
141
+ ! $post instanceof WP_Post
142
+ || $this->permissions_helper->is_rewrite_and_republish_copy( $post )
143
  || $this->permissions_helper->has_rewrite_and_republish_copy( $post )
144
  || ! $this->permissions_helper->should_links_be_displayed( $post )
145
  || $this->permissions_helper->is_elementor_active()
158
  public function get_check_permalink() {
159
  $post = \get_post();
160
 
161
+ if ( ! $post instanceof WP_Post || ! $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
162
  return '';
163
  }
164
 
173
  public function get_original_post_edit_url() {
174
  $post = \get_post();
175
 
176
+ if ( ! $post instanceof WP_Post ) {
177
  return '';
178
  }
179
 
src/ui/class-classic-editor.php CHANGED
@@ -128,10 +128,7 @@ class Classic_Editor {
128
  }
129
  }
130
 
131
- if (
132
- ! \is_null( $post )
133
- && $this->permissions_helper->should_links_be_displayed( $post )
134
- ) {
135
  ?>
136
  <div id="duplicate-action">
137
  <a class="submitduplicate duplication"
128
  }
129
  }
130
 
131
+ if ( $post instanceof WP_Post && $this->permissions_helper->should_links_be_displayed( $post ) ) {
 
 
 
132
  ?>
133
  <div id="duplicate-action">
134
  <a class="submitduplicate duplication"
src/ui/class-column.php CHANGED
@@ -68,7 +68,9 @@ class Column {
68
  * @return array The updated array.
69
  */
70
  public function add_original_column( $post_columns ) {
71
- $post_columns['duplicate_post_original_item'] = \__( 'Original item', 'duplicate-post' );
 
 
72
  return $post_columns;
73
  }
74
 
68
  * @return array The updated array.
69
  */
70
  public function add_original_column( $post_columns ) {
71
+ if ( \is_array( $post_columns ) ) {
72
+ $post_columns['duplicate_post_original_item'] = \__( 'Original item', 'duplicate-post' );
73
+ }
74
  return $post_columns;
75
  }
76
 
src/ui/class-link-builder.php CHANGED
@@ -73,7 +73,7 @@ class Link_Builder {
73
  */
74
  public function build_link( $post, $context, $action_name ) {
75
  $post = \get_post( $post );
76
- if ( ! $post ) {
77
  return '';
78
  }
79
 
73
  */
74
  public function build_link( $post, $context, $action_name ) {
75
  $post = \get_post( $post );
76
+ if ( ! $post instanceof \WP_Post ) {
77
  return '';
78
  }
79
 
src/ui/class-metabox.php CHANGED
@@ -72,7 +72,7 @@ class Metabox {
72
  */
73
  public function custom_metabox_html( $post ) {
74
  $original_item = Utils::get_original( $post );
75
- if ( $original_item ) {
76
  if ( ! $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
77
  ?>
78
  <p>
72
  */
73
  public function custom_metabox_html( $post ) {
74
  $original_item = Utils::get_original( $post );
75
+ if ( $post instanceof \WP_Post && $original_item instanceof \WP_Post ) {
76
  if ( ! $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
77
  ?>
78
  <p>
src/ui/class-post-list.php CHANGED
@@ -102,11 +102,17 @@ class Post_List {
102
  protected function get_copy_ids( $post_type ) {
103
  global $wpdb;
104
 
 
 
 
 
105
  if ( \array_key_exists( $post_type, $this->copy_ids ) ) {
106
  return $this->copy_ids[ $post_type ];
107
  }
108
 
109
- $this->copy_ids[ $post_type ] = $wpdb->get_results(
 
 
110
  $wpdb->prepare(
111
  'SELECT post_id, post_status FROM ' . $wpdb->postmeta . ' AS pm ' .
112
  'JOIN ' . $wpdb->posts . ' AS p ON pm.post_id = p.ID ' .
@@ -117,6 +123,10 @@ class Post_List {
117
  OBJECT_K
118
  );
119
 
 
 
 
 
120
  return $this->copy_ids[ $post_type ];
121
  }
122
 
102
  protected function get_copy_ids( $post_type ) {
103
  global $wpdb;
104
 
105
+ if ( empty( $post_type ) ) {
106
+ return [];
107
+ }
108
+
109
  if ( \array_key_exists( $post_type, $this->copy_ids ) ) {
110
  return $this->copy_ids[ $post_type ];
111
  }
112
 
113
+ $this->copy_ids[ $post_type ] = [];
114
+
115
+ $results = $wpdb->get_results(
116
  $wpdb->prepare(
117
  'SELECT post_id, post_status FROM ' . $wpdb->postmeta . ' AS pm ' .
118
  'JOIN ' . $wpdb->posts . ' AS p ON pm.post_id = p.ID ' .
123
  OBJECT_K
124
  );
125
 
126
+ if ( \is_array( $results ) ) {
127
+ $this->copy_ids[ $post_type ] = $results;
128
+ }
129
+
130
  return $this->copy_ids[ $post_type ];
131
  }
132
 
src/ui/class-post-states.php CHANGED
@@ -50,6 +50,11 @@ class Post_States {
50
  * @return array The updated post states array.
51
  */
52
  public function show_original_in_post_states( $post_states, $post ) {
 
 
 
 
 
53
  $original_item = Utils::get_original( $post );
54
 
55
  if ( ! $original_item ) {
50
  * @return array The updated post states array.
51
  */
52
  public function show_original_in_post_states( $post_states, $post ) {
53
+ if ( ! $post instanceof WP_Post
54
+ || ! \is_array( $post_states ) ) {
55
+ return $post_states;
56
+ }
57
+
58
  $original_item = Utils::get_original( $post );
59
 
60
  if ( ! $original_item ) {
src/ui/class-row-actions.php CHANGED
@@ -76,7 +76,9 @@ class Row_Actions {
76
  * @return array The updated array of actions.
77
  */
78
  public function add_clone_action_link( $actions, $post ) {
79
- if ( ! $post instanceof WP_Post || ! $this->permissions_helper->should_links_be_displayed( $post ) ) {
 
 
80
  return $actions;
81
  }
82
 
@@ -101,7 +103,9 @@ class Row_Actions {
101
  * @return array The updated array of actions.
102
  */
103
  public function add_new_draft_action_link( $actions, $post ) {
104
- if ( ! $post instanceof WP_Post || ! $this->permissions_helper->should_links_be_displayed( $post ) ) {
 
 
105
  return $actions;
106
  }
107
 
@@ -131,6 +135,7 @@ class Row_Actions {
131
  ! $post instanceof WP_Post
132
  || ! $this->permissions_helper->should_rewrite_and_republish_be_allowed( $post )
133
  || ! $this->permissions_helper->should_links_be_displayed( $post )
 
134
  ) {
135
  return $actions;
136
  }
76
  * @return array The updated array of actions.
77
  */
78
  public function add_clone_action_link( $actions, $post ) {
79
+ if ( ! $post instanceof WP_Post
80
+ || ! $this->permissions_helper->should_links_be_displayed( $post )
81
+ || ! \is_array( $actions ) ) {
82
  return $actions;
83
  }
84
 
103
  * @return array The updated array of actions.
104
  */
105
  public function add_new_draft_action_link( $actions, $post ) {
106
+ if ( ! $post instanceof WP_Post
107
+ || ! $this->permissions_helper->should_links_be_displayed( $post )
108
+ || ! \is_array( $actions ) ) {
109
  return $actions;
110
  }
111
 
135
  ! $post instanceof WP_Post
136
  || ! $this->permissions_helper->should_rewrite_and_republish_be_allowed( $post )
137
  || ! $this->permissions_helper->should_links_be_displayed( $post )
138
+ || ! \is_array( $actions )
139
  ) {
140
  return $actions;
141
  }
src/watchers/class-bulk-actions-watcher.php CHANGED
@@ -38,8 +38,10 @@ class Bulk_Actions_Watcher {
38
  * @return array The updated array of query args keys.
39
  */
40
  public function add_removable_query_args( $removable_query_args ) {
41
- $removable_query_args[] = 'bulk_cloned';
42
- $removable_query_args[] = 'bulk_rewriting';
 
 
43
  return $removable_query_args;
44
  }
45
 
38
  * @return array The updated array of query args keys.
39
  */
40
  public function add_removable_query_args( $removable_query_args ) {
41
+ if ( \is_array( $removable_query_args ) ) {
42
+ $removable_query_args[] = 'bulk_cloned';
43
+ $removable_query_args[] = 'bulk_rewriting';
44
+ }
45
  return $removable_query_args;
46
  }
47
 
src/watchers/class-copied-post-watcher.php CHANGED
@@ -88,7 +88,7 @@ class Copied_Post_Watcher {
88
 
89
  $post = \get_post();
90
 
91
- if ( \is_null( $post ) ) {
92
  return;
93
  }
94
 
@@ -107,7 +107,7 @@ class Copied_Post_Watcher {
107
  public function add_block_editor_notice() {
108
  $post = \get_post();
109
 
110
- if ( \is_null( $post ) ) {
111
  return;
112
  }
113
 
88
 
89
  $post = \get_post();
90
 
91
+ if ( ! $post instanceof \WP_Post ) {
92
  return;
93
  }
94
 
107
  public function add_block_editor_notice() {
108
  $post = \get_post();
109
 
110
+ if ( ! $post instanceof \WP_Post ) {
111
  return;
112
  }
113
 
src/watchers/class-link-actions-watcher.php CHANGED
@@ -52,8 +52,10 @@ class Link_Actions_Watcher {
52
  * @return array The updated array of query args keys.
53
  */
54
  public function add_removable_query_args( $removable_query_args ) {
55
- $removable_query_args[] = 'cloned';
56
- $removable_query_args[] = 'rewriting';
 
 
57
  return $removable_query_args;
58
  }
59
 
52
  * @return array The updated array of query args keys.
53
  */
54
  public function add_removable_query_args( $removable_query_args ) {
55
+ if ( \is_array( $removable_query_args ) ) {
56
+ $removable_query_args[] = 'cloned';
57
+ $removable_query_args[] = 'rewriting';
58
+ }
59
  return $removable_query_args;
60
  }
61
 
src/watchers/class-original-post-watcher.php CHANGED
@@ -69,7 +69,7 @@ class Original_Post_Watcher {
69
 
70
  $post = \get_post();
71
 
72
- if ( \is_null( $post ) ) {
73
  return;
74
  }
75
 
@@ -88,7 +88,7 @@ class Original_Post_Watcher {
88
  public function add_block_editor_notice() {
89
  $post = \get_post();
90
 
91
- if ( \is_null( $post ) ) {
92
  return;
93
  }
94
 
69
 
70
  $post = \get_post();
71
 
72
+ if ( ! $post instanceof \WP_Post ) {
73
  return;
74
  }
75
 
88
  public function add_block_editor_notice() {
89
  $post = \get_post();
90
 
91
+ if ( ! $post instanceof \WP_Post ) {
92
  return;
93
  }
94
 
src/watchers/class-republished-post-watcher.php CHANGED
@@ -52,10 +52,11 @@ class Republished_Post_Watcher {
52
  * @return array The updated array of query args keys.
53
  */
54
  public function add_removable_query_args( $removable_query_args ) {
55
- $removable_query_args[] = 'dprepublished';
56
- $removable_query_args[] = 'dpcopy';
57
- $removable_query_args[] = 'dpnonce';
58
-
 
59
  return $removable_query_args;
60
  }
61
 
52
  * @return array The updated array of query args keys.
53
  */
54
  public function add_removable_query_args( $removable_query_args ) {
55
+ if ( \is_array( $removable_query_args ) ) {
56
+ $removable_query_args[] = 'dprepublished';
57
+ $removable_query_args[] = 'dpcopy';
58
+ $removable_query_args[] = 'dpnonce';
59
+ }
60
  return $removable_query_args;
61
  }
62