| Server IP : 43.130.17.34 / Your IP : 216.73.217.6 Web Server : nginx/1.28.0 System : Linux VM-4-12-opencloudos 6.6.92-34.1.oc9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 25 21:32:13 CST 2025 x86_64 User : www ( 1000) PHP Version : 8.0.26 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/yespkg.com/wp-content/plugins/admin-columns-pro.5.1.3/admin-columns/classes/ |
Upload File : |
<?php
namespace AC;
/**
* Holds the groups to which columns can belong.
*/
final class Groups {
const SORT_PRIORITY = 1;
const SORT_SLUG = 2;
const SORT_LABEL = 3;
/**
* @var array
*/
private $groups = [];
/**
* @return array
*/
public function get_groups() {
return $this->groups;
}
/**
* Return the registered groups sorted by either label, slug or priority
*
* @param int $sort_by Default is self::SORT_PRIORITY
*
* @return array
*/
public function get_groups_sorted( $sort_by = null ) {
switch ( $sort_by ) {
case self::SORT_LABEL :
$sorted = $this->sort_groups_by_string( $this->get_groups(), 'label' );
break;
case self::SORT_SLUG :
$sorted = $this->sort_groups_by_string( $this->get_groups(), 'slug' );
break;
default :
$sorted = $this->sort_groups_by_priority( $this->get_groups() );
}
return $sorted;
}
/**
* Sort the group by priority
* If there are more groups with the same priority it will those groups by label
*
* @param $groups
*
* @return array
*/
private function sort_groups_by_priority( array $groups ) {
$aggregated = $sorted = [];
foreach ( $groups as $group ) {
$aggregated[ $group['priority'] ][] = $group;
}
ksort( $aggregated, SORT_NUMERIC );
foreach ( $aggregated as $priority => $_groups ) {
$sorted = array_merge( $sorted, $this->sort_groups_by_string( $_groups, 'label' ) );
}
return $sorted;
}
/**
* Sort the group by label or slug
*
* @param array $groups
* @param string $key
*
* @return array
*/
private function sort_groups_by_string( array $groups, $key ) {
$sorted = [];
foreach ( $groups as $k => $group ) {
$sorted[ $k ] = $group[ $key ];
}
natcasesort( $sorted );
foreach ( array_keys( $sorted ) as $k ) {
$sorted[ $k ] = $groups[ $k ];
}
return $sorted;
}
/**
* @param string $slug
*
* @return bool|mixed
*/
public function get_group( $slug ) {
if ( ! $this->has_group( $slug ) ) {
return false;
}
return $this->groups[ $slug ];
}
public function get_group_label( $slug ) {
$group = $this->get_group( $slug );
return $group ? $group['label'] : false;
}
/**
* @param string $slug
*
* @return bool
*/
public function has_group( $slug ) {
return isset( $this->groups[ $slug ] );
}
/**
* Register a (column) group
*
* @param string $slug
* @param string $label Should be translatable
* @param int $priority
*
* @return bool
*/
public function register_group( $slug, $label, $priority = 10 ) {
if ( $this->has_group( $slug ) ) {
return false;
}
$this->groups[ $slug ] = [
'slug' => $slug,
'label' => $label,
'priority' => $priority,
];
return true;
}
}