restrict event creation to admin only

how do i limit the creation of events to certain user levels so regular users (contributors) cannot create events?

  • Ash

    Hello @Ohad

    Welcome to WPMU community!

    I hope you are well today and thanks for asking the question.

    Please try to add the following code:

    add_filter( 'eab_post_type_register', 'eab_post_type_register_cb', 99, 1 );
    function eab_post_type_register_cb( $event_type_args ){
        $event_type_args['capabilities'] = array(
            'edit_post'          => 'update_core',
            'read_post'          => 'update_core',
            'delete_post'        => 'update_core',
            'edit_posts'         => 'update_core',
            'edit_others_posts'  => 'update_core',
            'publish_posts'      => 'update_core',
            'read_private_posts' => 'update_core'
        );
        return $event_type_args;
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Let us know if it works for you.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.