Skip to content

Commit

Permalink
Add a filter around the return value from our current_user_can_upload…
Browse files Browse the repository at this point in the history
…_svg method, allowing others to modify which users can or can not upload
  • Loading branch information
dkotter committed Apr 17, 2024
1 parent 55772cf commit dc116d8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions safe-svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,24 @@ public function __construct() {
*/
public function current_user_can_upload_svg() {
$upload_roles = get_option( 'safe_svg_upload_roles', [] );
$can_upload = false;

// Fallback to upload_files check for backwards compatibility.
if ( empty( $upload_roles ) ) {
return current_user_can( 'upload_files' );
// Fallback to upload_files check for backwards compatibility.
$can_upload = current_user_can( 'upload_files' );
} else {
// Use our custom capability if some upload roles are set.
$can_upload = current_user_can( 'safe_svg_upload_svg' );
}

return current_user_can( 'safe_svg_upload_svg' );
/**
* Determine if the current user can upload an svg.
*
* @param bool $can_upload Can the current user upload an svg?
*
* @return bool
*/
return (bool) apply_filters( 'safe_svg_current_user_can_upload', $can_upload );
}

/**
Expand Down

0 comments on commit dc116d8

Please sign in to comment.