author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Media management action handler. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** Load WordPress Administration Bootstrap */ |
|
10 |
require_once( dirname( __FILE__ ) . '/admin.php' ); |
|
11 |
||
12 |
$parent_file = 'upload.php'; |
|
13 |
$submenu_file = 'upload.php'; |
|
14 |
||
15 |
wp_reset_vars(array('action')); |
|
16 |
||
5 | 17 |
switch ( $action ) { |
0 | 18 |
case 'editattachment' : |
19 |
$attachment_id = (int) $_POST['attachment_id']; |
|
20 |
check_admin_referer('media-form'); |
|
21 |
||
22 |
if ( !current_user_can('edit_post', $attachment_id) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
wp_die ( __('Sorry, you are not allowed to edit this attachment.') ); |
0 | 24 |
|
25 |
$errors = media_upload_form_handler(); |
|
26 |
||
27 |
if ( empty($errors) ) { |
|
28 |
$location = 'media.php'; |
|
29 |
if ( $referer = wp_get_original_referer() ) { |
|
30 |
if ( false !== strpos($referer, 'upload.php') || ( url_to_postid($referer) == $attachment_id ) ) |
|
31 |
$location = $referer; |
|
32 |
} |
|
33 |
if ( false !== strpos($location, 'upload.php') ) { |
|
34 |
$location = remove_query_arg('message', $location); |
|
35 |
$location = add_query_arg('posted', $attachment_id, $location); |
|
36 |
} elseif ( false !== strpos($location, 'media.php') ) { |
|
37 |
$location = add_query_arg('message', 'updated', $location); |
|
38 |
} |
|
39 |
wp_redirect($location); |
|
40 |
exit; |
|
41 |
} |
|
42 |
||
5 | 43 |
// No break. |
0 | 44 |
case 'edit' : |
45 |
$title = __('Edit Media'); |
|
46 |
||
47 |
if ( empty($errors) ) |
|
48 |
$errors = null; |
|
49 |
||
50 |
if ( empty( $_GET['attachment_id'] ) ) { |
|
51 |
wp_redirect( admin_url('upload.php') ); |
|
52 |
exit(); |
|
53 |
} |
|
54 |
$att_id = (int) $_GET['attachment_id']; |
|
55 |
||
56 |
if ( !current_user_can('edit_post', $att_id) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
wp_die ( __('Sorry, you are not allowed to edit this attachment.') ); |
0 | 58 |
|
59 |
$att = get_post($att_id); |
|
60 |
||
61 |
if ( empty($att->ID) ) wp_die( __('You attempted to edit an attachment that doesn’t exist. Perhaps it was deleted?') ); |
|
62 |
if ( 'attachment' !== $att->post_type ) wp_die( __('You attempted to edit an item that isn’t an attachment. Please go back and try again.') ); |
|
63 |
if ( $att->post_status == 'trash' ) wp_die( __('You can’t edit this attachment because it is in the Trash. Please move it out of the Trash and try again.') ); |
|
64 |
||
65 |
add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2); |
|
66 |
||
67 |
wp_enqueue_script( 'wp-ajax-response' ); |
|
68 |
wp_enqueue_script('image-edit'); |
|
69 |
wp_enqueue_style('imgareaselect'); |
|
70 |
||
71 |
get_current_screen()->add_help_tab( array( |
|
72 |
'id' => 'overview', |
|
73 |
'title' => __('Overview'), |
|
74 |
'content' => |
|
75 |
'<p>' . __('This screen allows you to edit five fields for metadata in a file within the media library.') . '</p>' . |
|
76 |
'<p>' . __('For images only, you can click on Edit Image under the thumbnail to expand out an inline image editor with icons for cropping, rotating, or flipping the image as well as for undoing and redoing. The boxes on the right give you more options for scaling the image, for cropping it, and for cropping the thumbnail in a different way than you crop the original image. You can click on Help in those boxes to get more information.') . '</p>' . |
|
77 |
'<p>' . __('Note that you crop the image by clicking on it (the Crop icon is already selected) and dragging the cropping frame to select the desired part. Then click Save to retain the cropping.') . '</p>' . |
|
78 |
'<p>' . __('Remember to click Update Media to save metadata entered or changed.') . '</p>' |
|
79 |
) ); |
|
80 |
||
81 |
get_current_screen()->set_help_sidebar( |
|
82 |
'<p><strong>' . __('For more information:') . '</strong></p>' . |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
'<p>' . __('<a href="https://codex.wordpress.org/Media_Add_New_Screen#Edit_Media">Documentation on Edit Media</a>') . '</p>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>' |
0 | 85 |
); |
86 |
||
87 |
require( ABSPATH . 'wp-admin/admin-header.php' ); |
|
88 |
||
89 |
$parent_file = 'upload.php'; |
|
90 |
$message = ''; |
|
91 |
$class = ''; |
|
92 |
if ( isset($_GET['message']) ) { |
|
5 | 93 |
switch ( $_GET['message'] ) { |
94 |
case 'updated' : |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
$message = __('Media file updated.'); |
5 | 96 |
$class = 'updated'; |
97 |
break; |
|
98 |
} |
|
0 | 99 |
} |
100 |
if ( $message ) |
|
101 |
echo "<div id='message' class='$class'><p>$message</p></div>\n"; |
|
102 |
||
103 |
?> |
|
104 |
||
105 |
<div class="wrap"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
<h1 class="wp-heading-inline"><?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
echo esc_html( $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
?></h1> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
|
0 | 110 |
<?php |
111 |
if ( current_user_can( 'upload_files' ) ) { ?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
<a href="media-new.php" class="page-title-action"><?php echo esc_html_x('Add New', 'file'); ?></a> |
0 | 113 |
<?php } ?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
<hr class="wp-header-end"> |
0 | 116 |
|
5 | 117 |
<form method="post" class="media-upload-form" id="media-single-form"> |
0 | 118 |
<p class="submit" style="padding-bottom: 0;"> |
119 |
<?php submit_button( __( 'Update Media' ), 'primary', 'save', false ); ?> |
|
120 |
</p> |
|
121 |
||
122 |
<div class="media-single"> |
|
5 | 123 |
<div id="media-item-<?php echo $att_id; ?>" class="media-item"> |
0 | 124 |
<?php echo get_media_item( $att_id, array( 'toggle' => false, 'send' => false, 'delete' => false, 'show_title' => false, 'errors' => !empty($errors[$att_id]) ? $errors[$att_id] : null ) ); ?> |
125 |
</div> |
|
126 |
</div> |
|
127 |
||
128 |
<?php submit_button( __( 'Update Media' ), 'primary', 'save' ); ?> |
|
129 |
<input type="hidden" name="post_id" id="post_id" value="<?php echo isset($post_id) ? esc_attr($post_id) : ''; ?>" /> |
|
130 |
<input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr($att_id); ?>" /> |
|
131 |
<input type="hidden" name="action" value="editattachment" /> |
|
132 |
<?php wp_original_referer_field(true, 'previous'); ?> |
|
133 |
<?php wp_nonce_field('media-form'); ?> |
|
134 |
||
135 |
</form> |
|
136 |
||
137 |
</div> |
|
138 |
||
139 |
<?php |
|
140 |
||
141 |
require( ABSPATH . 'wp-admin/admin-footer.php' ); |
|
142 |
||
143 |
exit; |
|
144 |
||
145 |
default: |
|
146 |
wp_redirect( admin_url('upload.php') ); |
|
147 |
exit; |
|
148 |
||
5 | 149 |
} |