author | ymh <ymh.work@gmail.com> |
Tue, 15 Oct 2019 15:48:13 +0200 | |
changeset 13 | d255fe9cd479 |
parent 9 | 177826044cd9 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Manage media uploaded file. |
|
4 |
* |
|
5 |
* There are many filters in here for media. Plugins can extend functionality |
|
6 |
* by hooking into the filters. |
|
7 |
* |
|
8 |
* @package WordPress |
|
9 |
* @subpackage Administration |
|
10 |
*/ |
|
11 |
||
9 | 12 |
if ( ! isset( $_GET['inline'] ) ) { |
13 |
define( 'IFRAME_REQUEST', true ); |
|
14 |
} |
|
0 | 15 |
|
16 |
/** Load WordPress Administration Bootstrap */ |
|
17 |
require_once( dirname( __FILE__ ) . '/admin.php' ); |
|
18 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
if ( ! current_user_can( 'upload_files' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
wp_die( __( 'Sorry, you are not allowed to upload files.' ), 403 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
} |
0 | 22 |
|
9 | 23 |
wp_enqueue_script( 'plupload-handlers' ); |
24 |
wp_enqueue_script( 'image-edit' ); |
|
25 |
wp_enqueue_script( 'set-post-thumbnail' ); |
|
26 |
wp_enqueue_style( 'imgareaselect' ); |
|
0 | 27 |
wp_enqueue_script( 'media-gallery' ); |
28 |
||
9 | 29 |
@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); |
0 | 30 |
|
31 |
// IDs should be integers |
|
9 | 32 |
$ID = isset( $ID ) ? (int) $ID : 0; |
33 |
$post_id = isset( $post_id ) ? (int) $post_id : 0; |
|
0 | 34 |
|
5 | 35 |
// Require an ID for the edit screen. |
9 | 36 |
if ( isset( $action ) && $action == 'edit' && ! $ID ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
wp_die( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
'<h1>' . __( 'Something went wrong.' ) . '</h1>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
'<p>' . __( 'Invalid item ID.' ) . '</p>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
403 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
); |
5 | 42 |
} |
43 |
||
9 | 44 |
if ( ! empty( $_REQUEST['post_id'] ) && ! current_user_can( 'edit_post', $_REQUEST['post_id'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
wp_die( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
'<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
403 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
); |
5 | 50 |
} |
0 | 51 |
|
5 | 52 |
// Upload type: image, video, file, ..? |
9 | 53 |
if ( isset( $_GET['type'] ) ) { |
54 |
$type = strval( $_GET['type'] ); |
|
5 | 55 |
} else { |
56 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* Filters the default media upload type in the legacy (pre-3.5.0) media popup. |
5 | 58 |
* |
59 |
* @since 2.5.0 |
|
60 |
* |
|
61 |
* @param string $type The default media upload type. Possible values include |
|
62 |
* 'image', 'audio', 'video', 'file', etc. Default 'file'. |
|
63 |
*/ |
|
64 |
$type = apply_filters( 'media_upload_default_type', 'file' ); |
|
65 |
} |
|
0 | 66 |
|
5 | 67 |
// Tab: gallery, library, or type-specific. |
9 | 68 |
if ( isset( $_GET['tab'] ) ) { |
69 |
$tab = strval( $_GET['tab'] ); |
|
5 | 70 |
} else { |
71 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
* Filters the default tab in the legacy (pre-3.5.0) media popup. |
5 | 73 |
* |
74 |
* @since 2.5.0 |
|
75 |
* |
|
76 |
* @param string $type The default media popup tab. Default 'type' (From Computer). |
|
77 |
*/ |
|
78 |
$tab = apply_filters( 'media_upload_default_tab', 'type' ); |
|
79 |
} |
|
80 |
||
81 |
$body_id = 'media-upload'; |
|
0 | 82 |
|
5 | 83 |
// Let the action code decide how to handle the request. |
9 | 84 |
if ( $tab == 'type' || $tab == 'type_url' || ! array_key_exists( $tab, media_upload_tabs() ) ) { |
5 | 85 |
/** |
86 |
* Fires inside specific upload-type views in the legacy (pre-3.5.0) |
|
87 |
* media popup based on the current tab. |
|
88 |
* |
|
89 |
* The dynamic portion of the hook name, `$type`, refers to the specific |
|
90 |
* media upload type. Possible values include 'image', 'audio', 'video', |
|
91 |
* 'file', etc. |
|
92 |
* |
|
93 |
* The hook only fires if the current `$tab` is 'type' (From Computer), |
|
94 |
* 'type_url' (From URL), or, if the tab does not exist (i.e., has not |
|
95 |
* been registered via the {@see 'media_upload_tabs'} filter. |
|
96 |
* |
|
97 |
* @since 2.5.0 |
|
98 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
do_action( "media_upload_{$type}" ); |
5 | 100 |
} else { |
101 |
/** |
|
102 |
* Fires inside limited and specific upload-tab views in the legacy |
|
103 |
* (pre-3.5.0) media popup. |
|
104 |
* |
|
105 |
* The dynamic portion of the hook name, `$tab`, refers to the specific |
|
106 |
* media upload tab. Possible values include 'library' (Media Library), |
|
107 |
* or any custom tab registered via the {@see 'media_upload_tabs'} filter. |
|
108 |
* |
|
109 |
* @since 2.5.0 |
|
110 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
do_action( "media_upload_{$tab}" ); |
5 | 112 |
} |
0 | 113 |