Duplicate Page and Post - Version 2.9

Version Description

Download this release

Release Info

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

Code changes from version 2.8 to 2.9

duplicate-wp-page-post-setting.php CHANGED
@@ -1,97 +1,126 @@
1
- <?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
 
 
2
  <div class="wrap dpp_page_settings">
3
- <h1><?php _e('Plugin Settings', 'dpp_wpp_page')?></h1>
4
- <?php
5
- $dpp_options = array();
6
- $opt = get_option('dpp_wpp_page_options');
7
- $instruct = isset($_GET['instruct']) ? $_GET['instruct'] : '';
8
- if(isset($_POST['submit_dpp_wpp_page']) && wp_verify_nonce( $_POST['dpp_nonce_field'], 'dpp_page_action' )):
9
- _e("<strong>changes saving..</strong>", 'dpp_wpp_page');
10
- $dpp_nosave = array('submit_dpp_wpp_page');
11
- foreach($dpp_nosave as $noneed):
12
- unset($_POST[$noneed]);
13
- endforeach;
14
- foreach($_POST as $key => $val):
15
- $dpp_options[$key] = sanitize_text_field($val);
16
  endforeach;
17
- $dpp_settings_save = update_option('dpp_wpp_page_options', $dpp_options );
18
- if($dpp_settings_save){ dpp_wpp_page::dp_redirect('options-general.php?page=dpp_page_settings&instruct=1'); }
19
- else{ dpp_wpp_page::dp_redirect('options-general.php?page=dpp_page_settings&instruct=2'); }endif;
20
- if(!empty($instruct) && $instruct == 1):
21
- _e( '<div id="message" class="updated notice notice-success is-dismissible">
 
 
 
 
 
 
22
  <p>Changes Saved!</p>
23
  <button type="button" class="notice-dismiss">
24
  <span class="screen-reader-text">Ignore this notice.</span>
25
  </button>
26
- </div>', 'dpp_wpp_page');
27
- elseif(!empty($instruct) && $instruct == 2):
28
- _e( '<div id="message" class="error notice notice-error is-dismissible">
29
  <p>Changes not saved!</p>
30
  <button type="button" class="notice-dismiss">
31
  <span class="screen-reader-text">Ignore this notice.</span>
32
  </button>
33
- </div>', 'dpp_wpp_page');
34
- endif;
35
- //$dpp_post_status = array('draft');
36
- ?>
37
- <div id="dpp-stuff"><div id="dpp-post-body" class="metabox-holder columns-2"><div id="dpp-post-body-content" style="position: relative;">
38
- <form style="padding: 10px; border: 1px solid #333;" action="" method="post" name="dpp_wpp_page_form">
39
- <?php wp_nonce_field( 'dpp_page_action', 'dpp_nonce_field' ); ?>
40
- <table class="form-table">
41
- <tbody>
42
- <tr>
43
- <th scope="row"><label for="dpp_posteditor"><?php _e('Select Editor<br><em>Default: Classic Editor</em>', 'dpp_wpp_page'); ?></label></th>
44
- <td>
45
- <select id="dpp_posteditor" name="dpp_posteditor">
46
- <option value="classic" <?php echo (isset($opt['dpp_posteditor']) && $opt['dpp_posteditor'] == 'classic') ? "selected = 'selected'" : ''; ?>><?php _e('Classic Editor', 'dpp_wpp_page'); ?></option>
47
- <option value="gutenberg" <?php echo (isset($opt['dpp_posteditor']) && $opt['dpp_posteditor'] == 'gutenberg') ? "selected = 'selected'" : ''; ?>><?php _e('Gutenberg Editor', 'dpp_wpp_page'); ?></option>
48
- </select>
49
- <p><?php _e('Please select which editor you are using.<br> If you are using Gutenberg, select gutenberg editor otherwise it will not show Duplicate button on edit screen.', 'dpp_wpp_page'); ?></p>
50
- </td>
51
- </tr>
52
- <tr>
53
- <th scope="row"><label for="dpp_post_status"><?php _e('Post Status<br><em>Default: Draft</em>', 'dpp_wpp_page'); ?></label></th>
54
- <td>
55
- <select id="dpp_post_status" name="dpp_post_status">
56
- <option value="draft" <?php echo($opt['dpp_post_status'] == 'draft') ? "selected = 'selected'" : ''; ?>><?php _e('Draft', 'dpp_wpp_page'); ?></option>
57
- <option value="publish" <?php echo($opt['dpp_post_status'] == 'publish') ? "selected = 'selected'" : ''; ?>><?php _e('Publish', 'dpp_wpp_page'); ?></option>
58
- <option value="private" <?php echo($opt['dpp_post_status'] == 'private') ? "selected = 'selected'" : ''; ?>><?php _e('Private', 'dpp_wpp_page'); ?></option>
59
- <option value="pending" <?php echo($opt['dpp_post_status'] == 'pending') ? "selected = 'selected'" : ''; ?>><?php _e('Pending', 'dpp_wpp_page'); ?></option>
60
- </select>
61
- <p><?php _e('Please select any post status you want to assign for duplicate post.', 'dpp_wpp_page'); ?></p>
62
- </td>
63
- </tr>
64
- <tr>
65
- <th scope="row"><label for="dpp_post_redirect"><?php _e('Redirect<br><em>Default: To current list.</em><br>(After click on <strong>Duplicate</strong>)', 'dpp_wpp_page'); ?></label></th>
66
- <td>
67
- <select id="dpp_post_redirect" name="dpp_post_redirect">
68
- <option value="to_list" <?php echo($opt['dpp_post_redirect'] == 'to_list') ? "selected = 'selected'" : ''; ?>><?php _e('All Post List', 'dpp_wpp_page'); ?></option>
69
- <option value="to_page" <?php echo($opt['dpp_post_redirect'] == 'to_page') ? "selected = 'selected'" : ''; ?>><?php _e('Direct Edit', 'dpp_wpp_page'); ?></option>
70
- </select>
71
- <p><?php _e('Please select any post redirection, redirect you to selected after click on duplicate.', 'dpp_wpp_page'); ?></p>
72
- </td>
73
- </tr>
74
- <tr>
75
- <th scope="row"><label for="dpp_post_suffix"><?php _e('Duplicate Post Suffix<br><em>Default: Empty</em>', 'dpp_wpp_page')?></label></th>
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
- <td>
78
- <input type="text" class="regular-text" value="<?php echo !empty($opt['dpp_post_suffix']) ? esc_attr($opt['dpp_post_suffix']) : ''?>" id="dpp_post_suffix" name="dpp_post_suffix">
79
- <p><?php _e('Add a suffix for duplicate page and post. It will show after title.', 'dpp_wpp_page')?></p>
80
- </td>
81
- </tr>
82
- <tr>
83
- <th scope="row"><label for="dpp_post_link_title"><?php _e('Duplicate Link Text<br><em>Default: Duplicate</em>', 'dpp_wpp_page')?></label></th>
84
- <td>
85
- <input type="text" class="regular-text" value="<?php echo !empty($opt['dpp_post_link_title']) ? esc_attr($opt['dpp_post_link_title']) : ''?>" id="dpp_post_link_title" name="dpp_post_link_title">
86
- <p><?php _e('It will show above text on duplicate page/post link button instead of default (Duplicate)', 'dpp_wpp_page')?></p>
87
- </td>
88
- </tr>
89
- </tbody>
90
- </table>
91
- <p class="submit"><input type="submit" value="Save Settings" class="button button-primary" id="submit" name="submit_dpp_wpp_page"></p>
92
- </form></div></div>
93
- <div>
94
- <h3><a href="https://wordpress.org/support/plugin/duplicate-wp-page-post/reviews/?filter=5#new-post">Please review us</a> if you like the plugin.</h3>
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  </div>
96
- </div>
97
  </div>
1
+ <?php if ( ! defined( 'ABSPATH' ) ) {
2
+ exit;
3
+ } ?>
4
  <div class="wrap dpp_page_settings">
5
+ <h1><?php _e( 'Plugin Settings', 'duplicate-wp-page-post' ) ?></h1>
6
+ <?php
7
+ $dpp_options = array();
8
+ $opt = get_option( 'dpp_wpp_page_options' );
9
+ $instruct = isset( $_GET['instruct'] ) ? $_GET['instruct'] : '';
10
+ if ( isset( $_POST['submit_dpp_wpp_page'] ) && wp_verify_nonce( $_POST['dpp_nonce_field'], 'dpp_page_action' ) ):
11
+ _e( "<strong>changes saving..</strong>", 'duplicate-wp-page-post' );
12
+ $dpp_nosave = array( 'submit_dpp_wpp_page' );
13
+ foreach ( $dpp_nosave as $noneed ):
14
+ unset( $_POST[ $noneed ] );
 
 
 
15
  endforeach;
16
+ foreach ( $_POST as $key => $val ):
17
+ $dpp_options[ $key ] = sanitize_text_field( $val );
18
+ endforeach;
19
+ $dpp_settings_save = update_option( 'dpp_wpp_page_options', $dpp_options );
20
+ if ( $dpp_settings_save ) {
21
+ dpp_wpp_page::dp_redirect( 'options-general.php?page=dpp_page_settings&instruct=1' );
22
+ } else {
23
+ dpp_wpp_page::dp_redirect( 'options-general.php?page=dpp_page_settings&instruct=2' );
24
+ }endif;
25
+ if ( ! empty( $instruct ) && $instruct == 1 ):
26
+ _e( '<div id="message" class="updated notice notice-success is-dismissible">
27
  <p>Changes Saved!</p>
28
  <button type="button" class="notice-dismiss">
29
  <span class="screen-reader-text">Ignore this notice.</span>
30
  </button>
31
+ </div>', 'duplicate-wp-page-post' );
32
+ elseif ( ! empty( $instruct ) && $instruct == 2 ):
33
+ _e( '<div id="message" class="error notice notice-error is-dismissible">
34
  <p>Changes not saved!</p>
35
  <button type="button" class="notice-dismiss">
36
  <span class="screen-reader-text">Ignore this notice.</span>
37
  </button>
38
+ </div>', 'duplicate-wp-page-post' );
39
+ endif;
40
+ ?>
41
+ <div id="dpp-stuff">
42
+ <div id="dpp-post-body" class="metabox-holder columns-2">
43
+ <div id="dpp-post-body-content" style="position: relative;">
44
+ <form style="padding: 10px; border: 1px solid #333;" action="" method="post" name="dpp_wpp_page_form">
45
+ <?php wp_nonce_field( 'dpp_page_action', 'dpp_nonce_field' ); ?>
46
+ <table class="form-table">
47
+ <tbody>
48
+ <tr>
49
+ <th scope="row"><label
50
+ for="dpp_posteditor">Select Editor<br><em>Default: Classic Editor</em></label>
51
+ </th>
52
+ <td>
53
+ <select id="dpp_posteditor" name="dpp_posteditor">
54
+ <option value="classic" <?php echo ( isset( $opt['dpp_posteditor'] ) && $opt['dpp_posteditor'] == 'classic' ) ? "selected = 'selected'" : ''; ?>><?php _e( 'Classic Editor', 'duplicate-wp-page-post' ); ?></option>
55
+ <option value="gutenberg" <?php echo ( isset( $opt['dpp_posteditor'] ) && $opt['dpp_posteditor'] == 'gutenberg' ) ? "selected = 'selected'" : ''; ?>><?php _e( 'Gutenberg Editor', 'duplicate-wp-page-post' ); ?></option>
56
+ </select>
57
+ <p>Please select which editor you are using.<br> If you are using Gutenberg, select
58
+ gutenberg editor otherwise it will not show Duplicate button on edit screen.</p>
59
+ </td>
60
+ </tr>
61
+ <tr>
62
+ <th scope="row"><label
63
+ for="dpp_post_status">Post Status<br><em>Default: Draft</em></label>
64
+ </th>
65
+ <td>
66
+ <select id="dpp_post_status" name="dpp_post_status">
67
+ <option value="draft" <?php echo ( $opt['dpp_post_status'] == 'draft' ) ? "selected = 'selected'" : ''; ?>><?php _e( 'Draft', 'duplicate-wp-page-post' ); ?></option>
68
+ <option value="publish" <?php echo ( $opt['dpp_post_status'] == 'publish' ) ? "selected = 'selected'" : ''; ?>><?php _e( 'Publish', 'duplicate-wp-page-post' ); ?></option>
69
+ <option value="private" <?php echo ( $opt['dpp_post_status'] == 'private' ) ? "selected = 'selected'" : ''; ?>><?php _e( 'Private', 'duplicate-wp-page-post' ); ?></option>
70
+ <option value="pending" <?php echo ( $opt['dpp_post_status'] == 'pending' ) ? "selected = 'selected'" : ''; ?>><?php _e( 'Pending', 'duplicate-wp-page-post' ); ?></option>
71
+ </select>
72
+ <p>Please select any post status you want to assign for duplicate post.</p>
73
+ </td>
74
+ </tr>
75
+ <tr>
76
+ <th scope="row"><label
77
+ for="dpp_post_redirect">Redirect<br><em>Default: To current list.</em><br>(After
78
+ click on <strong>Duplicate</strong></label>
79
+ </th>
80
+ <td>
81
+ <select id="dpp_post_redirect" name="dpp_post_redirect">
82
+ <option value="to_list" <?php echo ( $opt['dpp_post_redirect'] == 'to_list' ) ? "selected = 'selected'" : ''; ?>><?php _e( 'All Post List', 'duplicate-wp-page-post' ); ?></option>
83
+ <option value="to_page" <?php echo ( $opt['dpp_post_redirect'] == 'to_page' ) ? "selected = 'selected'" : ''; ?>><?php _e( 'Direct Edit', 'duplicate-wp-page-post' ); ?></option>
84
+ </select>
85
+ <p>Please select any post redirection, redirect you to selected after click on
86
+ duplicate.</p>
87
+ </td>
88
+ </tr>
89
+ <tr>
90
+ <th scope="row"><label
91
+ for="dpp_post_suffix">Duplicate Post Suffix<br><em>Default: Empty</em></label>
92
+ </th>
93
 
94
+ <td>
95
+ <input type="text" class="regular-text"
96
+ value="<?php echo ! empty( $opt['dpp_post_suffix'] ) ? esc_attr( $opt['dpp_post_suffix'] ) : '' ?>"
97
+ id="dpp_post_suffix" name="dpp_post_suffix">
98
+ <p>Add a suffix for duplicate page and post. It will show after title.</p>
99
+ </td>
100
+ </tr>
101
+ <tr>
102
+ <th scope="row"><label
103
+ for="dpp_post_link_title">Duplicate Link Text<br><em>Default:
104
+ Duplicate</em></label>
105
+ </th>
106
+ <td>
107
+ <input type="text" class="regular-text"
108
+ value="<?php echo ! empty( $opt['dpp_post_link_title'] ) ? esc_attr( $opt['dpp_post_link_title'] ) : '' ?>"
109
+ id="dpp_post_link_title" name="dpp_post_link_title">
110
+ <p>It will show above text on duplicate page/post link button instead of default
111
+ (Duplicate)</p>
112
+ </td>
113
+ </tr>
114
+ </tbody>
115
+ </table>
116
+ <p class="submit"><input type="submit" value="Save Settings" class="button button-primary"
117
+ id="submit" name="submit_dpp_wpp_page"></p>
118
+ </form>
119
+ </div>
120
+ </div>
121
+ <div>
122
+ <h3><a href="https://wordpress.org/support/plugin/duplicate-wp-page-post/reviews/?filter=5#new-post">Please
123
+ review us</a> if you like the plugin.</h3>
124
+ </div>
125
  </div>
 
126
  </div>
duplicate-wp-page-post.php CHANGED
@@ -5,256 +5,280 @@ 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.8
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
- {
21
-
22
- /*AutoLoad Hooks*/
23
- public function __construct()
24
- {
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);
32
- if (isset($opt['dpp_posteditor']) && $opt['dpp_posteditor'] == 'gutenberg') {
33
- add_action('admin_head', array(&$this, 'dpp_wpp_button_guten'));
34
- } else {
35
- add_action( 'post_submitbox_misc_actions', array(&$this,'dpp_wpp_page_custom_button'));
36
- }
37
- add_action( 'wp_before_admin_bar_render', array(&$this, 'dpp_wpp_page_admin_bar_link'));
38
- }
39
-
40
-
41
-
42
- /*Activation plugin Hook*/
43
- public function dpp_wpp_page_install()
44
- {
45
- $defaultsettings = array('dpp_post_status' => 'draft',
46
- 'dpp_post_redirect' => 'to_list',
47
- 'dpp_post_suffix' => '',
48
- 'dpp_posteditor' => 'classic',
49
- 'dpp_post_link_title' => '', );
50
- $opt = get_option('dpp_wpp_page_options');
51
- if(!$opt['dpp_post_status'])
52
- {
53
- update_option('dpp_wpp_page_options', $defaultsettings);
54
- }
55
- }
56
-
57
-
58
- /* Page Title and Dashboard Menu (Setting options) */
59
- public function dpp_page_options_page(){
60
- add_options_page( __( 'Duplicate Page and Post', 'dpp_wpp_page' ), __( 'Duplicate post', 'dpp_wpp_page' ), 'manage_options', 'dpp_page_settings',array(&$this, 'dpp_page_settings'));
61
- }
62
-
63
- /*Include plugin setting file*/
64
- public function dpp_page_settings(){
65
- if(current_user_can( 'manage_options' )){
66
- include('duplicate-wp-page-post-setting.php');
67
- }
68
- }
69
-
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
-
77
- if(wp_verify_nonce( $nonce, 'dt-duplicate-page-'.$post_id) && current_user_can('edit_posts')) {
78
- global $wpdb;
79
-
80
- /*sanitize_GET POST REQUEST*/
81
- //$post_copy = sanitize_text_field( $_POST["post"] );
82
- //$get_copy = sanitize_text_field( $_GET['post'] );
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
-
98
- $current_user = wp_get_current_user();
99
- $new_post_author = $current_user->ID;
100
-
101
- /*Create the post Copy */
102
- if (isset( $post ) && $post != null) {
103
- /* Post data array */
104
- $args = array('comment_status' => $post->comment_status,
105
- 'ping_status' => $post->ping_status,
106
- 'post_author' => $new_post_author,
107
- 'post_content' => (isset($opt['dpp_posteditor']) && $opt['dpp_posteditor'] == 'gutenberg') ? wp_slash($post->post_content) : $post->post_content,
108
- 'post_excerpt' => $post->post_excerpt,
109
- //'post_name' => $post->post_name,
110
- 'post_parent' => $post->post_parent,
111
- 'post_password' => $post->post_password,
112
- 'post_status' => $post_status,
113
- 'post_title' => $post->post_title.$suffix,
114
- 'post_type' => $post->post_type,
115
- 'to_ping' => $post->to_ping,
116
- 'menu_order' => $post->menu_order
117
-
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
- }
138
- $sql_query.= implode(" UNION ALL ", $sql_query_sel);
139
- $wpdb->query($sql_query);
140
- }
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 {
151
- wp_die('Error! Post creation failed: ' . $post_id);
152
- }
153
- } else {
154
- wp_die('Security check issue, Please try again.');
155
- }
156
- }
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
- }
169
- return $actions;
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>';
184
- $html .= '</div>';
185
- $html .= '</div>';
186
- echo $html;
187
- }
188
- /*
189
- * Add the duplicate link to edit screen - gutenberg
190
- */
191
- public function dpp_wpp_button_guten()
192
- {
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>
200
- <script>jQuery(window).load(function(e){
201
- var dpp_postid = "<?php echo $post->ID; ?>";
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>
209
- <?php
210
- }
211
- }
212
- }
213
-
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;
225
- if ( ! empty( $current_object->post_type ) && ( $post_type_object = get_post_type_object( $current_object->post_type ) )&& ( $post_type_object->show_ui || $current_object->post_type == 'attachment') )
226
- {
227
- $wp_admin_bar->add_menu( array(
228
- 'parent' => 'edit',
229
- 'id' => 'dpp_this',
230
- 'title' => __("Clone this as ".$post_status."", 'dpp_wpp_page'),
231
- 'href' => admin_url().'admin.php?action=dt_dpp_post_as_draft&amp;post='.$post->ID.'&amp;nonce='.wp_create_nonce( 'dt-duplicate-page-'.$post->ID )
232
- ));
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
  ?>
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.9
9
  License: GPLv2 or later
10
  Text Domain: dpp_wpp_page
11
  */
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
  if ( ! defined( 'DPP_BASE_NAME' ) ) {
16
+
17
+ define( 'DPP_BASE_NAME', plugin_basename( __FILE__ ) );
18
  }
19
 
20
+ if ( ! class_exists( 'dcc_dpp_wpp_page' ) ):
21
+ class dpp_wpp_page {
22
+
23
+ /*AutoLoad Hooks*/
24
+ public function __construct() {
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 );
32
+ if ( isset( $opt['dpp_posteditor'] ) && $opt['dpp_posteditor'] == 'gutenberg' ) {
33
+ add_action( 'admin_head', array( &$this, 'dpp_wpp_button_guten' ) );
34
+ } else {
35
+ add_action( 'post_submitbox_misc_actions', array( &$this, 'dpp_wpp_page_custom_button' ) );
36
+ }
37
+ add_action( 'wp_before_admin_bar_render', array( &$this, 'dpp_wpp_page_admin_bar_link' ) );
38
+ }
39
+
40
+
41
+ /*Activation plugin Hook*/
42
+ public function dpp_wpp_page_install() {
43
+ $defaultsettings = array(
44
+ 'dpp_post_status' => 'draft',
45
+ 'dpp_post_redirect' => 'to_list',
46
+ 'dpp_post_suffix' => '',
47
+ 'dpp_posteditor' => 'classic',
48
+ 'dpp_post_link_title' => '',
49
+ );
50
+ $opt = get_option( 'dpp_wpp_page_options' );
51
+ if ( ! $opt['dpp_post_status'] ) {
52
+ update_option( 'dpp_wpp_page_options', $defaultsettings );
53
+ }
54
+ }
55
+
56
+
57
+ /* Page Title and Dashboard Menu (Setting options) */
58
+ public function dpp_page_options_page() {
59
+ add_options_page( __( 'Duplicate Page and Post', 'dpp_wpp_page' ), __( 'Duplicate post', 'dpp_wpp_page' ), 'manage_options', 'dpp_page_settings', array(
60
+ &$this,
61
+ 'dpp_page_settings'
62
+ ) );
63
+ }
64
+
65
+ /*Include plugin setting file*/
66
+ public function dpp_page_settings() {
67
+ if ( current_user_can( 'manage_options' ) ) {
68
+ include( 'duplicate-wp-page-post-setting.php' );
69
+ }
70
+ }
71
+
72
+ /*Important function*/
73
+ public function dt_dpp_post_as_draft() {
74
+ $nonce = sanitize_text_field( $_REQUEST['nonce'] );
75
+ $post_id = ( isset( $_GET['post'] ) ? intval( $_GET['post'] ) : intval( $_POST['post'] ) );
76
+
77
+
78
+ if ( wp_verify_nonce( $nonce, 'dt-duplicate-page-' . $post_id ) && current_user_can( 'edit_posts' ) ) {
79
+ global $wpdb;
80
+
81
+ /*sanitize_GET POST REQUEST*/
82
+ //$post_copy = sanitize_text_field( $_POST["post"] );
83
+ //$get_copy = sanitize_text_field( $_GET['post'] );
84
+ //$request_copy = sanitize_text_field( $_REQUEST['action'] );
85
+
86
+ $opt = get_option( 'dpp_wpp_page_options' );
87
+ $suffix = ! empty( $opt['dpp_post_suffix'] ) ? ' -- ' . esc_attr( $opt['dpp_post_suffix'] ) : '';
88
+
89
+ $post_status = ! empty( $opt['dpp_post_status'] ) ? esc_attr( $opt['dpp_post_status'] ) : 'draft';
90
+ $redirectit = ! empty( $opt['dpp_post_redirect'] ) ? esc_attr( $opt['dpp_post_redirect'] ) : 'to_list';
91
+
92
+ if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'dt_dpp_post_as_draft' == $_REQUEST['action'] ) ) ) {
93
+ wp_die( 'No post!' );
94
+ }
95
+ $returnpage = '';
96
+
97
+ $post = get_post( $post_id );
98
+
99
+ $current_user = wp_get_current_user();
100
+ $new_post_author = $current_user->ID;
101
+
102
+ /*Create the post Copy */
103
+ if ( isset( $post ) && $post != null ) {
104
+ /* Post data array */
105
+ $args = array(
106
+ 'comment_status' => $post->comment_status,
107
+ 'ping_status' => $post->ping_status,
108
+ 'post_author' => $new_post_author,
109
+ 'post_content' => ( isset( $opt['dpp_posteditor'] ) && $opt['dpp_posteditor'] == 'gutenberg' ) ? wp_slash( $post->post_content ) : $post->post_content,
110
+ 'post_excerpt' => $post->post_excerpt,
111
+ //'post_name' => $post->post_name,
112
+ 'post_parent' => $post->post_parent,
113
+ 'post_password' => $post->post_password,
114
+ 'post_status' => $post_status,
115
+ 'post_title' => $post->post_title . $suffix,
116
+ 'post_type' => $post->post_type,
117
+ 'to_ping' => $post->to_ping,
118
+ 'menu_order' => $post->menu_order
119
+
120
+ );
121
+ $new_post_id = wp_insert_post( $args );
122
+
123
+
124
+ $taxonomies = array_map( 'sanitize_text_field', get_object_taxonomies( $post->post_type ) );
125
+ if ( ! empty( $taxonomies ) && is_array( $taxonomies ) ):
126
+ foreach ( $taxonomies as $taxonomy ) {
127
+ $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
128
+ wp_set_object_terms( $new_post_id, $post_terms, $taxonomy, false );
129
+ }
130
+ endif;
131
+
132
+ $post_meta_infos = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=%d", $post_id ) );
133
+ if ( count( $post_meta_infos ) != 0 ) {
134
+ $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
135
+ foreach ( $post_meta_infos as $meta_info ) {
136
+
137
+ $meta_key = sanitize_text_field( $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
+ }
141
+ $sql_query .= implode( " UNION ALL ", $sql_query_sel );
142
+ $wpdb->query( $sql_query );
143
+ }
144
+
145
+ /*choice redirect */
146
+ if ( $post->post_type != 'post' ):$returnpage = '?post_type=' . $post->post_type; endif;
147
+ if ( ! empty( $redirectit ) && $redirectit == 'to_list' ):esc_url_raw( wp_redirect( admin_url( 'edit.php' . $returnpage ) ) );
148
+ elseif ( ! empty( $redirectit ) && $redirectit == 'to_page' ):esc_url_raw( wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) ) );
149
+ else:
150
+ wp_redirect( esc_url_raw( admin_url( 'edit.php' . $returnpage ) ) );
151
+ endif;
152
+ exit;
153
+ } else {
154
+ wp_die( 'Error! Post creation failed: ' . $post_id );
155
+ }
156
+ } else {
157
+ wp_die( 'Security check issue, Please try again.' );
158
+ }
159
+ }
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'] ) ? esc_attr( $opt['dpp_post_link_title'] ) : 'Duplicate';
166
+ $opt = get_option( 'dpp_wpp_page_options' );
167
+ $post_status = ! empty( $opt['dpp_post_status'] ) ? esc_attr( $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
+ }
171
+
172
+ return $actions;
173
+ }
174
+
175
+ /*Add link to edit Post*/
176
+ public function dpp_wpp_page_custom_button() {
177
+ $opt = get_option( 'dpp_wpp_page_options' );
178
+ $link_title = ! empty( $opt['dpp_post_link_title'] ) ? esc_attr( $opt['dpp_post_link_title'] ) : 'Duplicate';
179
+ global $post;
180
+ $opt = get_option( 'dpp_wpp_page_options' );
181
+ $post_status = ! empty( $opt['duplicate_post_status'] ) ? esc_attr( $opt['duplicate_post_status'] ) : 'draft';
182
+
183
+ $html = '<div id="major-publishing-actions">';
184
+ $html .= '<div id="export-action">';
185
+ $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>';
186
+ $html .= '</div>';
187
+ $html .= '</div>';
188
+ echo $html;
189
+ }
190
+
191
+ /*
192
+ * Add the duplicate link to edit screen - gutenberg
193
+ */
194
+ public function dpp_wpp_button_guten() {
195
+ global $post;
196
+ if ( $post ) {
197
+ $opt = get_option( 'dpp_wpp_page_options' );
198
+ $post_status = ! empty( $opt['dpp_post_status'] ) ? esc_attr( $opt['dpp_post_status'] ) : 'draft';
199
+ if ( isset( $opt['dpp_posteditor'] ) && $opt['dpp_posteditor'] == 'gutenberg' ) {
200
+ ?>
201
+ <style> .link_gutenberg {
202
+ text-align: center;
203
+ margin-top: 15px;
204
+ }
205
+
206
+ .link_gutenberg a {
207
+ text-decoration: none;
208
+ display: block;
209
+ height: 40px;
210
+ line-height: 28px;
211
+ padding: 3px 12px 2px;
212
+ background: #0073AA;
213
+ border-radius: 3px;
214
+ border-width: 1px;
215
+ border-style: solid;
216
+ color: #ffffff;
217
+ font-size: 16px;
218
+ }
219
+
220
+ .link_gutenberg a:hover {
221
+ background: #23282D;
222
+ border-color: #23282D;
223
+ }</style>
224
+ <script>jQuery(window).load(function (e) {
225
+ var dpp_postid = "<?php echo esc_attr( $post->ID ); ?>";
226
+ var dtnonce = "<?php echo wp_create_nonce( 'dt-duplicate-page-' . $post->ID );?>";
227
+ var dpp_posttitle = "Duplicate this as <?php echo esc_attr( $post_status ); ?>";
228
+ var dpp_duplicatelink = '<div class="link_gutenberg">';
229
+ dpp_duplicatelink += '<a href="admin.php?action=dt_dpp_post_as_draft&amp;post=' + dpp_postid + '&amp;nonce=' + dtnonce + '" title="' + dpp_posttitle + '">Duplicate</a>';
230
+ dpp_duplicatelink += '</div>';
231
+ jQuery('.edit-post-post-status').append(dpp_duplicatelink);
232
+ });</script>
233
+ <?php
234
+ }
235
+ }
236
+ }
237
+
238
+
239
+ /*Click here to clone Admin Bar*/
240
+ public function dpp_wpp_page_admin_bar_link() {
241
+ global $wp_admin_bar;
242
+ global $post;
243
+ $opt = get_option( 'dpp_wpp_page_options' );
244
+ $post_status = ! empty( $opt['dpp_post_status'] ) ? esc_attr( $opt['dpp_post_status'] ) : 'draft';
245
+ $current_object = get_queried_object();
246
+ if ( empty( $current_object ) ) {
247
+ return;
248
+ }
249
+ if ( ! empty( $current_object->post_type ) && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) && ( $post_type_object->show_ui || $current_object->post_type == 'attachment' ) ) {
250
+ $wp_admin_bar->add_menu( array(
251
+ 'parent' => 'edit',
252
+ 'id' => 'dpp_this',
253
+ 'title' => __( "Clone this as " . $post_status . "", 'duplicate-wp-page-post' ),
254
+ 'href' => admin_url() . 'admin.php?action=dt_dpp_post_as_draft&amp;post=' . $post->ID . '&amp;nonce=' . wp_create_nonce( 'dt-duplicate-page-' . $post->ID )
255
+ ) );
256
+ }
257
+ }
258
+
259
+
260
+ /*WP Url Redirect*/
261
+ static function dp_redirect( $url ) {
262
+ $result = '<script>window.location.href="' . $url . '"</script>';
263
+ print( $result );
264
+ }
265
+
266
+ /*plugin settings page link*/
267
+ function dpp_settings_link( $links, $file ) {
268
+ if ( $file == DPP_BASE_NAME ) {
269
+
270
+ $links[] = '<a href="' .
271
+ admin_url( 'options-general.php?page=dpp_page_settings' ) .
272
+ '">' . __( 'Settings' ) . '</a>';
273
+ }
274
+
275
+ return $links;
276
+
277
+ }
278
+
279
+ }
280
+
281
+ new dpp_wpp_page();
282
 
283
  endif;
284
  ?>
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: 6.0.1
6
  Requires PHP: 5.2.4
7
- Stable tag: 2.8
8
- Version: 2.8
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: 6.0.2
6
  Requires PHP: 5.2.4
7
+ Stable tag: 2.9
8
+ Version: 2.9
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11