How to restrict access to Import Entries

Screenshot of the Import/Export page of Gravity Forms

It's easy to give access to a custom user role to import entries by adding some capabilities to that role. But if you want to restrict access to the Import Entries tab in the Import/Export page of Gravity Forms, then you'll need to use the code snippet below.

/**
 * Remove the ability of a user to import entries based on their role.
 *
 * @param array $caps Array of capabilities required to display the UI.
 *
 * @return array
 */
add_filter( 'gravityview/import/capabilities', function ( $caps ) {

    // REPLACE THIS with the role you want to exclude from importing entries.
    $role = 'editor';

    $user = wp_get_current_user();

    if ( ! $user || ! $user->exists() ) {
        return [];
    }

    if ( in_array( $role, $user->roles, true ) ) {
        return [];
    }

    return $caps;
} );

See how to add this code snippet to your website: Where to put code samples.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us