Conditions | 7 |
Paths | 8 |
Total Lines | 103 |
Code Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
125 | public function render_select() { |
||
126 | $blogs = $this->collection->get(); |
||
127 | if ( $blogs ) { |
||
128 | global $post; |
||
129 | |||
130 | $type = get_post_type( $post->ID ); |
||
131 | $mydata = new MslsOptionsPost( $post->ID ); |
||
132 | |||
133 | $this->maybe_set_linked_post( $mydata ); |
||
134 | |||
135 | $temp = $post; |
||
136 | |||
137 | wp_nonce_field( MSLS_PLUGIN_PATH, 'msls_noncename' ); |
||
138 | |||
139 | $lis = ''; |
||
140 | |||
141 | foreach ( $blogs as $blog ) { |
||
142 | switch_to_blog( $blog->userblog_id ); |
||
143 | |||
144 | $language = $blog->get_language(); |
||
145 | |||
146 | $icon = MslsAdminIcon::create() |
||
147 | ->set_language( $language ) |
||
148 | ->set_src( MslsOptions::instance()->get_flag_url( $language ) ); |
||
149 | if ( $mydata->has_value( $language ) ) { |
||
150 | $icon->set_href( $mydata->$language ); |
||
151 | } |
||
152 | |||
153 | $selects = ''; |
||
154 | $pto = get_post_type_object( $type ); |
||
155 | |||
156 | if ( $pto->hierarchical ) { |
||
157 | $args = array( |
||
158 | 'post_type' => $type, |
||
159 | 'selected' => $mydata->$language, |
||
160 | 'name' => 'msls_input_' . $language, |
||
161 | 'show_option_none' => ' ', |
||
162 | 'option_none_value' => 0, |
||
163 | 'sort_column' => 'menu_order, post_title', |
||
164 | 'echo' => 0, |
||
165 | ); |
||
166 | /** |
||
167 | * Overrides the args for wp_dropdown_pages when using the HTML select in the MetaBox |
||
168 | * @since 1.0.5 |
||
169 | * |
||
170 | * @param array $args |
||
171 | */ |
||
172 | $args = (array) apply_filters( 'msls_meta_box_render_select_hierarchical', $args ); |
||
173 | |||
174 | $selects .= wp_dropdown_pages( $args ); |
||
175 | } else { |
||
176 | $options = ''; |
||
177 | |||
178 | $my_query = new \WP_Query( |
||
179 | array( |
||
180 | 'post_type' => $type, |
||
181 | 'post_status' => get_post_stati( [ 'internal' => '' ] ), |
||
182 | 'orderby' => 'title', |
||
183 | 'order' => 'ASC', |
||
184 | 'posts_per_page' => - 1, |
||
185 | 'fields' => 'ids', |
||
186 | ) |
||
187 | ); |
||
188 | |||
189 | if ( $my_query->have_posts() ) { |
||
190 | foreach ( $my_query->posts as $my_id ) { |
||
191 | $options .= sprintf( |
||
192 | '<option value="%s" %s>%s</option>', |
||
193 | $my_id, |
||
194 | selected( $my_id, $mydata->$language, false ), |
||
195 | get_the_title( $my_id ) |
||
196 | ); |
||
197 | } |
||
198 | } |
||
199 | $selects .= sprintf( |
||
200 | '<select name="msls_input_%s"><option value="0"></option>%s</select>', |
||
201 | $language, |
||
202 | $options |
||
203 | ); |
||
204 | } |
||
205 | |||
206 | $lis .= sprintf( |
||
207 | '<li><label for="msls_input_%s">%s</label>%s</li>', |
||
208 | $language, |
||
209 | $icon, |
||
210 | $selects |
||
211 | ); |
||
212 | |||
213 | restore_current_blog(); |
||
214 | } |
||
215 | printf( |
||
216 | '<ul>%s</ul><input type="submit" class="button-secondary" value="%s"/>', |
||
217 | $lis, |
||
218 | __( 'Update', 'multisite-language-switcher' ) |
||
219 | ); |
||
220 | $post = $temp; |
||
221 | } else { |
||
222 | printf( |
||
223 | '<p>%s</p>', |
||
224 | __( 'You should define at least another blog in a different language in order to have some benefit from this plugin!', 'multisite-language-switcher' ) |
||
225 | ); |
||
226 | } |
||
227 | } |
||
228 | |||
371 |