-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload.php
27 lines (21 loc) · 997 Bytes
/
upload.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
<?php
add_filter('attachment_fields_to_edit', function ($fields, $post) {
if (realpath($_SERVER['SCRIPT_FILENAME']) === ABSPATH.'wp-admin/async-upload.php') {
$upload_default = get_option('dxw_members_only_upload_default');
$fields['dmo_add_to_list'] = [
'input' => 'html',
'label' => __('Add to whitelist', 'dxwmembersonly'),
'html' => '<input type="checkbox" name="attachments['.$post->ID.'][dmo_add_to_list]" '.($upload_default==='true'?'checked':'').'>',
];
}
return $fields;
}, 10, 2);
add_filter('attachment_fields_to_save', function ($post, $attachment) {
if (isset($attachment['dmo_add_to_list']) && $attachment['dmo_add_to_list']) {
$url = parse_url($attachment['url'], PHP_URL_PATH);
$list_content = get_option('dxw_members_only_list_content');
$list_content .= "\n" . $url;
update_option('dxw_members_only_list_content', $list_content);
}
return $post;
}, 10, 2);