WPDKUserRoles::getInstance PHP Method

getInstance() public static method

Create a singleton instance of WPDKUserRoles class
public static getInstance ( ) : WPDKUserRoles
return WPDKUserRoles
    public static function getInstance()
    {
        return self::init();
    }

Usage Example

Example #1
0
 /**
  * Gets an array of capabilities according to each user role. Each role will return its caps, which are then
  * added to the overall $capabilities array.
  *
  * Note that if no role has the capability, it technically no longer exists. Since this could be a problem with
  * folks accidentally deleting the default WordPress capabilities, the members_default_capabilities() will
  * return all the defaults.
  *
  *     [cap] = [cap, desc, owner]
  *
  * @brief Get all role capabilities
  *
  * @return array $capabilities All the capabilities of all the user roles.
  */
 public function roleCapabilities()
 {
     // Get WPDKUserRoles
     $wpdk_roles = WPDKUserRoles::getInstance();
     // Set up an empty capabilities array
     $capabilities = array();
     // Loop through each role object because we need to get the caps
     foreach ($wpdk_roles->role_objects as $key => $role) {
         // Roles without capabilities will cause an error, so we need to check if $role->capabilities is an array
         if (is_array($role->capabilities)) {
             // Loop through the role's capabilities and add them to the $capabilities array
             $exclude = self::oldLevels();
             foreach ($role->capabilities as $cap => $grant) {
                 if (!isset($exclude[$cap])) {
                     $capabilities[$cap] = isset($this->_extendedData[$cap]) ? $this->_extendedData[$cap] : array($cap, '', '');
                 }
             }
         }
     }
     // Sort the capabilities by name so they're easier to read when shown on the screen
     ksort($capabilities);
     // Return the capabilities array
     return $capabilities;
 }
All Usage Examples Of WPDKUserRoles::getInstance