get_upload_capable_roles(); $valid_slugs = array_keys( $valid_roles ); $roles = array_intersect( $valid_slugs, $roles ); // Store a non empty/falsy value for easier handling. if ( empty( $roles ) ) { $roles = 'none'; } return $roles; } /** * Get roles with upload capabilities. * * @return array An array of roles with the upload_files capability. */ public function get_upload_capable_roles() { $all_roles = get_editable_roles(); $upload_roles = array_filter( $all_roles, function( $_role ) { return $_role['capabilities']['upload_files'] ?? false; } ); /** * Filter the roles that can upload SVG files. * * @since 2.2.0 * * @param array $upload_roles The roles that can upload SVG files. * @param array $all_roles All editable roles on the site. * @param safe_svg_settings $this The safe_svg_settings instance. */ return apply_filters( 'safe_svg_upload_roles', $upload_roles, $all_roles, $this ); } /** * Settings section callback function. * * @param array $args The settings array, defining title, id, callback. */ public function safe_svg_settings_callback( $args ) { ?>

get_upload_capable_roles(); if ( empty( $upload_roles ) ) { $upload_roles = array_keys( $role_options ); } foreach ( $role_options as $role => $info ) : ?>
add_cap( 'safe_svg_upload_svg' ); } } } if ( ! empty( $remove_roles ) ) { foreach ( $remove_roles as $role ) { $role = get_role( $role ); if ( $role instanceof \WP_Role ) { $role->remove_cap( 'safe_svg_upload_svg' ); } } } return $new_roles; } }