wp/wp-admin/media-new.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    11 
    11 
    12 /** Load WordPress Administration Bootstrap */
    12 /** Load WordPress Administration Bootstrap */
    13 require_once( dirname( __FILE__ ) . '/admin.php' );
    13 require_once( dirname( __FILE__ ) . '/admin.php' );
    14 
    14 
    15 if (!current_user_can('upload_files'))
    15 if (!current_user_can('upload_files'))
    16 	wp_die(__('You do not have permission to upload files.'));
    16 	wp_die(__('Sorry, you are not allowed to upload files.'));
    17 
    17 
    18 wp_enqueue_script('plupload-handlers');
    18 wp_enqueue_script('plupload-handlers');
    19 
    19 
    20 $post_id = 0;
    20 $post_id = 0;
    21 if ( isset( $_REQUEST['post_id'] ) ) {
    21 if ( isset( $_REQUEST['post_id'] ) ) {
    23 	if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) )
    23 	if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) )
    24 		$post_id = 0;
    24 		$post_id = 0;
    25 }
    25 }
    26 
    26 
    27 if ( $_POST ) {
    27 if ( $_POST ) {
    28 	$location = 'upload.php';
       
    29 	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
    28 	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
    30 		check_admin_referer('media-form');
    29 		check_admin_referer('media-form');
    31 		// Upload File button was clicked
    30 		// Upload File button was clicked
    32 		$id = media_handle_upload( 'async-upload', $post_id );
    31 		$upload_id = media_handle_upload( 'async-upload', $post_id );
    33 		if ( is_wp_error( $id ) )
    32 		if ( is_wp_error( $upload_id ) ) {
    34 			$location .= '?message=3';
    33 			wp_die( $upload_id );
       
    34 		}
    35 	}
    35 	}
    36 	wp_redirect( admin_url( $location ) );
    36 	wp_redirect( admin_url( 'upload.php' ) );
    37 	exit;
    37 	exit;
    38 }
    38 }
    39 
    39 
    40 $title = __('Upload New Media');
    40 $title = __('Upload New Media');
    41 $parent_file = 'upload.php';
    41 $parent_file = 'upload.php';
    51 		'<li>' . __('Revert to the <strong>Browser Uploader</strong> by clicking the link below the drag and drop box.') . '</li>' .
    51 		'<li>' . __('Revert to the <strong>Browser Uploader</strong> by clicking the link below the drag and drop box.') . '</li>' .
    52 	'</ul>'
    52 	'</ul>'
    53 ) );
    53 ) );
    54 get_current_screen()->set_help_sidebar(
    54 get_current_screen()->set_help_sidebar(
    55 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    55 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    56 	'<p>' . __('<a href="https://codex.wordpress.org/Media_Add_New_Screen" target="_blank">Documentation on Uploading Media Files</a>') . '</p>' .
    56 	'<p>' . __('<a href="https://codex.wordpress.org/Media_Add_New_Screen">Documentation on Uploading Media Files</a>') . '</p>' .
    57 	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    57 	'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
    58 );
    58 );
    59 
    59 
    60 require_once( ABSPATH . 'wp-admin/admin-header.php' );
    60 require_once( ABSPATH . 'wp-admin/admin-header.php' );
    61 
    61 
    62 $form_class = 'media-upload-form type-form validate';
    62 $form_class = 'media-upload-form type-form validate';
    63 
    63 
    64 if ( get_user_setting('uploader') || isset( $_GET['browser-uploader'] ) )
    64 if ( get_user_setting('uploader') || isset( $_GET['browser-uploader'] ) )
    65 	$form_class .= ' html-uploader';
    65 	$form_class .= ' html-uploader';
    66 ?>
    66 ?>
    67 <div class="wrap">
    67 <div class="wrap">
    68 	<h2><?php echo esc_html( $title ); ?></h2>
    68 	<h1><?php echo esc_html( $title ); ?></h1>
    69 
    69 
    70 	<form enctype="multipart/form-data" method="post" action="<?php echo admin_url('media-new.php'); ?>" class="<?php echo esc_attr( $form_class ); ?>" id="file-form">
    70 	<form enctype="multipart/form-data" method="post" action="<?php echo admin_url('media-new.php'); ?>" class="<?php echo esc_attr( $form_class ); ?>" id="file-form">
    71 
    71 
    72 	<?php media_upload_form(); ?>
    72 	<?php media_upload_form(); ?>
    73 
    73