MultiSite.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Helper\Select\Group\CustomField; |
| 4 | |
| 5 | use AC\Helper\Select\Formatter; |
| 6 | use AC\Helper\Select\Group; |
| 7 | use AC\Helper\Select\Option; |
| 8 | |
| 9 | class MultiSite extends Group { |
| 10 | |
| 11 | /** |
| 12 | * @var array $groups |
| 13 | */ |
| 14 | private $groups; |
| 15 | |
| 16 | public function __construct( Formatter $formatter ) { |
| 17 | $this->groups = $this->get_groups(); |
| 18 | |
| 19 | parent::__construct( $formatter ); |
| 20 | } |
| 21 | |
| 22 | private function get_groups() { |
| 23 | global $wpdb; |
| 24 | |
| 25 | $groups = []; |
| 26 | |
| 27 | foreach ( get_sites() as $site ) { |
| 28 | $label = __( 'Network Site:', 'codepress-admin-columns' ) . ' ' . ac_helper()->network->get_site_option( $site->blog_id, 'blogname' ); |
| 29 | |
| 30 | if ( get_current_blog_id() == $site->blog_id ) { |
| 31 | $label .= ' (' . __( 'current', 'codepress-admin-columns' ) . ')'; |
| 32 | } |
| 33 | |
| 34 | $groups[ $wpdb->get_blog_prefix( $site->blog_id ) ] = $label; |
| 35 | } |
| 36 | |
| 37 | return array_reverse( $groups ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @param $entity |
| 42 | * @param Option $option |
| 43 | * |
| 44 | * @return string |
| 45 | */ |
| 46 | public function get_label( $entity, Option $option ) { |
| 47 | foreach ( $this->groups as $key => $label ) { |
| 48 | if ( strpos( $entity, $key ) === 0 ) { |
| 49 | return $label; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return __( 'Default', 'codepress-admin-columns' ); |
| 54 | } |
| 55 | |
| 56 | } |