Version Description
Download this release
Release Info
Developer | arjunthakur |
Plugin | 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 +113 -84
- duplicate-wp-page-post.php +268 -244
- readme.txt +3 -3
duplicate-wp-page-post-setting.php
CHANGED
@@ -1,97 +1,126 @@
|
|
1 |
-
<?php if ( ! defined( 'ABSPATH' ) )
|
|
|
|
|
2 |
<div class="wrap dpp_page_settings">
|
3 |
-
<h1><?php _e('Plugin Settings', '
|
4 |
-
<?php
|
5 |
-
$dpp_options = array();
|
6 |
-
$opt
|
7 |
-
$instruct
|
8 |
-
if(isset($_POST['submit_dpp_wpp_page']) && wp_verify_nonce( $_POST['dpp_nonce_field'], 'dpp_page_action' )):
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
endforeach;
|
14 |
-
foreach($_POST as $key => $val):
|
15 |
-
$dpp_options[$key] = sanitize_text_field($val);
|
16 |
endforeach;
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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>', '
|
27 |
-
elseif(!empty($instruct) && $instruct == 2):
|
28 |
-
|
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>', '
|
34 |
-
endif;
|
35 |
-
|
36 |
-
|
37 |
-
<div id="dpp-
|
38 |
-
<
|
39 |
-
|
40 |
-
|
41 |
-
<
|
42 |
-
<
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
</
|
52 |
-
<
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
<
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
</
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
</
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
9 |
License: GPLv2 or later
|
10 |
Text Domain: dpp_wpp_page
|
11 |
*/
|
12 |
-
if ( ! defined( 'ABSPATH' ) )
|
|
|
|
|
13 |
if ( ! defined( 'DPP_BASE_NAME' ) ) {
|
14 |
-
|
15 |
-
|
16 |
}
|
17 |
|
18 |
-
if(!class_exists('dcc_dpp_wpp_page')):
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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&post=' . $post->ID . '&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&post=' . $post->ID . '&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&post=' + dpp_postid + '&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&post=' . $post->ID . '&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.
|
6 |
Requires PHP: 5.2.4
|
7 |
-
Stable tag: 2.
|
8 |
-
Version: 2.
|
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 |
|