diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 94a1f5cd7e..e584b634e6 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -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'] ? '*' : ''; $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 .= "'; } else { - $item .= ""; + $item .= ""; } if ( !empty( $field['helps'] ) ) $item .= "

" . join( "

\n

", array_unique( (array) $field['helps'] ) ) . '

'; diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index ad5938a181..f167b5b647 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -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 ) ); diff --git a/wp-includes/media.php b/wp-includes/media.php index 17ed7533d3..8b6bbcf07c 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1658,10 +1658,12 @@ function wp_print_media_templates() {
<# } #> - <# if ( data.describe ) { #> + <# + var maybeReadOnly = data.can.save || data.allowLocalEdits ? '' : 'readonly'; + if ( data.describe ) { #> <# if ( 'image' === data.type ) { #> + placeholder="" {{ maybeReadOnly }} /> <# } else { #> @@ -1670,7 +1672,7 @@ function wp_print_media_templates() { placeholder="" <# } else { #> placeholder="" - <# } #> /> + <# } #> {{ maybeReadOnly }} /> <# } #> <# } #> @@ -1713,25 +1715,27 @@ function wp_print_media_templates() { - <# if ( 'image' === data.type ) { #> + <# + var maybeReadOnly = data.can.save || data.allowLocalEdits ? '' : 'readonly'; + if ( 'image' === data.type ) { #> <# } else { #>