wp/wp-admin/media.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 11:14:17 +0000
changeset 6 490d5cc509ed
parent 5 5e2f62d02dcd
child 7 cf61fcea0001
permissions -rw-r--r--
update portfolio
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Media management action handler.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/** Load WordPress Administration Bootstrap */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
require_once( dirname( __FILE__ ) . '/admin.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
$parent_file = 'upload.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
$submenu_file = 'upload.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
wp_reset_vars(array('action'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
switch ( $action ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
case 'editattachment' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
	$attachment_id = (int) $_POST['attachment_id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
	check_admin_referer('media-form');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	if ( !current_user_can('edit_post', $attachment_id) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
		wp_die ( __('You are not allowed to edit this attachment.') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
	$errors = media_upload_form_handler();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	if ( empty($errors) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		$location = 'media.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
		if ( $referer = wp_get_original_referer() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
			if ( false !== strpos($referer, 'upload.php') || ( url_to_postid($referer) == $attachment_id )  )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
				$location = $referer;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
		if ( false !== strpos($location, 'upload.php') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
			$location = remove_query_arg('message', $location);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
			$location = add_query_arg('posted',	$attachment_id, $location);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		} elseif ( false !== strpos($location, 'media.php') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
			$location = add_query_arg('message', 'updated', $location);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		wp_redirect($location);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
		exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
	// No break.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
case 'edit' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	$title = __('Edit Media');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	if ( empty($errors) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		$errors = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	if ( empty( $_GET['attachment_id'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
		wp_redirect( admin_url('upload.php') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
		exit();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	$att_id = (int) $_GET['attachment_id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	if ( !current_user_can('edit_post', $att_id) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
		wp_die ( __('You are not allowed to edit this attachment.') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	$att = get_post($att_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	if ( empty($att->ID) ) wp_die( __('You attempted to edit an attachment that doesn&#8217;t exist. Perhaps it was deleted?') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	if ( 'attachment' !== $att->post_type ) wp_die( __('You attempted to edit an item that isn&#8217;t an attachment. Please go back and try again.') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	if ( $att->post_status == 'trash' ) wp_die( __('You can&#8217;t edit this attachment because it is in the Trash. Please move it out of the Trash and try again.') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
	wp_enqueue_script( 'wp-ajax-response' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	wp_enqueue_script('image-edit');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	wp_enqueue_style('imgareaselect');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
		'id'      => 'overview',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
		'title'   => __('Overview'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		'content' =>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
			'<p>' . __('This screen allows you to edit five fields for metadata in a file within the media library.') . '</p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
			'<p>' . __('Remember to click Update Media to save metadata entered or changed.') . '</p>'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	get_current_screen()->set_help_sidebar(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	'<p><strong>' . __('For more information:') . '</strong></p>' .
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
	'<p>' . __('<a href="https://codex.wordpress.org/Media_Add_New_Screen#Edit_Media" target="_blank">Documentation on Edit Media</a>') . '</p>' .
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	require( ABSPATH . 'wp-admin/admin-header.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	$parent_file = 'upload.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	$message = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	$class = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	if ( isset($_GET['message']) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
		switch ( $_GET['message'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
			case 'updated' :
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
				$message = __('Media attachment updated.');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
				$class = 'updated';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
				break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	if ( $message )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
		echo "<div id='message' class='$class'><p>$message</p></div>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
<div class="wrap">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
<h2>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
echo esc_html( $title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
if ( current_user_can( 'upload_files' ) ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
	<a href="media-new.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'file'); ?></a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
</h2>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
<form method="post" class="media-upload-form" id="media-single-form">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
<p class="submit" style="padding-bottom: 0;">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
<?php submit_button( __( 'Update Media' ), 'primary', 'save', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
<div class="media-single">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
<div id="media-item-<?php echo $att_id; ?>" class="media-item">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
<?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 ) ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
<?php submit_button( __( 'Update Media' ), 'primary', 'save' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
<input type="hidden" name="post_id" id="post_id" value="<?php echo isset($post_id) ? esc_attr($post_id) : ''; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
<input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr($att_id); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
<input type="hidden" name="action" value="editattachment" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
<?php wp_original_referer_field(true, 'previous'); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
<?php wp_nonce_field('media-form'); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
	require( ABSPATH . 'wp-admin/admin-footer.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
	exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
default:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
	wp_redirect( admin_url('upload.php') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
	exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
}