Conditions | 18 |
Paths | 289 |
Total Lines | 133 |
Code Lines | 85 |
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 |
||
194 | function page_admin_scripts() { |
||
195 | if ( $this->is_redirecting ) { |
||
196 | return; // No need for scripts on a fallback page |
||
197 | } |
||
198 | |||
199 | $is_dev_mode = Jetpack::is_development_mode(); |
||
200 | |||
201 | // Enqueue jp.js and localize it |
||
202 | wp_enqueue_script( 'react-plugin', plugins_url( '_inc/build/admin.js', JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION, true ); |
||
203 | |||
204 | if ( ! $is_dev_mode ) { |
||
205 | // Required for Analytics |
||
206 | wp_enqueue_script( 'jp-tracks', '//stats.wp.com/w.js', array(), gmdate( 'YW' ), true ); |
||
207 | } |
||
208 | |||
209 | $localeSlug = explode( '_', jetpack_get_user_locale() ); |
||
210 | $localeSlug = $localeSlug[0]; |
||
211 | |||
212 | // Collecting roles that can view site stats |
||
213 | $stats_roles = array(); |
||
214 | $enabled_roles = function_exists( 'stats_get_option' ) ? stats_get_option( 'roles' ) : array( 'administrator' ); |
||
215 | foreach( get_editable_roles() as $slug => $role ) { |
||
216 | $stats_roles[ $slug ] = array( |
||
217 | 'name' => translate_user_role( $role['name'] ), |
||
218 | 'canView' => is_array( $enabled_roles ) ? in_array( $slug, $enabled_roles, true ) : false, |
||
219 | ); |
||
220 | } |
||
221 | |||
222 | $response = rest_do_request( new WP_REST_Request( 'GET', '/jetpack/v4/module/all' ) ); |
||
223 | $modules = $response->get_data(); |
||
224 | |||
225 | // Preparing translated fields for JSON encoding by transforming all HTML entities to |
||
226 | // respective characters. |
||
227 | foreach( $modules as $slug => $data ) { |
||
228 | $modules[ $slug ]['name'] = html_entity_decode( $data['name'] ); |
||
229 | $modules[ $slug ]['description'] = html_entity_decode( $data['description'] ); |
||
230 | $modules[ $slug ]['short_description'] = html_entity_decode( $data['short_description'] ); |
||
231 | $modules[ $slug ]['long_description'] = html_entity_decode( $data['long_description'] ); |
||
232 | } |
||
233 | |||
234 | // Get last post, to build the link to Customizer in the Related Posts module. |
||
235 | $last_post = get_posts( array( 'posts_per_page' => 1 ) ); |
||
236 | $last_post = isset( $last_post[0] ) && $last_post[0] instanceof WP_Post |
||
237 | ? get_permalink( $last_post[0]->ID ) |
||
238 | : get_home_url(); |
||
239 | |||
240 | // Get information about current theme. |
||
241 | $current_theme = wp_get_theme(); |
||
242 | |||
243 | // Get all themes that Infinite Scroll provides support for natively. |
||
244 | $inf_scr_support_themes = array(); |
||
245 | foreach ( Jetpack::glob_php( JETPACK__PLUGIN_DIR . 'modules/infinite-scroll/themes/*.php' ) as $path ) { |
||
246 | if ( is_readable( $path ) ) { |
||
247 | $inf_scr_support_themes[] = basename( $path, '.php' ); |
||
248 | } |
||
249 | } |
||
250 | |||
251 | // Add objects to be passed to the initial state of the app |
||
252 | wp_localize_script( 'react-plugin', 'Initial_State', array( |
||
253 | 'WP_API_root' => esc_url_raw( rest_url() ), |
||
254 | 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ), |
||
255 | 'pluginBaseUrl' => plugins_url( '', JETPACK__PLUGIN_FILE ), |
||
256 | 'connectionStatus' => array( |
||
257 | 'isActive' => Jetpack::is_active(), |
||
258 | 'isStaging' => Jetpack::is_staging_site(), |
||
259 | 'devMode' => array( |
||
260 | 'isActive' => $is_dev_mode, |
||
261 | 'constant' => defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG, |
||
262 | 'url' => site_url() && false === strpos( site_url(), '.' ), |
||
263 | 'filter' => apply_filters( 'jetpack_development_mode', false ), |
||
264 | ), |
||
265 | 'isPublic' => '1' == get_option( 'blog_public' ), |
||
266 | 'isInIdentityCrisis' => Jetpack::validate_sync_error_idc_option(), |
||
267 | ), |
||
268 | 'dismissedNotices' => $this->get_dismissed_jetpack_notices(), |
||
269 | 'isDevVersion' => Jetpack::is_development_version(), |
||
270 | 'currentVersion' => JETPACK__VERSION, |
||
271 | 'getModules' => $modules, |
||
272 | 'showJumpstart' => jetpack_show_jumpstart(), |
||
273 | 'showHolidaySnow' => function_exists( 'jetpack_show_holiday_snow_option' ) ? jetpack_show_holiday_snow_option() : false, |
||
274 | 'rawUrl' => Jetpack::build_raw_urls( get_home_url() ), |
||
275 | 'adminUrl' => esc_url( admin_url() ), |
||
276 | 'stats' => array( |
||
277 | // data is populated asynchronously on page load |
||
278 | 'data' => array( |
||
279 | 'general' => false, |
||
280 | 'day' => false, |
||
281 | 'week' => false, |
||
282 | 'month' => false, |
||
283 | ), |
||
284 | 'roles' => $stats_roles, |
||
285 | ), |
||
286 | 'settings' => $this->get_flattened_settings( $modules ), |
||
287 | 'settingNames' => array( |
||
288 | 'jetpack_holiday_snow_enabled' => function_exists( 'jetpack_holiday_snow_option_name' ) ? jetpack_holiday_snow_option_name() : false, |
||
289 | ), |
||
290 | 'userData' => array( |
||
291 | // 'othersLinked' => Jetpack::get_other_linked_admins(), |
||
292 | 'currentUser' => jetpack_current_user_data(), |
||
293 | ), |
||
294 | 'siteData' => array( |
||
295 | 'icon' => has_site_icon() |
||
296 | ? apply_filters( 'jetpack_photon_url', get_site_icon_url(), array( 'w' => 64 ) ) |
||
297 | : '', |
||
298 | 'siteVisibleToSearchEngines' => '1' == get_option( 'blog_public' ), |
||
299 | /** |
||
300 | * Whether promotions are visible or not. |
||
301 | * |
||
302 | * @since 4.8.0 |
||
303 | * |
||
304 | * @param bool $are_promotions_active Status of promotions visibility. True by default. |
||
305 | */ |
||
306 | 'showPromotions' => apply_filters( 'jetpack_show_promotions', true ), |
||
307 | ), |
||
308 | 'themeData' => array( |
||
309 | 'name' => $current_theme->get( 'Name' ), |
||
310 | 'hasUpdate' => (bool) get_theme_update_available( $current_theme ), |
||
311 | 'support' => array( |
||
312 | 'infinite-scroll' => current_theme_supports( 'infinite-scroll' ) || in_array( $current_theme->get_stylesheet(), $inf_scr_support_themes ), |
||
313 | ), |
||
314 | ), |
||
315 | 'locale' => $this->get_i18n_data(), |
||
316 | 'localeSlug' => $localeSlug, |
||
317 | 'jetpackStateNotices' => array( |
||
318 | 'messageCode' => Jetpack::state( 'message' ), |
||
319 | 'errorCode' => Jetpack::state( 'error' ), |
||
320 | 'errorDescription' => Jetpack::state( 'error_description' ), |
||
321 | ), |
||
322 | 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), |
||
323 | 'currentIp' => function_exists( 'jetpack_protect_get_ip' ) ? jetpack_protect_get_ip() : false, |
||
324 | 'lastPostUrl' => esc_url( $last_post ), |
||
325 | ) ); |
||
326 | } |
||
327 | |||
435 |