Fatal error: Call to a member function add_cap() on a non-object

I’am developing WordPress theme and I can’t figured it out why I can’t add new custom capabilities for existing custom role without using any plugins for user

//Function for creating new custom capability


function map_custom_cap($roles = array()){

    foreach ( $roles as $role => $cap ) {

        $role->add_cap($cap);

    }
}

//This capabilities are not yet existing

        $reviewer_cap = array( 'read', 'edit_posts', 'delete_posts');

        $movie_author_cap = array( 'read_movie', 'edit_movies', 'delete_movies');

        $roles = array(
            'reviewer' => $reviewer_cap,
            'movie_author' => $movie_author_cap
        );

map_custom_cap($roles);

Related posts

Leave a Reply