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 |
||
117 | public function render_select() { |
||
118 | $blogs = MslsBlogCollection::instance()->get(); |
||
119 | if ( $blogs ) { |
||
120 | global $post; |
||
121 | |||
122 | $type = get_post_type( $post->ID ); |
||
123 | $mydata = new MslsOptionsPost( $post->ID ); |
||
124 | |||
125 | $this->maybe_set_linked_post( $mydata ); |
||
126 | |||
127 | $temp = $post; |
||
128 | |||
129 | wp_nonce_field( MSLS_PLUGIN_PATH, 'msls_noncename' ); |
||
130 | |||
131 | $lis = ''; |
||
132 | |||
133 | foreach ( $blogs as $blog ) { |
||
134 | switch_to_blog( $blog->userblog_id ); |
||
135 | |||
136 | $language = $blog->get_language(); |
||
137 | |||
138 | $icon = MslsAdminIcon::create() |
||
139 | ->set_language( $language ) |
||
140 | ->set_src( MslsOptions::instance()->get_flag_url( $language ) ); |
||
141 | if ( $mydata->has_value( $language ) ) { |
||
142 | $icon->set_href( $mydata->$language ); |
||
143 | } |
||
144 | |||
145 | $selects = ''; |
||
146 | $pto = get_post_type_object( $type ); |
||
147 | |||
148 | if ( $pto->hierarchical ) { |
||
149 | $args = array( |
||
150 | 'post_type' => $type, |
||
151 | 'selected' => $mydata->$language, |
||
152 | 'name' => 'msls_input_' . $language, |
||
153 | 'show_option_none' => ' ', |
||
154 | 'option_none_value' => 0, |
||
155 | 'sort_column' => 'menu_order, post_title', |
||
156 | 'echo' => 0, |
||
157 | ); |
||
158 | /** |
||
159 | * Overrides the args for wp_dropdown_pages when using the HTML select in the MetaBox |
||
160 | * @since 1.0.5 |
||
161 | * |
||
162 | * @param array $args |
||
163 | */ |
||
164 | $args = (array) apply_filters( 'msls_meta_box_render_select_hierarchical', $args ); |
||
165 | |||
166 | $selects .= wp_dropdown_pages( $args ); |
||
167 | } else { |
||
168 | $options = ''; |
||
169 | |||
170 | $my_query = new WP_Query( |
||
171 | array( |
||
172 | 'post_type' => $type, |
||
173 | 'post_status' => get_post_stati( array( 'internal' => '' ) ), |
||
174 | 'orderby' => 'title', |
||
175 | 'order' => 'ASC', |
||
176 | 'posts_per_page' => - 1, |
||
177 | 'fields' => 'ids', |
||
178 | ) |
||
179 | ); |
||
180 | |||
181 | if ( $my_query->have_posts() ) { |
||
182 | foreach ( $my_query->posts as $my_id ) { |
||
183 | $options .= sprintf( |
||
184 | '<option value="%s" %s>%s</option>', |
||
185 | $my_id, |
||
186 | selected( $my_id, $mydata->$language, false ), |
||
187 | get_the_title( $my_id ) |
||
188 | ); |
||
189 | } |
||
190 | } |
||
191 | $selects .= sprintf( |
||
192 | '<select name="msls_input_%s"><option value="0"></option>%s</select>', |
||
193 | $language, |
||
194 | $options |
||
195 | ); |
||
196 | } |
||
197 | |||
198 | $lis .= sprintf( |
||
199 | '<li><label for="msls_input_%s">%s</label>%s</li>', |
||
200 | $language, |
||
201 | $icon, |
||
202 | $selects |
||
203 | ); |
||
204 | |||
205 | restore_current_blog(); |
||
206 | } |
||
207 | printf( |
||
208 | '<ul>%s</ul><input type="submit" class="button-secondary" value="%s"/>', |
||
209 | $lis, |
||
210 | __( 'Update', 'multisite-language-switcher' ) |
||
211 | ); |
||
212 | $post = $temp; |
||
213 | } else { |
||
214 | printf( |
||
215 | '<p>%s</p>', |
||
216 | __( 'You should define at least another blog in a different language in order to have some benefit from this plugin!', 'multisite-language-switcher' ) |
||
217 | ); |
||
218 | } |
||
219 | } |
||
220 | |||
360 |