ip-location-block-upload-capability

Posted on May 11, 2021

Overwrite the upload_files capability.

Description

When a user requests to upload some files, this plugin will verify his/her capability upload_files if you select “Verify capability and MIME type” as “Prevent malicious file uploading”. But some plugins and themes which support file uploading would tend to define their own capability, may be for the security reason.

In this case, you should overwrite the slug of capability according to the plugin or theme you are employing.

Parameters

  • Bool $capability
    Current user has the capability upload_files or not.

Use case

When a user has own role and capability (e.g. attach_files), overwrite the original one.

/**
 * Overwrite the `upload_files` capability.
 *
 * @param  Bool $capability `upload_files` capability of current user.
 * @return Bool TRUE if a user has right capability, FALSE if not.
 */
function my_upload_capability( $capability ) {
    if ( function_exists( 'wp_get_current_user' ) ) {
        $user = wp_get_current_user();
        if ( $user->has_cap( 'attach_files' ) ) {
            return TRUE;
        }
    }

    return $capability;
}
add_filter( 'ip-location-block-upload-capability', 'my_upload_capability' );
NOTE: When you select "mu-plugins" (ip-location-block-mu.php) as Validation timing , you should put your code snippet into drop-in.php in Geolocation API folder instead of functions.php. See My custom functions in “functions.php” doesn’t work. in FAQ for detail.

Since

0.3.0.4