-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
carbon-copy-options.php
375 lines (324 loc) · 17.9 KB
/
carbon-copy-options.php
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
<?php
// Options page
if( ! defined( 'ABSPATH' ) )
{
exit(); // No direct access
}
// Admin actions
if( is_admin() )
{
add_action( 'admin_menu', 'carbon_copy_menu' );
add_action( 'admin_init', 'carbon_copy_register_settings' );
}
// Whitelisted options
function carbon_copy_register_settings()
{
register_setting( 'carbon_copy_group', 'carbon_copy_copytitle' );
register_setting( 'carbon_copy_group', 'carbon_copy_copydate' );
register_setting( 'carbon_copy_group', 'carbon_copy_copystatus' );
register_setting( 'carbon_copy_group', 'carbon_copy_copyslug' );
register_setting( 'carbon_copy_group', 'carbon_copy_copyexcerpt' );
register_setting( 'carbon_copy_group', 'carbon_copy_copycontent' );
register_setting( 'carbon_copy_group', 'carbon_copy_copythumbnail' );
register_setting( 'carbon_copy_group', 'carbon_copy_copytemplate' );
register_setting( 'carbon_copy_group', 'carbon_copy_copyformat' );
register_setting( 'carbon_copy_group', 'carbon_copy_copyauthor' );
register_setting( 'carbon_copy_group', 'carbon_copy_copypassword' );
register_setting( 'carbon_copy_group', 'carbon_copy_copyattachments' );
register_setting( 'carbon_copy_group', 'carbon_copy_copychildren' );
register_setting( 'carbon_copy_group', 'carbon_copy_copycomments' );
register_setting( 'carbon_copy_group', 'carbon_copy_copymenuorder' );
register_setting( 'carbon_copy_group', 'carbon_copy_widgets_classic' );
register_setting( 'carbon_copy_group', 'carbon_copy_widgets' );
register_setting( 'carbon_copy_group', 'carbon_copy_menus' );
register_setting( 'carbon_copy_group', 'carbon_copy_roles' );
register_setting( 'carbon_copy_group', 'carbon_copy_types_enabled' );
register_setting( 'carbon_copy_group', 'carbon_copy_taxonomies_blacklist' );
register_setting( 'carbon_copy_group', 'carbon_copy_title_prefix' );
register_setting( 'carbon_copy_group', 'carbon_copy_title_suffix' );
register_setting( 'carbon_copy_group', 'carbon_copy_increase_menu_order_by' );
register_setting( 'carbon_copy_group', 'carbon_copy_blacklist ');
register_setting( 'carbon_copy_group', 'carbon_copy_show_row' );
register_setting( 'carbon_copy_group', 'carbon_copy_show_adminbar' );
register_setting( 'carbon_copy_group', 'carbon_copy_show_submitbox' );
register_setting( 'carbon_copy_group', 'carbon_copy_show_bulkactions' );
register_setting( 'carbon_copy_group', 'carbon_copy_show_original_column' );
register_setting( 'carbon_copy_group', 'carbon_copy_show_original_in_post_states' );
register_setting( 'carbon_copy_group', 'carbon_copy_show_original_meta_box' );
register_setting( 'carbon_copy_group', 'carbon_copy_cleaner' );
}
// Admin backend menu
function carbon_copy_menu()
{
add_options_page( __( "Carbon Copy Options", 'carbon-copy' ), __( "Carbon Copy", 'carbon-copy' ), 'manage_options', 'carboncopy', 'carbon_copy_options' );
}
function carbon_copy_options()
{
if( current_user_can( 'promote_users' ) && ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true ) )
{
global $wp_roles;
$roles = $wp_roles->get_names();
$cc_roles = get_option( 'carbon_copy_roles' );
if( $cc_roles == "" )
$cc_roles = array();
foreach( $roles as $name => $display_name )
{
$role = get_role( $name );
// If role capability does not exsist, add it.
if( ! $role->has_cap( 'copy_posts' ) && in_array( $name, $cc_roles ) )
$role->add_cap( 'copy_posts' );
// If role capability exists but was not selected, remove it.
elseif( $role->has_cap( 'copy_posts' ) && !in_array($name, $cc_roles ) )
$role->remove_cap( 'copy_posts' );
}
}
?>
<div class="wrap">
<h1><?php esc_html_e( "Carbon Copy Options", 'default' ); ?></h1>
<script>
function toggle_private_taxonomies()
{
jQuery( '.taxonomy_private' ).toggle( 300 );
}
jQuery( function()
{
jQuery( '.taxonomy_private' ).hide( 300 );
});
</script>
<form method="post" action="options.php" style="clear: both" id="carbon_copy_settings_form">
<?php settings_fields('carbon_copy_group'); ?>
<div style="padding:10px 0px;"></div>
<h2 id="elements-copy">Elements to be Copied</h2>
<hr />
<label>
<input type="checkbox" name="carbon_copy_copytitle" value="1" <?php if( get_option( 'carbon_copy_copytitle' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Title", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copydate" value="1" <?php if( get_option( 'carbon_copy_copydate' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Date", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copystatus" value="1" <?php if( get_option( 'carbon_copy_copystatus' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Status", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copyslug" value="1" <?php if( get_option( 'carbon_copy_copyslug' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Slug", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copyexcerpt" value="1" <?php if( get_option( 'carbon_copy_copyexcerpt' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Excerpt", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copycontent" value="1" <?php if( get_option( 'carbon_copy_copycontent' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Content", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copythumbnail" value="1" <?php if( get_option( 'carbon_copy_copythumbnail' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Featured Image", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copytemplate" value="1" <?php if( get_option( 'carbon_copy_copytemplate' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Template", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copyformat" value="1" <?php if( get_option( 'carbon_copy_copyformat' ) == 1 ) echo 'checked="checked"'; ?> /><?php echo esc_html_x( "Format", 'post format', 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copyauthor" value="1" <?php if( get_option( 'carbon_copy_copyauthor' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Author", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copypassword" value="1" <?php if( get_option( 'carbon_copy_copypassword' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Password", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copyattachments" value="1" <?php if( get_option( 'carbon_copy_copyattachments' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Attachments", 'default' ); ?>
<span class="description">(<em><?php esc_html_e( "leave unchecked, unless you need special requirements", 'default' ); ?></em>)</span>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copychildren" value="1" <?php if( get_option( 'carbon_copy_copychildren' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Children", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copycomments" value="1" <?php if( get_option( 'carbon_copy_copycomments' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Comments", 'default' ); ?>
<span class="description">(<em><?php esc_html_e( "except pingbacks and trackbacks", 'default' ); ?></em>)</span>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_copymenuorder" value="1" <?php if( get_option( 'carbon_copy_copymenuorder' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Menu order", 'default' ); ?>
</label><br />
<div style="padding:10px 0px;"></div>
<h3>Others</h3>
<label>
<input type="checkbox" name="carbon_copy_widgets_classic" value="1" <?php if( get_option( 'carbon_copy_widgets_classic' ) == 1 ) echo 'checked="checked"'; ?> /><strong><?php esc_html_e( "Classic Widgets:", 'default' ); ?></strong> <?php esc_html_e( "Disables Widget Block Editor Management", 'default' ); ?>
</label><?php if( get_option( 'carbon_copy_widgets_classic' ) == 1 ) echo ' | <a href="widgets.php" title="Opens Widgets page in New Window" target="_blank">Widgets Page</a>'; ?><br />
<label>
<input type="checkbox" name="carbon_copy_widgets" value="1" <?php if( get_option( 'carbon_copy_widgets' ) == 1 ) echo 'checked="checked"'; ?> /><strong><?php esc_html_e( "Widgets Carbon Copier:", 'default' ); ?></strong> <?php esc_html_e( "(only works with Classic Widgets) Located under Appearance > Widgets", 'default' ); ?>
</label><?php if( get_option( 'carbon_copy_widgets' ) == 1 ) echo ' | <a href="widgets.php" title="Opens Widgets page in New Window" target="_blank">Widgets Page</a>'; ?><br />
<label>
<input type="checkbox" name="carbon_copy_menus" value="1" <?php if( get_option( 'carbon_copy_menus' ) == 1 ) echo 'checked="checked"'; ?> /><strong><?php esc_html_e( "Menus Carbon Copy:", 'default' ); ?></strong> <?php esc_html_e( "Located under Appearance > Menus Carbon Copy", 'default' ); ?>
</label><?php if( get_option( 'carbon_copy_menus' ) == 1 ) echo ' | <a href="themes.php?page=carbon-copy-menu" title="Opens Menus Carbon Copy page in New Window" target="_blank">Menus Carbon Copy</a>'; ?><br />
<div style="padding:10px 0px;"></div>
<h2 id="permissions">Copy Permissions</h2>
<hr />
<?php if( current_user_can( 'promote_users' ) )
{
?>
<h3>Roles Allowed to Copy</h3>
<span class="description"><?php esc_html_e( "NOTICE: If enabled, users role can copy ALL posts, even from other users!", 'default' ); ?></span><br />
<span class="description"><?php esc_html_e( "Password protected posts and contents will be visible users and visitors.", 'default' ); ?></span><br />
<br />
<?php
global $wp_roles;
$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="carbon_copy_roles[]" value="<?php echo $name; ?>" <?php if( $role->has_cap( 'copy_posts' ) ) echo 'checked="checked"'; ?> /><?php echo translate_user_role( $display_name ); ?>
</label><br />
<?php
endif;
endforeach;
}
?>
<div style="padding:10px 0px;"></div>
<h3>Permitted Post Types</h3>
<span class="description"><?php esc_html_e( "Select post types to be enabled. Custom Post Types might not display here as they are dependent upon your Theme or Plugin.", 'default' ); ?></span><br />
<br />
<?php
$post_types = get_post_types( array( 'show_ui' => true ), 'objects' );
foreach( $post_types as $post_type_object ) :
if( $post_type_object->name == 'attachment' )
continue;
?>
<label>
<input type="checkbox" name="carbon_copy_types_enabled[]" value="<?php echo $post_type_object->name; ?>" <?php if( carbon_copy_is_post_type_enabled( $post_type_object->name ) ) echo 'checked="checked"'; ?> /><?php echo $post_type_object->labels->name; ?>
</label><br />
<?php
endforeach;
?>
<div style="padding:10px 0px;"></div>
<h3>Taxonomies to be Excluded</h3>
<span class="description"><?php esc_html_e( "Select the taxonomies to be exclude.", 'carbon-copy' ); ?></span><br />
<a class="toggle_link" href="#" onclick="toggle_private_taxonomies();return false;"><?php esc_html_e( 'Show/hide private taxonomies', 'default' ); ?></a><br />
<br />
<?php
$taxonomies = get_taxonomies( array(), 'objects' );
usort( $taxonomies, 'carbon_copy_tax_obj_cmp' );
$taxonomies_blacklist = get_option( 'carbon_copy_taxonomies_blacklist' );
if( ! is_array( $taxonomies_blacklist ) )
{
$taxonomies_blacklist = array();
}
foreach( $taxonomies as $taxonomy ) :
if( $taxonomy->name == 'post_format' )
{
continue;
}
?>
<label class="taxonomy_<?php echo ( $taxonomy->public ) ? 'public' : 'private'; ?>">
<input type="checkbox" name="carbon_copy_taxonomies_blacklist[]" value="<?php echo $taxonomy->name ?>" <?php if( in_array( $taxonomy->name, $taxonomies_blacklist ) ) echo 'checked="checked"' ?> /><?php echo $taxonomy->labels->name.' ['.$taxonomy->name.']'; ?>
</label><br />
<?php
endforeach;
?>
<div style="padding:10px 0px;"></div>
<h2 id="customizations">Copy Customizations</h2>
<hr />
<table class="form-table">
<tr valign="top">
<th scope="row">
<label for="carbon_copy_title_prefix">
<?php esc_html_e( "Title prefix", 'default' ); ?>
</label>
</th>
<td>
<input type="text" name="carbon_copy_title_prefix" id="carbon_copy_title_prefix" value="<?php form_option( 'carbon_copy_title_prefix' ); ?>" /><br />
<span class="description"><?php esc_html_e( "For example; \"Copy of\" (leave blank for no prefix)", 'default' ); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="carbon_copy_title_suffix">
<?php esc_html_e( "Title suffix", 'default' ); ?>
</label>
</th>
<td>
<input type="text" name="carbon_copy_title_suffix" id="carbon_copy_title_suffix" value="<?php form_option( 'carbon_copy_title_suffix' ); ?>" /><br />
<span class="description"><?php esc_html_e( "For example; \"Copy\" (leave blank for no suffix)", 'default' ); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="carbon_copy_increase_menu_order_by">
<?php esc_html_e( "Menu order increase", 'default' ); ?>
</label>
</th>
<td>
<input type="text" name="carbon_copy_increase_menu_order_by" id="carbon_copy_increase_menu_order_by" value="<?php form_option( 'carbon_copy_increase_menu_order_by' ); ?>" /><br />
<span class="description"><?php esc_html_e( "Add number to original menu order (leave blank/zero to retain value)", 'default' ); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="carbon_copy_blacklist">
<?php esc_html_e( "Meta Field Exclusion List", 'default' ); ?>
</label>
</th>
<td id="textfield">
<input type="text" class="regular-text" name="carbon_copy_blacklist" id="carbon_copy_blacklist" value="<?php form_option( 'carbon_copy_blacklist' ); ?>" /><br />
<span class="description"><?php esc_html_e( "Comma-separate list, use * to match zero or more alphanumeric characters or underscores: ex. field*", 'default' ); ?></span>
</td>
</tr>
</table>
<div style="padding:10px 0px;"></div>
<h2 id="display">Display</h2>
<hr />
<div style="padding:10px 0px;"></div>
<h3>Link Display Locations</h3>
<span class="description"><?php esc_html_e( "Copy Links for Custom Post Types might not display, they are dependent upon your Theme or Plugin.", 'default' ); ?></span><br />
<span class="description"><?php esc_html_e( "You can use the template tag: carbon_copy_clone_post_link( $link, $before, $after, $id )", 'default' ); ?></span><br />
<?php printf(__( 'Learn more by visiting the <a href="%s" target="_blank" title="Opens in New Window">developer's guide for Carbon Copy</a>', 'default' ), 'https://endurtech.com/carbon-copy-wordpress-plugin/#clone_post_link'); ?></span><br />
<br />
<label>
<input type="checkbox" name="carbon_copy_show_row" value="1" <?php if( get_option( 'carbon_copy_show_row' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Post list", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_show_submitbox" value="1" <?php if( get_option( 'carbon_copy_show_submitbox' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Edit screen", 'default' ); ?>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_show_adminbar" value="1" <?php if( get_option( 'carbon_copy_show_adminbar' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Admin bar", 'default' ); ?>
<span class="description">(<em><?php esc_html_e( "Works on Edit screen, check to use with Gutenberg enabled.", 'default' ); ?></em>)</span>
</label><br />
<?php
global $wp_version;
if( version_compare($wp_version, '4.7') >= 0 )
{
?>
<label>
<input type="checkbox" name="carbon_copy_show_bulkactions" value="1" <?php if( get_option( 'carbon_copy_show_bulkactions' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Bulk Actions", 'default' ); ?>
</label><br />
<?php
}
?>
<div style="padding:10px 0px;"></div>
<h3>Original Post Link</h3>
<label>
<input type="checkbox" name="carbon_copy_show_original_meta_box" value="1" <?php if( get_option( 'carbon_copy_show_original_meta_box' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "In a metabox on the Edit screen [Classic editor]", 'default' ); ?>
<span class="description">(<?php esc_html_e( "You will also be able to delete the reference to the original item with a checkbox.", 'default' ); ?>)</span>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_show_original_column" value="1" <?php if( get_option( 'carbon_copy_show_original_column' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "In a column in the Post list", 'default' ); ?>
<span class="description">(<?php esc_html_e( "You will also be able to delete the reference to the original item with a checkbox in Quick Edit.", 'default' ); ?>)</span>
</label><br />
<label>
<input type="checkbox" name="carbon_copy_show_original_in_post_states" value="1" <?php if( get_option( 'carbon_copy_show_original_in_post_states' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "After the title in the Post list", 'default' ); ?>
</label>
<div style="padding:10px 0px;"></div>
<p>Did <a href="https://wordpress.org/plugins/carbon-copy/" target="_blank" title="Opens New Window">this plugin</a> save you time? <a href="https://endurtech.com/give-thanks/" target="_blank" title="Opens New Window"><strong>Share your appreciation</strong></a> and support future improvements.</p>
<p><label>
<input type="checkbox" name="carbon_copy_cleaner" value="1" <?php if( get_option( 'carbon_copy_cleaner' ) == 1 ) echo 'checked="checked"'; ?> /><?php esc_html_e( "Remove Plugin Database Values Upon Deactivation", 'default' ); ?>
</label></p>
<p class="submit"><input type="submit" class="button-primary" value="<?php esc_html_e( 'Save Changes', 'default' ) ?>" /></p>
</form>
</div>
<?php
}
?>