Exemplo n.º 1
0
 function test_largo_get_user_list()
 {
     /**
      * With no arguments, `largo_get_user_list` should get a list of all authors for the current blog;
      */
     $result = largo_get_user_list();
     $ids = array_map(function ($user) {
         return $user->ID;
     }, $result);
     $this->assertEquals(count($ids), count($this->author_user_ids));
     // Make sure all of the ids in the list returned by `largo_get_user_list` are the same as
     // those in $this->author_user_ids
     $not_present = array();
     foreach ($ids as $id) {
         if (!in_array($id, $this->author_user_ids)) {
             $not_present[] = $id;
         }
     }
     $this->assertEmpty($not_present);
     unset($result);
     unset($ids);
     /**
      * When we specify a role, we should get back only users with that role.
      */
     $result = largo_get_user_list(array('roles' => array('contributor')));
     $ids = array_map(function ($user) {
         return $user->ID;
     }, $result);
     $this->assertEquals(count($ids), count($this->contributor_user_ids));
     // Make sure all of the ids in the list returned by `largo_get_user_list` are the same as
     // those in $this->contribut_user_ids
     $not_present = array();
     foreach ($ids as $id) {
         if (!in_array($id, $this->contributor_user_ids)) {
             $not_present[] = $id;
         }
     }
     $this->assertEmpty($not_present);
     unset($result);
     unset($ids);
     /**
      * When we specify multiple roles, we should get back a list of users with any of the roles specified.
      */
     $result = largo_get_user_list(array('roles' => array('contributor', 'author')));
     $ids = array_map(function ($user) {
         return $user->ID;
     }, $result);
     $this->assertEquals(count($ids), count($this->contributor_user_ids) + count($this->author_user_ids));
     // Make sure all of the ids in the list returned by `largo_get_user_list` are the same as
     // those in $this->contributor_user_ids and $this->author_user_ids
     $not_present = array();
     foreach ($ids as $id) {
         if (!in_array($id, $this->contributor_user_ids) && !in_array($id, $this->author_user_ids)) {
             $not_present[] = $id;
         }
     }
     $this->assertEmpty($not_present);
     unset($result);
     unset($ids);
 }
Exemplo n.º 2
0
/**
 * Shortcode version of `largo_render_user_list`
 *
 * @param $atts array The attributes of the shortcode.
 *
 * Example of possible attributes:
 *
 * 	[roster roles="author,contributor" include="292,12312" exclude="5002,2320" show_users_with_empty_desc="true"]
 *
 * @since 0.4
 */
function largo_render_staff_list_shortcode($atts = array())
{
    $options = array();
    $show_users_with_empty_desc = false;
    if (!empty($atts['show_users_with_empty_desc'])) {
        $show_users_with_empty_desc = $atts['show_users_with_empty_desc'] == 'false' ? false : true;
        unset($atts['show_users_with_empty_desc']);
    }
    if (!empty($atts['roles'])) {
        $roles = explode(',', $atts['roles']);
        $options['roles'] = array_map(function ($arg) {
            return trim($arg);
        }, $roles);
    }
    if (!empty($atts['exclude'])) {
        $exclude = explode(',', $atts['exclude']);
        $options['exclude'] = array_map(function ($arg) {
            return trim($arg);
        }, $exclude);
    }
    if (!empty($atts['include'])) {
        $exclude = explode(',', $atts['include']);
        $options['include'] = array_map(function ($arg) {
            return trim($arg);
        }, $exclude);
    }
    $defaults = array('roles' => array('author'));
    $args = array_merge($defaults, $options);
    largo_render_user_list(largo_get_user_list($args), $show_users_with_empty_desc);
}