title: Fatal error: Call to a member function add_cap() on a non-object
body: <p>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</p>
  
  <pre><code>//Function for creating new custom capability
  
  
  function map_custom_cap($roles = array()){
  
      foreach ( $roles as $role =&gt; $cap ) {
  
          $role-&gt;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' =&gt; $reviewer_cap,
              'movie_author' =&gt; $movie_author_cap
          );
  
  map_custom_cap($roles);
  </code></pre>