Duplicate Page and Post - Version 2.7

Version Description

Download this release

Release Info

Developer arjunthakur
Plugin Icon 128x128 Duplicate Page and Post
Version 2.7
Comparing to
See all releases

Code changes from version 2.6.1 to 2.7

Files changed (2) hide show
  1. duplicate-wp-page-post.php +45 -41
  2. readme.txt +3 -3
duplicate-wp-page-post.php CHANGED
@@ -2,15 +2,19 @@
2
  /*
3
  Plugin Name: Duplicate Page and Post
4
  Plugin URI: https://wordpress.org/plugins/duplicate-wp-page-post/
5
- Description: This plugin quickly creates a clone of page or post and supports Gutenberg.
6
  Author: Arjun Thakur
7
  Author URI: https://profiles.wordpress.org/arjunthakur#content-plugins
8
- Version: 2.6.1
9
  License: GPLv2 or later
10
  Text Domain: dpp_wpp_page
11
  */
12
  if ( ! defined( 'ABSPATH' ) ) exit;
13
- if (!defined("dpp_wpp_page_directory-dn")) define("dpp_wpp_page_directory-dn", plugin_basename(dirname(__FILE__)));
 
 
 
 
14
  if(!class_exists('dcc_dpp_wpp_page')):
15
  class dpp_wpp_page
16
  {
@@ -21,7 +25,7 @@ if(!class_exists('dcc_dpp_wpp_page')):
21
  $opt = get_option('dpp_wpp_page_options');
22
  register_activation_hook(__FILE__, array(&$this, 'dpp_wpp_page_install'));
23
  add_action('admin_menu', array(&$this, 'dpp_page_options_page'));
24
- add_filter( 'plugin_action_links', array(&$this, 'dpp_page_plugin_action_links'), 10, 2 );
25
  add_action( 'admin_action_dt_dpp_post_as_draft', array(&$this,'dt_dpp_post_as_draft') );
26
  add_filter( 'post_row_actions', array(&$this,'dt_dpp_post_link'), 10, 2);
27
  add_filter( 'page_row_actions', array(&$this,'dt_dpp_post_link'), 10, 2);
@@ -50,10 +54,6 @@ if(!class_exists('dcc_dpp_wpp_page')):
50
  }
51
  }
52
 
53
- /* Plugin Action Links(Dashboard) */
54
- public function dpp_page_plugin_action_links($links, $file){
55
- return $links;
56
- }
57
 
58
  /* Page Title and Dashboard Menu (Setting options) */
59
  public function dpp_page_options_page(){
@@ -70,8 +70,7 @@ if(!class_exists('dcc_dpp_wpp_page')):
70
  /*Important function*/
71
  public function dt_dpp_post_as_draft()
72
  {
73
-
74
- $nonce = $_REQUEST['nonce'];
75
  $post_id = (isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post']));
76
 
77
 
@@ -84,19 +83,15 @@ if(!class_exists('dcc_dpp_wpp_page')):
84
  //$request_copy = sanitize_text_field( $_REQUEST['action'] );
85
 
86
  $opt = get_option('dpp_wpp_page_options');
87
- $suffix = !empty($opt['dpp_post_suffix']) ? ' -- '.$opt['dpp_post_suffix'] : '';
88
 
89
- $post_status = !empty($opt['dpp_post_status']) ? $opt['dpp_post_status'] : 'draft';
90
- $redirectit = !empty($opt['dpp_post_redirect']) ? $opt['dpp_post_redirect'] : 'to_list';
91
 
92
- //if (! ( isset( $get_copy ) || isset( $post_copy ) || ( isset($request_copy) && 'dt_dpp_post_as_draft' == $request_copy ) ) ) {
93
  if (!(isset($_GET['post']) || isset($_POST['post']) || (isset($_REQUEST['action']) && 'dt_dpp_post_as_draft' == $_REQUEST['action']))) {
94
  wp_die('No post!');
95
  }
96
  $returnpage = '';
97
-
98
- /* Get post id */
99
- //$post_id = (isset($get_copy) ? $get_copy : $post_copy );
100
 
101
  $post = get_post( $post_id );
102
 
@@ -123,18 +118,20 @@ if(!class_exists('dcc_dpp_wpp_page')):
123
  );
124
  $new_post_id = wp_insert_post( $args );
125
 
126
- $taxonomies = get_object_taxonomies($post->post_type);
 
127
  if(!empty($taxonomies) && is_array($taxonomies)):
128
  foreach ($taxonomies as $taxonomy) {
129
  $post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs'));
130
  wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);}
131
  endif;
132
 
133
- $post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id");
134
  if (count($post_meta_infos)!=0) {
135
  $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
136
  foreach ($post_meta_infos as $meta_info) {
137
- $meta_key = $meta_info->meta_key;
 
138
  $meta_value = addslashes($meta_info->meta_value);
139
  $sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'";
140
  }
@@ -144,10 +141,10 @@ if(!class_exists('dcc_dpp_wpp_page')):
144
 
145
  /*choice redirect */
146
  if($post->post_type != 'post'):$returnpage = '?post_type='.$post->post_type; endif;
147
- if(!empty($redirectit) && $redirectit == 'to_list'):wp_redirect( admin_url( 'edit.php'.$returnpage ) );
148
- elseif(!empty($redirectit) && $redirectit == 'to_page'):wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) );
149
  else:
150
- wp_redirect( admin_url( 'edit.php'.$returnpage ) );
151
  endif;
152
  exit;
153
  } else {
@@ -160,11 +157,12 @@ if(!class_exists('dcc_dpp_wpp_page')):
160
 
161
 
162
  /*Add link to action*/
163
- public function dt_dpp_post_link( $actions, $post ) {
 
164
  $opt = get_option('dpp_wpp_page_options');
165
- $link_title = !empty($opt['dpp_post_link_title']) ? $opt['dpp_post_link_title'] : 'Duplicate';
166
  $opt = get_option('dpp_wpp_page_options');
167
- $post_status = !empty($opt['dpp_post_status']) ? $opt['dpp_post_status'] : 'draft';
168
  if (current_user_can('edit_posts')) {
169
  $actions['dpp'] = '<a href="admin.php?action=dt_dpp_post_as_draft&amp;post='.$post->ID.'&amp;nonce='.wp_create_nonce( 'dt-duplicate-page-'.$post->ID ).'" title="Clone this as '.$post_status.'" rel="permalink">'.$link_title.'</a>';
170
  }
@@ -172,12 +170,14 @@ if(!class_exists('dcc_dpp_wpp_page')):
172
  }
173
 
174
  /*Add link to edit Post*/
175
- public function dpp_wpp_page_custom_button(){
 
176
  $opt = get_option('dpp_wpp_page_options');
177
- $link_title = !empty($opt['dpp_post_link_title']) ? $opt['dpp_post_link_title'] : 'Duplicate';
178
  global $post;
179
  $opt = get_option('dpp_wpp_page_options');
180
- $post_status = !empty($opt['dpp_post_status']) ? $opt['dpp_post_status'] : 'draft';
 
181
  $html = '<div id="major-publishing-actions">';
182
  $html .= '<div id="export-action">';
183
  $html .= '<a href="admin.php?action=dt_dpp_post_as_draft&amp;post='.$post->ID.'&amp;nonce='.wp_create_nonce( 'dt-duplicate-page-'.$post->ID ).'" title="Duplicate this as '.$post_status.'" rel="permalink">'.$link_title.'</a>';
@@ -193,7 +193,7 @@ if(!class_exists('dcc_dpp_wpp_page')):
193
  global $post;
194
  if ($post) {
195
  $opt = get_option('dpp_wpp_page_options');
196
- $post_status = !empty($opt['dpp_post_status']) ? $opt['dpp_post_status'] : 'draft';
197
  if (isset($opt['dpp_posteditor']) && $opt['dpp_posteditor'] == 'gutenberg') {
198
  ?>
199
  <style> .link_gutenberg {text-align: center; margin-top: 15px;} .link_gutenberg a {text-decoration: none; display: block; height: 40px; line-height: 28px; padding: 3px 12px 2px; background: #0073AA; border-radius: 3px; border-width: 1px; border-style: solid; color: #ffffff; font-size: 16px; } .link_gutenberg a:hover { background: #23282D; border-color: #23282D; }</style>
@@ -202,7 +202,7 @@ if(!class_exists('dcc_dpp_wpp_page')):
202
  var dtnonce = "<?php echo wp_create_nonce( 'dt-duplicate-page-'.$post->ID );?>";
203
  var dpp_posttitle = "Duplicate this as <?php echo $post_status; ?>";
204
  var dpp_duplicatelink = '<div class="link_gutenberg">';
205
- dpp_duplicatelink += '<a href="admin.php?action=dt_dpp_post_as_draft&amp;post='+dpp_postid'&amp;nonce='+dtnonce+'" title="'+dpp_posttitle+'">Duplicate</a>';
206
  dpp_duplicatelink += '</div>';
207
  jQuery('.edit-post-post-status').append(dpp_duplicatelink);
208
  });</script>
@@ -214,11 +214,11 @@ if(!class_exists('dcc_dpp_wpp_page')):
214
 
215
  /*Click here to clone Admin Bar*/
216
  public function dpp_wpp_page_admin_bar_link()
217
- {
218
  global $wp_admin_bar;
219
  global $post;
220
  $opt = get_option('dpp_wpp_page_options');
221
- $post_status = !empty($opt['dpp_post_status']) ? $opt['dpp_post_status'] : 'draft';
222
  $current_object = get_queried_object();
223
  if ( empty($current_object) )
224
  return;
@@ -233,24 +233,28 @@ if(!class_exists('dcc_dpp_wpp_page')):
233
  }
234
  }
235
 
 
236
  /*WP Url Redirect*/
237
  static function dp_redirect($url)
238
  {
239
  echo '<script>window.location.href="'.$url.'"</script>';
240
  }
241
- }
242
- new dpp_wpp_page;
243
-
244
  /*plugin settings page link*/
245
- add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'dpp_settings_link');
246
- function dpp_settings_link( $links ) {
 
 
247
  $links[] = '<a href="' .
248
  admin_url( 'options-general.php?page=dpp_page_settings' ) .
249
  '">' . __('Settings') . '</a>';
250
- return $links;
 
 
 
 
251
  }
 
252
 
253
  endif;
254
-
255
-
256
  ?>
2
  /*
3
  Plugin Name: Duplicate Page and Post
4
  Plugin URI: https://wordpress.org/plugins/duplicate-wp-page-post/
5
+ Description: Quickly clone a page, post or custom post and supports Gutenberg.
6
  Author: Arjun Thakur
7
  Author URI: https://profiles.wordpress.org/arjunthakur#content-plugins
8
+ Version: 2.7
9
  License: GPLv2 or later
10
  Text Domain: dpp_wpp_page
11
  */
12
  if ( ! defined( 'ABSPATH' ) ) exit;
13
+ if ( ! defined( 'DPP_BASE_NAME' ) ) {
14
+
15
+ define( 'DPP_BASE_NAME', plugin_basename( __FILE__ ) );
16
+ }
17
+
18
  if(!class_exists('dcc_dpp_wpp_page')):
19
  class dpp_wpp_page
20
  {
25
  $opt = get_option('dpp_wpp_page_options');
26
  register_activation_hook(__FILE__, array(&$this, 'dpp_wpp_page_install'));
27
  add_action('admin_menu', array(&$this, 'dpp_page_options_page'));
28
+ add_filter( 'plugin_action_links', array(&$this, 'dpp_settings_link'), 10, 2 );
29
  add_action( 'admin_action_dt_dpp_post_as_draft', array(&$this,'dt_dpp_post_as_draft') );
30
  add_filter( 'post_row_actions', array(&$this,'dt_dpp_post_link'), 10, 2);
31
  add_filter( 'page_row_actions', array(&$this,'dt_dpp_post_link'), 10, 2);
54
  }
55
  }
56
 
 
 
 
 
57
 
58
  /* Page Title and Dashboard Menu (Setting options) */
59
  public function dpp_page_options_page(){
70
  /*Important function*/
71
  public function dt_dpp_post_as_draft()
72
  {
73
+ $nonce = sanitize_text_field($_REQUEST['nonce']);
 
74
  $post_id = (isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post']));
75
 
76
 
83
  //$request_copy = sanitize_text_field( $_REQUEST['action'] );
84
 
85
  $opt = get_option('dpp_wpp_page_options');
86
+ $suffix = !empty($opt['dpp_post_suffix']) ? ' -- '. esc_attr($opt['dpp_post_suffix']) : '';
87
 
88
+ $post_status = !empty($opt['dpp_post_status']) ? esc_attr($opt['dpp_post_status']) : 'draft';
89
+ $redirectit = !empty($opt['dpp_post_redirect']) ? esc_attr($opt['dpp_post_redirect']) : 'to_list';
90
 
 
91
  if (!(isset($_GET['post']) || isset($_POST['post']) || (isset($_REQUEST['action']) && 'dt_dpp_post_as_draft' == $_REQUEST['action']))) {
92
  wp_die('No post!');
93
  }
94
  $returnpage = '';
 
 
 
95
 
96
  $post = get_post( $post_id );
97
 
118
  );
119
  $new_post_id = wp_insert_post( $args );
120
 
121
+
122
+ $taxonomies = array_map('sanitize_text_field',get_object_taxonomies($post->post_type));
123
  if(!empty($taxonomies) && is_array($taxonomies)):
124
  foreach ($taxonomies as $taxonomy) {
125
  $post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs'));
126
  wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);}
127
  endif;
128
 
129
+ $post_meta_infos = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=%d",$post_id));
130
  if (count($post_meta_infos)!=0) {
131
  $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
132
  foreach ($post_meta_infos as $meta_info) {
133
+
134
+ $meta_key = sanitize_text_field($meta_info->meta_key);
135
  $meta_value = addslashes($meta_info->meta_value);
136
  $sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'";
137
  }
141
 
142
  /*choice redirect */
143
  if($post->post_type != 'post'):$returnpage = '?post_type='.$post->post_type; endif;
144
+ if(!empty($redirectit) && $redirectit == 'to_list'):esc_url_raw(wp_redirect( admin_url( 'edit.php'.$returnpage ) ));
145
+ elseif(!empty($redirectit) && $redirectit == 'to_page'):esc_url_raw(wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) ));
146
  else:
147
+ wp_redirect( esc_url_raw(admin_url( 'edit.php'.$returnpage ) ));
148
  endif;
149
  exit;
150
  } else {
157
 
158
 
159
  /*Add link to action*/
160
+ public function dt_dpp_post_link( $actions, $post )
161
+ {
162
  $opt = get_option('dpp_wpp_page_options');
163
+ $link_title = !empty($opt['dpp_post_link_title']) ? esc_attr($opt['dpp_post_link_title']) : 'Duplicate';
164
  $opt = get_option('dpp_wpp_page_options');
165
+ $post_status = !empty($opt['dpp_post_status']) ? esc_attr($opt['dpp_post_status']) : 'draft';
166
  if (current_user_can('edit_posts')) {
167
  $actions['dpp'] = '<a href="admin.php?action=dt_dpp_post_as_draft&amp;post='.$post->ID.'&amp;nonce='.wp_create_nonce( 'dt-duplicate-page-'.$post->ID ).'" title="Clone this as '.$post_status.'" rel="permalink">'.$link_title.'</a>';
168
  }
170
  }
171
 
172
  /*Add link to edit Post*/
173
+ public function dpp_wpp_page_custom_button()
174
+ {
175
  $opt = get_option('dpp_wpp_page_options');
176
+ $link_title = !empty($opt['dpp_post_link_title']) ? esc_attr($opt['dpp_post_link_title']) : 'Duplicate';
177
  global $post;
178
  $opt = get_option('dpp_wpp_page_options');
179
+ $post_status = !empty($opt['duplicate_post_status']) ? esc_attr($opt['duplicate_post_status']) : 'draft';
180
+
181
  $html = '<div id="major-publishing-actions">';
182
  $html .= '<div id="export-action">';
183
  $html .= '<a href="admin.php?action=dt_dpp_post_as_draft&amp;post='.$post->ID.'&amp;nonce='.wp_create_nonce( 'dt-duplicate-page-'.$post->ID ).'" title="Duplicate this as '.$post_status.'" rel="permalink">'.$link_title.'</a>';
193
  global $post;
194
  if ($post) {
195
  $opt = get_option('dpp_wpp_page_options');
196
+ $post_status = !empty($opt['dpp_post_status']) ? esc_attr($opt['dpp_post_status']) : 'draft';
197
  if (isset($opt['dpp_posteditor']) && $opt['dpp_posteditor'] == 'gutenberg') {
198
  ?>
199
  <style> .link_gutenberg {text-align: center; margin-top: 15px;} .link_gutenberg a {text-decoration: none; display: block; height: 40px; line-height: 28px; padding: 3px 12px 2px; background: #0073AA; border-radius: 3px; border-width: 1px; border-style: solid; color: #ffffff; font-size: 16px; } .link_gutenberg a:hover { background: #23282D; border-color: #23282D; }</style>
202
  var dtnonce = "<?php echo wp_create_nonce( 'dt-duplicate-page-'.$post->ID );?>";
203
  var dpp_posttitle = "Duplicate this as <?php echo $post_status; ?>";
204
  var dpp_duplicatelink = '<div class="link_gutenberg">';
205
+ dpp_duplicatelink += '<a href="admin.php?action=dt_dpp_post_as_draft&amp;post='+dpp_postid+'&amp;nonce='+dtnonce+'" title="'+dpp_posttitle+'">Duplicate</a>';
206
  dpp_duplicatelink += '</div>';
207
  jQuery('.edit-post-post-status').append(dpp_duplicatelink);
208
  });</script>
214
 
215
  /*Click here to clone Admin Bar*/
216
  public function dpp_wpp_page_admin_bar_link()
217
+ {
218
  global $wp_admin_bar;
219
  global $post;
220
  $opt = get_option('dpp_wpp_page_options');
221
+ $post_status = !empty($opt['dpp_post_status']) ? esc_attr($opt['dpp_post_status']) : 'draft';
222
  $current_object = get_queried_object();
223
  if ( empty($current_object) )
224
  return;
233
  }
234
  }
235
 
236
+
237
  /*WP Url Redirect*/
238
  static function dp_redirect($url)
239
  {
240
  echo '<script>window.location.href="'.$url.'"</script>';
241
  }
242
+
 
 
243
  /*plugin settings page link*/
244
+ function dpp_settings_link( $links, $file )
245
+ {
246
+ if ($file == DPP_BASE_NAME) {
247
+
248
  $links[] = '<a href="' .
249
  admin_url( 'options-general.php?page=dpp_page_settings' ) .
250
  '">' . __('Settings') . '</a>';
251
+ }
252
+ return $links;
253
+
254
+ }
255
+
256
  }
257
+ new dpp_wpp_page();
258
 
259
  endif;
 
 
260
  ?>
readme.txt CHANGED
@@ -2,10 +2,10 @@
2
  Contributors: arjunthakur, efficientninja
3
  Tags: duplicate post, duplicate page, clone page, clone post, duplicate custom posts, clone custom post, wordpress page duplicator, wordpress post duplicator, page duplicate, clone page and post, wp post clone.
4
  Requires at least: 3.5
5
- Tested up to: 5.4.2
6
  Requires PHP: 5.2.4
7
- Stable tag: 2.6.1
8
- Version: 2.6.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
2
  Contributors: arjunthakur, efficientninja
3
  Tags: duplicate post, duplicate page, clone page, clone post, duplicate custom posts, clone custom post, wordpress page duplicator, wordpress post duplicator, page duplicate, clone page and post, wp post clone.
4
  Requires at least: 3.5
5
+ Tested up to: 5.9.2
6
  Requires PHP: 5.2.4
7
+ Stable tag: 2.7
8
+ Version: 2.7
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11