PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 4.3.2
Admin Columns v4.3.2
7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Settings / Column / Meta.php
codepress-admin-columns / classes / Settings / Column Last commit date
BeforeAfter 5 years ago Pro 5 years ago ActionIcons.php 5 years ago AttachmentDisplay.php 5 years ago BeforeAfter.php 5 years ago CharacterLimit.php 5 years ago Comment.php 5 years ago CommentCount.php 5 years ago CommentLink.php 5 years ago CustomField.php 5 years ago CustomFieldType.php 5 years ago Date.php 5 years ago DateTimeFormat.php 5 years ago ExifData.php 5 years ago Image.php 5 years ago Images.php 5 years ago Label.php 5 years ago LinkLabel.php 5 years ago LinkToMenu.php 5 years ago MediaLink.php 5 years ago Message.php 5 years ago Meta.php 5 years ago MissingImageSize.php 5 years ago NumberFormat.php 5 years ago NumberOfItems.php 5 years ago Password.php 5 years ago PathScope.php 5 years ago Post.php 5 years ago PostFormatIcon.php 5 years ago PostLink.php 5 years ago PostStatus.php 5 years ago PostType.php 5 years ago Pro.php 5 years ago Separator.php 5 years ago StatusIcon.php 5 years ago StringLimit.php 5 years ago Taxonomy.php 5 years ago Term.php 5 years ago TermLink.php 5 years ago Time.php 5 years ago Toggle.php 5 years ago Type.php 5 years ago User.php 5 years ago UserLink.php 5 years ago Width.php 5 years ago WordLimit.php 5 years ago WordsPerMinute.php 5 years ago
Meta.php
211 lines
1 <?php
2
3 namespace AC\Settings\Column;
4
5 use AC\Form\Element\Select;
6 use AC\MetaType;
7 use AC\Settings\Column;
8 use AC\View;
9
10 abstract class Meta extends Column {
11
12 /**
13 * @var string
14 */
15 private $field;
16
17 abstract protected function get_meta_keys();
18
19 protected function define_options() {
20 return [ 'field' ];
21 }
22
23 /**
24 * @return Select
25 */
26 protected function get_setting_field() {
27 $setting = $this
28 ->create_element( 'select', 'field' )
29 ->set_options( $this->group_keys( $this->get_cached_keys() ) )
30 ->set_no_result( __( 'No fields available.', 'codepress-admin-columns' ) );
31
32 return $setting;
33 }
34
35 /**
36 * @return array|false
37 */
38 protected function get_cached_keys() {
39 $keys = $this->get_cache();
40
41 if ( ! $keys ) {
42 $keys = $this->get_meta_keys();
43
44 $this->set_cache( $keys );
45 }
46
47 return $keys;
48 }
49
50 /**
51 * @return string
52 */
53 protected function get_cache_key() {
54 return $this->column->get_list_screen()->get_storage_key();
55 }
56
57 /**
58 * @return string
59 */
60 protected function get_meta_type() {
61 return $this->column->get_list_screen()->get_meta_type();
62 }
63
64 protected function get_cache_group() {
65 return 'ac_settings_meta';
66 }
67
68 /**
69 * @return View
70 */
71 public function create_view() {
72 $view = new View( [
73 'label' => __( 'Field', 'codepress-admin-columns' ),
74 'setting' => $this->get_setting_field(),
75 ] );
76
77 return $view;
78 }
79
80 /**
81 * @return string
82 */
83 public function get_field() {
84 return $this->field;
85 }
86
87 /**
88 * @param string $field
89 *
90 * @return bool
91 */
92 public function set_field( $field ) {
93 $this->field = $field;
94
95 return true;
96 }
97
98 private function get_cache() {
99 return wp_cache_get( $this->get_cache_key(), $this->get_cache_group() );
100 }
101
102 /**
103 * @param array $data
104 * @param int $expire Seconds
105 */
106 private function set_cache( $data, $expire = 15 ) {
107 wp_cache_add( $this->get_cache_key(), $data, $this->get_cache_group(), $expire );
108 }
109
110 /**
111 * @return array
112 */
113 protected function get_meta_groups() {
114 global $wpdb;
115
116 $groups = [
117 '' => __( 'Public', 'codepress-admin-columns' ),
118 '_' => __( 'Hidden', 'codepress-admin-columns' ),
119 ];
120
121 // User only
122 if ( MetaType::USER === $this->get_meta_type() ) {
123
124 if ( is_multisite() ) {
125 foreach ( get_sites() as $site ) {
126 $label = __( 'Network Site:', 'codepress-admin-columns' ) . ' ' . ac_helper()->network->get_site_option( $site->blog_id, 'blogname' );
127
128 if ( get_current_blog_id() == $site->blog_id ) {
129 $label .= ' (' . __( 'current', 'codepress-admin-columns' ) . ')';
130 }
131
132 $groups[ $wpdb->get_blog_prefix( $site->blog_id ) ] = $label;
133 }
134 } else {
135 $groups[ $wpdb->get_blog_prefix() ] = __( 'Site Options', 'codepress-admin-columns' );
136 }
137 }
138
139 return $groups;
140 }
141
142 /**
143 * @param array $keys
144 *
145 * @return array
146 */
147 private function group_keys( $keys ) {
148 if ( ! $keys ) {
149 return [];
150 }
151
152 $grouped = [];
153
154 $groups = $this->get_meta_groups();
155
156 // groups are ordered desc because the prefixes without a blog id ( e.g. wp_ ) should be matched last.
157 krsort( $groups );
158
159 foreach ( $groups as $prefix => $title ) {
160
161 $options = [];
162
163 foreach ( $keys as $k => $key ) {
164
165 // Match prefix with meta key
166 if ( $prefix && 0 === strpos( $key, $prefix ) ) {
167 $options[ $key ] = $key;
168
169 unset( $keys[ $k ] );
170 }
171 }
172
173 if ( $options ) {
174 $grouped[ $prefix ] = [
175 'title' => $title,
176 'options' => $options,
177 ];
178 }
179 }
180
181 ksort( $grouped );
182
183 // Default group
184 if ( $keys ) {
185 $default = [
186 'title' => $groups[''],
187 'options' => array_combine( $keys, $keys ),
188 ];
189
190 array_unshift( $grouped, $default );
191 }
192
193 // Place the hidden group at the end
194 if ( isset( $grouped['_'] ) ) {
195 $grouped[] = $grouped['_'];
196
197 unset( $grouped['_'] );
198 }
199
200 // Remove groups when there is only one group
201 if ( 1 === count( $grouped ) ) {
202 $grouped = array_pop( $grouped );
203
204 $grouped = $grouped['options'];
205 }
206
207 return $grouped;
208 }
209
210 }
211