Intelligently make media fields readonly when the user cannot update or do anything with them. props koopersmith, helenyhou, nacin. fixes #22613
git-svn-id: https://develop.svn.wordpress.org/trunk@23072 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c2f15bc83b
commit
92793b6ec2
@ -1290,6 +1290,8 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
|
||||
'description' => false,
|
||||
);
|
||||
|
||||
$user_can_edit = current_user_can( 'edit_post', $attachment_id );
|
||||
|
||||
$args = wp_parse_args( $args, $default_args );
|
||||
$args = apply_filters( 'get_media_item_args', $args );
|
||||
|
||||
@ -1314,6 +1316,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
|
||||
foreach ( $terms as $term )
|
||||
$values[] = $term->slug;
|
||||
$t['value'] = join(', ', $values);
|
||||
$t['taxonomy'] = true;
|
||||
|
||||
$form_fields[$taxonomy] = $t;
|
||||
}
|
||||
@ -1363,6 +1366,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$readonly = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : '';
|
||||
$required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
|
||||
$aria_required = $field['required'] ? " aria-required='true' " : '';
|
||||
$class = 'compat-field-' . $id;
|
||||
@ -1381,7 +1385,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
|
||||
}
|
||||
$item .= "<textarea id='$id_attr' name='$name' $aria_required>" . $field['value'] . '</textarea>';
|
||||
} else {
|
||||
$item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
|
||||
$item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly $aria_required />";
|
||||
}
|
||||
if ( !empty( $field['helps'] ) )
|
||||
$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
|
||||
|
@ -1543,6 +1543,10 @@
|
||||
multiple: options.multiple ? 'reset' : false,
|
||||
editable: true,
|
||||
|
||||
// If the user isn't allowed to edit fields,
|
||||
// can they still edit it locally?
|
||||
allowLocalEdits: true,
|
||||
|
||||
// Show the attachment display settings.
|
||||
displaySettings: true,
|
||||
// Update user settings when users adjust the
|
||||
@ -2840,6 +2844,9 @@
|
||||
options.can.save = !! options.nonces.update;
|
||||
}
|
||||
|
||||
if ( this.controller.state().get('allowLocalEdits') )
|
||||
options.allowLocalEdits = true;
|
||||
|
||||
this.views.detach();
|
||||
this.$el.html( this.template( options ) );
|
||||
|
||||
|
@ -1658,10 +1658,12 @@ function wp_print_media_templates() {
|
||||
<a class="check" href="#" title="<?php _e('Deselect'); ?>"><div class="media-modal-icon"></div></a>
|
||||
<# } #>
|
||||
</div>
|
||||
<# if ( data.describe ) { #>
|
||||
<#
|
||||
var maybeReadOnly = data.can.save || data.allowLocalEdits ? '' : 'readonly';
|
||||
if ( data.describe ) { #>
|
||||
<# if ( 'image' === data.type ) { #>
|
||||
<input type="text" value="{{ data.caption }}" class="describe" data-setting="caption"
|
||||
placeholder="<?php esc_attr_e('Describe this image…'); ?>" />
|
||||
placeholder="<?php esc_attr_e('Describe this image…'); ?>" {{ maybeReadOnly }} />
|
||||
<# } else { #>
|
||||
<input type="text" value="{{ data.title }}" class="describe" data-setting="title"
|
||||
<# if ( 'video' === data.type ) { #>
|
||||
@ -1670,7 +1672,7 @@ function wp_print_media_templates() {
|
||||
placeholder="<?php esc_attr_e('Describe this audio file…'); ?>"
|
||||
<# } else { #>
|
||||
placeholder="<?php esc_attr_e('Describe this media file…'); ?>"
|
||||
<# } #> />
|
||||
<# } #> {{ maybeReadOnly }} />
|
||||
<# } #>
|
||||
<# } #>
|
||||
</script>
|
||||
@ -1713,25 +1715,27 @@ function wp_print_media_templates() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<# if ( 'image' === data.type ) { #>
|
||||
<#
|
||||
var maybeReadOnly = data.can.save || data.allowLocalEdits ? '' : 'readonly';
|
||||
if ( 'image' === data.type ) { #>
|
||||
<label class="setting" data-setting="title">
|
||||
<span><?php _e('Title'); ?></span>
|
||||
<input type="text" value="{{ data.title }}" />
|
||||
<input type="text" value="{{ data.title }}" {{ maybeReadOnly }} />
|
||||
</label>
|
||||
<label class="setting" data-setting="caption">
|
||||
<span><?php _e('Caption'); ?></span>
|
||||
<textarea
|
||||
<textarea {{ maybeReadOnly }}
|
||||
placeholder="<?php esc_attr_e('Describe this image…'); ?>"
|
||||
>{{ data.caption }}</textarea>
|
||||
</label>
|
||||
<label class="setting" data-setting="alt">
|
||||
<span><?php _e('Alt Text'); ?></span>
|
||||
<input type="text" value="{{ data.alt }}" />
|
||||
<input type="text" value="{{ data.alt }}" {{ maybeReadOnly }} />
|
||||
</label>
|
||||
<# } else { #>
|
||||
<label class="setting" data-setting="title">
|
||||
<span><?php _e('Title'); ?></span>
|
||||
<input type="text" value="{{ data.title }}"
|
||||
<input type="text" value="{{ data.title }}" {{ maybeReadOnly }}
|
||||
<# if ( 'video' === data.type ) { #>
|
||||
placeholder="<?php esc_attr_e('Describe this video…'); ?>"
|
||||
<# } else if ( 'audio' === data.type ) { #>
|
||||
|
Loading…
Reference in New Issue
Block a user