forked from Yoast/duplicate-post
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduplicate-post-options.php
More file actions
550 lines (514 loc) · 19.8 KB
/
duplicate-post-options.php
File metadata and controls
550 lines (514 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
<?php
/**
* Options page
*
* @package Duplicate Post
* @since 2.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit();
}
if ( is_admin() ) {
add_action( 'admin_menu', 'duplicate_post_menu' );
add_action( 'admin_init', 'duplicate_post_register_settings' );
}
/**
* Registers settings.
*/
function duplicate_post_register_settings() {
register_setting( 'duplicate_post_group', 'duplicate_post_copytitle' );
register_setting( 'duplicate_post_group', 'duplicate_post_copydate' );
register_setting( 'duplicate_post_group', 'duplicate_post_copystatus' );
register_setting( 'duplicate_post_group', 'duplicate_post_copyslug' );
register_setting( 'duplicate_post_group', 'duplicate_post_copyexcerpt' );
register_setting( 'duplicate_post_group', 'duplicate_post_copycontent' );
register_setting( 'duplicate_post_group', 'duplicate_post_copythumbnail' );
register_setting( 'duplicate_post_group', 'duplicate_post_copytemplate' );
register_setting( 'duplicate_post_group', 'duplicate_post_copyformat' );
register_setting( 'duplicate_post_group', 'duplicate_post_copyauthor' );
register_setting( 'duplicate_post_group', 'duplicate_post_copypassword' );
register_setting( 'duplicate_post_group', 'duplicate_post_copyattachments' );
register_setting( 'duplicate_post_group', 'duplicate_post_copychildren' );
register_setting( 'duplicate_post_group', 'duplicate_post_copycomments' );
register_setting( 'duplicate_post_group', 'duplicate_post_copymenuorder' );
register_setting( 'duplicate_post_group', 'duplicate_post_blacklist' );
register_setting( 'duplicate_post_group', 'duplicate_post_taxonomies_blacklist' );
register_setting( 'duplicate_post_group', 'duplicate_post_title_prefix' );
register_setting( 'duplicate_post_group', 'duplicate_post_title_suffix' );
register_setting( 'duplicate_post_group', 'duplicate_post_increase_menu_order_by' );
register_setting( 'duplicate_post_group', 'duplicate_post_roles' );
register_setting( 'duplicate_post_group', 'duplicate_post_types_enabled' );
register_setting( 'duplicate_post_group', 'duplicate_post_show_row' );
register_setting( 'duplicate_post_group', 'duplicate_post_show_adminbar' );
register_setting( 'duplicate_post_group', 'duplicate_post_show_submitbox' );
register_setting( 'duplicate_post_group', 'duplicate_post_show_bulkactions' );
register_setting( 'duplicate_post_group', 'duplicate_post_show_notice' );
}
/**
* Adds options page to menu.
*/
function duplicate_post_menu() {
add_options_page(
__( 'Duplicate Post Options', 'duplicate-post' ),
__( 'Duplicate Post', 'duplicate-post' ),
'manage_options',
'duplicatepost',
'duplicate_post_options'
);
}
/**
* Show options page.
*
* @global WP_Roles $wp_roles WordPress User Roles.
* @global string $wp_version The WordPress version string.
*/
function duplicate_post_options() {
global $wp_roles, $wp_version;
if ( current_user_can( 'promote_users' ) && ( isset( $_GET['settings-updated'] ) && true === $_GET['settings-updated'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$roles = $wp_roles->get_names();
$dp_roles = get_option( 'duplicate_post_roles' );
if ( '' === $dp_roles ) {
$dp_roles = array();
}
foreach ( $roles as $name => $display_name ) {
$role = get_role( $name );
if ( ! $role->has_cap( 'copy_posts' ) && in_array( $name, $dp_roles, true ) ) {
/* If the role doesn't have the capability and it was selected, add it. */
$role->add_cap( 'copy_posts' );
} elseif ( $role->has_cap( 'copy_posts' ) && ! in_array( $name, $dp_roles, true ) ) {
/* If the role has the capability and it wasn't selected, remove it. */
$role->remove_cap( 'copy_posts' );
}
}
}
?>
<div class="wrap">
<div id="icon-options-general" class="icon32">
<br>
</div>
<h1>
<?php esc_html_e( 'Duplicate Post Options', 'duplicate-post' ); ?>
</h1>
<div
style="margin: 9px 15px 4px 0; padding: 5px 30px; text-align: center; float: left; clear: left; border: solid 3px #cccccc; width: 600px;">
<p>
<?php esc_html_e( 'Help me develop the plugin, add new features and improve support!', 'duplicate-post' ); ?>
<br />
<?php esc_html_e( 'Donate whatever sum you choose, even just 10¢.', 'duplicate-post' ); ?>
<br /> <a href="https://duplicate-post.lopo.it/donate"><img
id="donate-button" style="margin: 0 auto;"
src="<?php echo esc_url( plugins_url( 'donate.png', __FILE__ ) ); ?>"
alt="Donate" /></a> <br /> <a href="https://duplicate-post.lopo.it/"><?php esc_html_e( 'Documentation', 'duplicate-post' ); ?></a>
- <a
href="https://translate.wordpress.org/projects/wp-plugins/duplicate-post"><?php esc_html_e( 'Translate', 'duplicate-post' ); ?></a>
- <a href="https://wordpress.org/support/plugin/duplicate-post"><?php esc_html_e( 'Support Forum', 'duplicate-post' ); ?></a>
</p>
</div>
<script>
jQuery(document).on( 'click', '.nav-tab-wrapper a', function() {
jQuery('.nav-tab').removeClass('nav-tab-active');
jQuery(this).addClass('nav-tab-active');
jQuery('section').hide();
jQuery('section').eq(jQuery(this).index()).show();
return false;
});
function toggle_private_taxonomies(){
jQuery('.taxonomy_private').toggle(300);
}
jQuery(function(){
jQuery('.taxonomy_private').hide(300);
});
</script>
<style>
h2.nav-tab-wrapper {
margin: 22px 0 0 0;
}
h2 .nav-tab:focus {
color: #555;
box-shadow: none;
}
#sections {
padding: 22px;
background: #fff;
border: 1px solid #ccc;
border-top: 0;
}
section {
display: none;
}
section:first-of-type {
display: block;
}
.no-js h2.nav-tab-wrapper {
display: none;
}
.no-js #sections {
border-top: 1px solid #ccc;
margin-top: 22px;
}
.no-js section {
border-top: 1px dashed #aaa;
margin-top: 22px;
padding-top: 22px;
}
.no-js section:first-child {
margin: 0;
padding: 0;
border: 0;
}
label {
display: block;
}
label.taxonomy_private {
font-style: italic;
}
a.toggle_link {
font-size: small;
}
img#donate-button {
vertical-align: middle;
}
</style>
<form method="post" action="options.php" style="clear: both">
<?php settings_fields( 'duplicate_post_group' ); ?>
<h2 class="nav-tab-wrapper">
<a class="nav-tab nav-tab-active"
href="<?php echo esc_url( admin_url( '/index.php?page=duplicate-post-what' ) ); ?>"><?php esc_html_e( 'What to copy', 'duplicate-post' ); ?>
</a> <a class="nav-tab"
href="<?php echo esc_url( admin_url( '/index.php?page=duplicate-post-who' ) ); ?>"><?php esc_html_e( 'Permissions', 'duplicate-post' ); ?>
</a> <a class="nav-tab"
href="<?php echo esc_url( admin_url( '/index.php?page=duplicate-post-where' ) ); ?>"><?php esc_html_e( 'Display', 'duplicate-post' ); ?>
</a>
</h2>
<section>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Post/page elements to copy', 'duplicate-post' ); ?>
</th>
<td colspan="2"><label> <input type="checkbox"
name="duplicate_post_copytitle" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copytitle' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Title', 'default' ); ?>
</label> <label> <input type="checkbox"
name="duplicate_post_copydate" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copydate' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Date', 'default' ); ?>
</label> <label> <input type="checkbox"
name="duplicate_post_copystatus" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copystatus' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Status', 'default' ); ?>
</label> <label> <input type="checkbox"
name="duplicate_post_copyslug" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copyslug' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Slug', 'default' ); ?>
</label> <label> <input type="checkbox"
name="duplicate_post_copyexcerpt" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copyexcerpt' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Excerpt', 'default' ); ?>
</label> <label> <input type="checkbox"
name="duplicate_post_copycontent" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copycontent' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Content', 'default' ); ?>
</label> <label> <input type="checkbox"
name="duplicate_post_copythumbnail" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copythumbnail' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Featured Image', 'default' ); ?>
</label> <label> <input type="checkbox"
name="duplicate_post_copytemplate" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copytemplate' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Template', 'default' ); ?>
</label> <label> <input type="checkbox"
name="duplicate_post_copyformat" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copyformat' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php echo esc_html_x( 'Format', 'post format', 'default' ); ?>
</label> <label> <input type="checkbox"
name="duplicate_post_copyauthor" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copyauthor' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Author', 'default' ); ?>
</label> <label> <input type="checkbox"
name="duplicate_post_copypassword" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copypassword' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Password', 'default' ); ?>
</label> <label> <input type="checkbox"
name="duplicate_post_copyattachments" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copyattachments' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Attachments', 'duplicate-post' ); ?> <small>(<?php esc_html_e( 'you probably want this unchecked, unless you have very special requirements', 'duplicate-post' ); ?>)</small>
</label> <label> <input type="checkbox"
name="duplicate_post_copychildren" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copychildren' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Children', 'duplicate-post' ); ?>
</label> <label> <input type="checkbox"
name="duplicate_post_copycomments" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copycomments' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Comments', 'default' ); ?> <small>(<?php esc_html_e( 'except pingbacks and trackbacks', 'duplicate-post' ); ?>)</small>
</label> <label> <input type="checkbox"
name="duplicate_post_copymenuorder" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_copymenuorder' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Menu order', 'default' ); ?>
</label></td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Title prefix', 'duplicate-post' ); ?>
</th>
<td><input type="text" name="duplicate_post_title_prefix"
value="<?php form_option( 'duplicate_post_title_prefix' ); ?>" />
</td>
<td><span class="description"><?php esc_html_e( 'Prefix to be added before the title, e.g. "Copy of" (blank for no prefix)', 'duplicate-post' ); ?>
</span></td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Title suffix', 'duplicate-post' ); ?>
</th>
<td><input type="text" name="duplicate_post_title_suffix"
value="<?php form_option( 'duplicate_post_title_suffix' ); ?>" />
</td>
<td><span class="description"><?php esc_html_e( 'Suffix to be added after the title, e.g. "(dup)" (blank for no suffix)', 'duplicate-post' ); ?>
</span></td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Increase menu order by', 'duplicate-post' ); ?>
</th>
<td><input type="number" min="0" step="1" name="duplicate_post_increase_menu_order_by"
value="<?php form_option( 'duplicate_post_increase_menu_order_by' ); ?>" />
</td>
<td><span class="description"><?php esc_html_e( 'Add this number to the original menu order (blank or zero to retain the value)', 'duplicate-post' ); ?>
</span></td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Do not copy these fields', 'duplicate-post' ); ?>
</th>
<td id="textfield"><input type="text"
name="duplicate_post_blacklist"
value="<?php form_option( 'duplicate_post_blacklist' ); ?>" /></td>
<td><span class="description"><?php esc_html_e( 'Comma-separated list of meta fields that must not be copied', 'duplicate-post' ); ?><br />
<small><?php esc_html_e( 'You can use * to match zero or more alphanumeric characters or underscores: e.g. field*', 'duplicate-post' ); ?>
</small> </span></td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Do not copy these taxonomies', 'duplicate-post' ); ?><br />
<a class="toggle_link" href="#"
onclick="toggle_private_taxonomies();return false;"><?php esc_html_e( 'Show/hide private taxonomies', 'duplicate-post' ); ?>
</a></th>
<td colspan="2">
<?php
$taxonomies = get_taxonomies( array(), 'objects' );
usort( $taxonomies, 'duplicate_post_tax_obj_cmp' );
$taxonomies_blacklist = get_option( 'duplicate_post_taxonomies_blacklist' );
if ( '' === $taxonomies_blacklist ) {
$taxonomies_blacklist = array();
}
foreach ( $taxonomies as $taxonomy ) :
if ( 'post_format' === $taxonomy->name ) {
continue;
}
?>
<label class="taxonomy_<?php echo ( $taxonomy->public ) ? 'public' : 'private'; ?>">
<input type="checkbox"
name="duplicate_post_taxonomies_blacklist[]"
value="<?php echo esc_attr( $taxonomy->name ); ?>"
<?php
if ( in_array( $taxonomy->name, $taxonomies_blacklist, true ) ) {
echo 'checked="checked"';}
?>
/>
<?php echo esc_html( $taxonomy->labels->name . ' [' . $taxonomy->name . ']' ); ?>
</label> <?php endforeach; ?> <span class="description"><?php esc_html_e( "Select the taxonomies you don't want to be copied", 'duplicate-post' ); ?>
</span></td>
</tr>
</table>
</section>
<section>
<table class="form-table">
<?php if ( current_user_can( 'promote_users' ) ) { ?>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Roles allowed to copy', 'duplicate-post' ); ?>
</th>
<td>
<?php
$roles = $wp_roles->get_names();
$post_types = get_post_types( array( 'show_ui' => true ), 'objects' );
$edit_capabilities = array( 'edit_posts' => true );
foreach ( $post_types as $post_type ) {
$edit_capabilities[ $post_type->cap->edit_posts ] = true;
}
foreach ( $roles as $name => $display_name ) :
$role = get_role( $name );
if ( count( array_intersect_key( $role->capabilities, $edit_capabilities ) ) > 0 ) :
?>
<label> <input type="checkbox" name="duplicate_post_roles[]" value="<?php echo esc_attr( $name ); ?>"
<?php
if ( $role->has_cap( 'copy_posts' ) ) {
echo 'checked="checked"';}
?>
/>
<?php echo esc_html( translate_user_role( $display_name ) ); ?>
</label>
<?php
endif;
endforeach;
?>
<span class="description"><?php esc_html_e( 'Warning: users will be able to copy all posts, even those of other users', 'duplicate-post' ); ?><br />
<?php esc_html_e( 'Passwords and contents of password-protected posts may become visible to undesired users and visitors', 'duplicate-post' ); ?>
</span></td>
</tr>
<?php } ?>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Enable for these post types', 'duplicate-post' ); ?>
</th>
<td>
<?php
$post_types = get_post_types( array( 'show_ui' => true ), 'objects' );
foreach ( $post_types as $post_type_object ) :
if ( 'attachment' === $post_type_object->name ) {
continue;
}
?>
<label> <input type="checkbox"
name="duplicate_post_types_enabled[]"
value="<?php echo esc_attr( $post_type_object->name ); ?>"
<?php
if ( duplicate_post_is_post_type_enabled( $post_type_object->name ) ) {
echo 'checked="checked"';}
?>
/>
<?php echo esc_html( $post_type_object->labels->name ); ?>
</label> <?php endforeach; ?> <span class="description"><?php esc_html_e( 'Select the post types you want the plugin to be enabled', 'duplicate-post' ); ?>
<br /> <?php esc_html_e( 'Whether the links are displayed for custom post types registered by themes or plugins depends on their use of standard WordPress UI elements', 'duplicate-post' ); ?>
</span></td>
</tr>
</table>
</section>
<section>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Show links in', 'duplicate-post' ); ?>
</th>
<td><label><input type="checkbox" name="duplicate_post_show_row"
value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_show_row' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Post list', 'duplicate-post' ); ?> </label> <label><input
type="checkbox" name="duplicate_post_show_submitbox" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_show_submitbox' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Edit screen', 'duplicate-post' ); ?> </label> <label><input
type="checkbox" name="duplicate_post_show_adminbar" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_show_adminbar' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Admin bar', 'duplicate-post' ); ?>
<small>(<?php esc_html_e( 'now works on Edit screen too - check this option to use with Gutenberg enabled', 'duplicate-post' ); ?>)</small></label>
<?php
if ( version_compare( $wp_version, '4.7' ) >= 0 ) {
?>
<label><input type="checkbox"
name="duplicate_post_show_bulkactions" value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_show_bulkactions' ) ) ) {
echo 'checked="checked"';}
?>
/>
<?php esc_html_e( 'Bulk Actions', 'default' ); ?> </label>
<?php } ?>
</td>
</tr>
<tr valign="top">
<td colspan="2"><span class="description"><?php esc_html_e( 'Whether the links are displayed for custom post types registered by themes or plugins depends on their use of standard WordPress UI elements', 'duplicate-post' ); ?>
<br />
<?php
/* translators: %s: URL of the template tag documentation */
printf( esc_html__( 'You can also use the template tag duplicate_post_clone_post_link( $link, $before, $after, $id ). More info <a href="%s">here</a>', 'duplicate-post' ), 'https://duplicate-post.lopo.it/docs/developers-guide/functions-template-tags/duplicate_post_clone_post_link/' );
?>
</span></td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Show update notice', 'duplicate-post' ); ?>
</th>
<td><input type="checkbox" name="duplicate_post_show_notice"
value="1"
<?php
if ( 1 === intval( get_option( 'duplicate_post_show_notice' ) ) ) {
echo 'checked="checked"';}
?>
/>
</td>
</tr>
</table>
</section>
<p class="submit">
<input type="submit" class="button-primary"
value="<?php esc_html_e( 'Save Changes', 'duplicate-post' ); ?>" />
</p>
</form>
</div>
<?php
}
?>