Skip to content

Commit

Permalink
Some upload/alt tag fixes.
Browse files Browse the repository at this point in the history
* Ensure that non-admins can upload and edit images.
* Don't double-add alt tag notice.

See #107, #118.
  • Loading branch information
boonebgorges committed May 4, 2018
1 parent c4f129a commit bf13d5c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40054,7 +40054,9 @@ const mapDispatchToProps = (dispatch, ownProps) => {
frame.reset();
} else {
const warning = '<p id="alt-tag-warning" class="alt-tag-warning">You must supply alt text before inserting this image.</p>';
toolbarView.$el.find('#alt-tag-warning').remove();
toolbarView.$el.find('.media-toolbar-primary').append(warning);
console.log(sidebar);
sidebar.$el.find('label.setting[data-setting="alt"]').addClass('has-error');
}
});
Expand Down
2 changes: 1 addition & 1 deletion build/index.js.map

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion classes/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function enqueue_redirector_script() {
* @return array $caps
*/
public static function map_meta_cap( $caps, $cap, $user_id, $args ) {
if ( 'upload_files' !== $cap ) {
if ( 'upload_files' !== $cap && 'edit_post' !== $cap ) {
return $caps;
}

Expand All @@ -353,6 +353,22 @@ public static function map_meta_cap( $caps, $cap, $user_id, $args ) {
return $caps;
}

$can = false;
switch ( $cap ) {
case 'upload_files' :
$can = true;
break;

case 'edit_post' :
$post = get_post( $args[0] );
$can = $post && $user_id === $post->post_author;
break;
}

if ( $can ) {
$caps = array( 'exist' );
}

// @todo Better filtering?
return array( 'exist' );
}
Expand Down
2 changes: 2 additions & 0 deletions src/containers/UploaderContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ const mapDispatchToProps = (dispatch, ownProps) => {
frame.reset()
} else {
const warning = '<p id="alt-tag-warning" class="alt-tag-warning">You must supply alt text before inserting this image.</p>'
toolbarView.$el.find('#alt-tag-warning').remove()
toolbarView.$el.find('.media-toolbar-primary').append(warning)
console.log(sidebar);
sidebar.$el.find('label.setting[data-setting="alt"]').addClass('has-error')
}
})
Expand Down

0 comments on commit bf13d5c

Please sign in to comment.