2
2
3
3
/**
4
4
* MslsMetaBox
5
+ *
5
6
* @author Dennis Ploetner <re@lloc.de>
6
7
* @since 0.9.8
7
8
*/
12
13
13
14
/**
14
15
* Meta box for the edit mode of the (custom) post types
16
+ *
15
17
* @package Msls
16
18
*/
17
19
class MslsMetaBox extends MslsMain {
@@ -23,17 +25,17 @@ class MslsMetaBox extends MslsMain {
23
25
* the requested search-term and then die silently
24
26
*/
25
27
public static function suggest () {
26
- $ json = new MslsJson ;
28
+ $ json = new MslsJson () ;
27
29
28
30
if ( filter_has_var ( INPUT_POST , 'blog_id ' ) ) {
29
31
switch_to_blog (
30
32
filter_input ( INPUT_POST , 'blog_id ' , FILTER_SANITIZE_NUMBER_INT )
31
33
);
32
34
33
- $ args = [
34
- 'post_status ' => get_post_stati ( [ 'internal ' => '' ] ),
35
+ $ args = array (
36
+ 'post_status ' => get_post_stati ( array ( 'internal ' => '' ) ),
35
37
'posts_per_page ' => 10 ,
36
- ] ;
38
+ ) ;
37
39
38
40
if ( filter_has_var ( INPUT_POST , 'post_type ' ) ) {
39
41
$ args ['post_type ' ] = sanitize_text_field (
@@ -55,7 +57,7 @@ public static function suggest() {
55
57
56
58
/**
57
59
* @param MslsJson $json
58
- * @param array $args
60
+ * @param array $args
59
61
*
60
62
* @return mixed
61
63
*/
@@ -66,25 +68,21 @@ public static function get_suggested_fields( $json, $args ) {
66
68
* @param array $args
67
69
*
68
70
* @since 0.9.9
69
- *
70
71
*/
71
72
$ args = (array ) apply_filters ( 'msls_meta_box_suggest_args ' , $ args );
72
73
73
- $ my_query = new \WP_Query ( $ args );
74
- while ( $ my_query ->have_posts () ) {
75
- $ my_query ->the_post ();
76
-
74
+ $ posts = get_posts ( $ args );
75
+ foreach ( $ posts as $ post ) {
77
76
/**
78
77
* Manipulates the WP_Post object before using it
79
78
*
80
79
* @param \WP_Post $post
81
80
*
82
81
* @since 0.9.9
83
- *
84
82
*/
85
- $ my_query -> post = apply_filters ( 'msls_meta_box_suggest_post ' , $ my_query -> post );
86
- if ( is_object ( $ my_query -> post ) ) {
87
- $ json ->add ( get_the_ID () , get_the_title () );
83
+ $ post = apply_filters ( 'msls_meta_box_suggest_post ' , $ post );
84
+ if ( is_object ( $ post ) ) {
85
+ $ json ->add ( $ post -> ID , get_the_title ( $ post ) );
88
86
}
89
87
}
90
88
@@ -106,9 +104,9 @@ public static function init() {
106
104
$ obj = new static ( $ options , msls_blog_collection () );
107
105
108
106
if ( ! $ options ->is_excluded () ) {
109
- add_action ( 'add_meta_boxes ' , [ $ obj , 'add ' ] );
110
- add_action ( 'save_post ' , [ $ obj , 'set ' ] );
111
- add_action ( 'trashed_post ' , [ $ obj , 'delete ' ] );
107
+ add_action ( 'add_meta_boxes ' , array ( $ obj , 'add ' ) );
108
+ add_action ( 'save_post ' , array ( $ obj , 'set ' ) );
109
+ add_action ( 'trashed_post ' , array ( $ obj , 'delete ' ) );
112
110
}
113
111
114
112
return $ obj ;
@@ -125,14 +123,14 @@ public function add() {
125
123
'msls_metabox_post_select_title ' ,
126
124
__ ( 'Multisite Language Switcher ' , 'multisite-language-switcher ' )
127
125
),
128
- [
126
+ array (
129
127
$ this ,
130
128
(
131
129
msls_options ()->activate_autocomplete ?
132
130
'render_input ' :
133
131
'render_select '
134
132
),
135
- ] ,
133
+ ) ,
136
134
$ post_type ,
137
135
'side ' ,
138
136
'high '
@@ -145,21 +143,22 @@ public function add() {
145
143
'msls_metabox_post_import_title ' ,
146
144
__ ( 'Multisite Language Switcher - Import content ' , 'multisite-language-switcher ' )
147
145
),
148
- [
146
+ array (
149
147
ContentImportMetaBox::instance (),
150
148
'render ' ,
151
- ] ,
149
+ ) ,
152
150
$ post_type ,
153
151
'side ' ,
154
152
'high '
155
153
);
156
- add_action ( 'admin_footer ' , [ ContentImportMetaBox::instance (), 'print_modal_html ' ] );
154
+ add_action ( 'admin_footer ' , array ( ContentImportMetaBox::instance (), 'print_modal_html ' ) );
157
155
}
158
156
}
159
157
}
160
158
161
159
/**
162
160
* Render the classic select-box
161
+ *
163
162
* @uses selected
164
163
*/
165
164
public function render_select () {
@@ -183,7 +182,7 @@ public function render_select() {
183
182
184
183
$ language = $ blog ->get_language ();
185
184
$ iconType = MslsAdminIcon::TYPE_FLAG === $ this ->options ->admin_display ? MslsAdminIcon::TYPE_FLAG : MslsAdminIcon::TYPE_LABEL ;
186
- $ icon = MslsAdminIcon::create ($ type )->set_language ( $ language )->set_icon_type ( $ iconType );
185
+ $ icon = MslsAdminIcon::create ( $ type )->set_language ( $ language )->set_icon_type ( $ iconType );
187
186
188
187
if ( $ mydata ->has_value ( $ language ) ) {
189
188
$ icon ->set_href ( $ mydata ->$ language );
@@ -193,23 +192,22 @@ public function render_select() {
193
192
$ p_object = get_post_type_object ( $ type );
194
193
195
194
if ( $ p_object ->hierarchical ) {
196
- $ args = [
195
+ $ args = array (
197
196
'post_type ' => $ type ,
198
197
'selected ' => $ mydata ->$ language ,
199
198
'name ' => 'msls_input_ ' . $ language ,
200
199
'show_option_none ' => ' ' ,
201
200
'option_none_value ' => 0 ,
202
201
'sort_column ' => 'menu_order, post_title ' ,
203
202
'echo ' => 0 ,
204
- ] ;
203
+ ) ;
205
204
206
205
/**
207
206
* Overrides the args for wp_dropdown_pages when using the HTML select in the MetaBox
208
207
*
209
208
* @param array $args
210
209
*
211
210
* @since 1.0.5
212
- *
213
211
*/
214
212
$ args = (array ) apply_filters ( 'msls_meta_box_render_select_hierarchical ' , $ args );
215
213
@@ -239,8 +237,10 @@ public function render_select() {
239
237
} else {
240
238
printf (
241
239
'<p>%s</p> ' ,
242
- __ ( 'You should define at least another blog in a different language in order to have some benefit from this plugin! ' ,
243
- 'multisite-language-switcher ' )
240
+ __ (
241
+ 'You should define at least another blog in a different language in order to have some benefit from this plugin! ' ,
242
+ 'multisite-language-switcher '
243
+ )
244
244
);
245
245
}
246
246
}
@@ -252,21 +252,20 @@ public function render_select() {
252
252
* @return string
253
253
*/
254
254
public function render_options ( $ type , $ msls_id ): string {
255
- $ options = [];
256
-
257
- $ my_query = new \WP_Query ( [
258
- 'post_type ' => $ type ,
259
- 'post_status ' => get_post_stati ( [ 'internal ' => '' ] ),
260
- 'orderby ' => 'title ' ,
261
- 'order ' => 'ASC ' ,
262
- 'posts_per_page ' => - 1 ,
263
- 'fields ' => 'ids ' ,
264
- ] );
265
-
266
- if ( $ my_query ->have_posts () ) {
267
- foreach ( $ my_query ->posts as $ post_id ) {
268
- $ options [] = $ this ->render_option ( $ post_id , $ msls_id );
269
- }
255
+ $ options = array ();
256
+
257
+ $ posts = get_posts (
258
+ array (
259
+ 'post_type ' => $ type ,
260
+ 'post_status ' => get_post_stati ( array ( 'internal ' => '' ) ),
261
+ 'orderby ' => 'title ' ,
262
+ 'order ' => 'ASC ' ,
263
+ 'posts_per_page ' => - 1 ,
264
+ )
265
+ );
266
+
267
+ foreach ( $ posts as $ post ) {
268
+ $ options [] = $ this ->render_option ( $ post ->ID , $ msls_id );
270
269
}
271
270
272
271
return implode ( PHP_EOL , $ options );
@@ -279,10 +278,12 @@ public function render_options( $type, $msls_id ): string {
279
278
* @return string
280
279
*/
281
280
public function render_option ( $ post_id , $ msls_id ) {
282
- return sprintf ( '<option value="%s" %s>%s</option> ' ,
281
+ return sprintf (
282
+ '<option value="%s" %s>%s</option> ' ,
283
283
$ post_id ,
284
284
selected ( $ post_id , $ msls_id , false ),
285
- get_the_title ( $ post_id ) );
285
+ get_the_title ( $ post_id )
286
+ );
286
287
}
287
288
288
289
/**
@@ -311,7 +312,7 @@ public function render_input( $echo = true ) {
311
312
312
313
$ language = $ blog ->get_language ();
313
314
$ icon = MslsAdminIcon::create ()
314
- ->set_language ( $ language );
315
+ ->set_language ( $ language );
315
316
316
317
if ( $ this ->options ->admin_display === 'label ' ) {
317
318
$ icon ->set_icon_type ( 'label ' );
@@ -356,8 +357,10 @@ public function render_input( $echo = true ) {
356
357
} else {
357
358
printf (
358
359
'<p>%s</p> ' ,
359
- __ ( 'You should define at least another blog in a different language in order to have some benefit from this plugin! ' ,
360
- 'multisite-language-switcher ' )
360
+ __ (
361
+ 'You should define at least another blog in a different language in order to have some benefit from this plugin! ' ,
362
+ 'multisite-language-switcher '
363
+ )
361
364
);
362
365
}
363
366
}
0 commit comments