Created
January 26, 2017 15:14
-
-
Save mdcpepper/3a3effaca580acd6d19c5a0eb72f144a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Craft; | |
class UserCountsPlugin extends BasePlugin | |
{ | |
public function getName() | |
{ | |
return Craft::t('User Counts'); | |
} | |
public function getVersion() | |
{ | |
return '0.1.0'; | |
} | |
public function getDeveloper() | |
{ | |
return 'Mike Pepper'; | |
} | |
public function getDeveloperUrl() | |
{ | |
return 'https://www.twitter.com/mdcpepper'; | |
} | |
public function modifyUserSources(&$sources, $context) | |
{ | |
if ($context == 'index') | |
{ | |
foreach ($sources as &$source) | |
{ | |
if (array_key_exists('heading', $source)) | |
{ | |
continue; | |
} | |
$criteria = array_merge( | |
(isset($source['criteria']) ? $source['criteria'] : array()), | |
array('limit' => null, 'status' => null) | |
); | |
$total = craft()->elements->getCriteria(ElementType::User, $criteria)->total(); | |
$source['label'] .= " ({$total})"; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated for Craft 3...