Jetpack::get_other_linked_admins PHP Method

get_other_linked_admins() static public method

Checks to see if there are any other users available to become primary Users must both: - Be linked to wpcom - Be an admin
static public get_other_linked_admins ( ) : mixed
return mixed False if no other users are linked, Int if there are.
    static function get_other_linked_admins()
    {
        $other_linked_users = get_transient('jetpack_other_linked_admins');
        if (false === $other_linked_users) {
            $admins = get_users(array('role' => 'administrator'));
            if (count($admins) > 1) {
                $available = array();
                foreach ($admins as $admin) {
                    if (Jetpack::is_user_connected($admin->ID)) {
                        $available[] = $admin->ID;
                    }
                }
                $count_connected_admins = count($available);
                if (count($available) > 1) {
                    $other_linked_users = $count_connected_admins;
                } else {
                    $other_linked_users = 0;
                }
            } else {
                $other_linked_users = 0;
            }
            set_transient('jetpack_other_linked_admins', $other_linked_users, HOUR_IN_SECONDS);
        }
        return 0 === $other_linked_users ? false : $other_linked_users;
    }

Usage Example

コード例 #1
0
 function test_other_linked_admins_transient_set_to_zero_returns_false()
 {
     set_transient('jetpack_other_linked_admins', 0, HOUR_IN_SECONDS);
     $this->assertFalse(Jetpack::get_other_linked_admins());
 }
Jetpack