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