| Conditions | 5 |
| Paths | 5 |
| Total Lines | 51 |
| Code Lines | 42 |
| 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 |
||
| 82 | public function welcome_scripts() { |
||
| 83 | |||
| 84 | $current_screen = get_current_screen(); |
||
| 85 | |||
| 86 | if ( empty( $current_screen->id ) || 'dashboard_page_monsterinsights-getting-started' !== $current_screen->id ) { |
||
| 87 | return; |
||
| 88 | } |
||
| 89 | |||
| 90 | global $wp_version; |
||
| 91 | $version_path = monsterinsights_is_pro_version() ? 'pro' : 'lite'; |
||
| 92 | if ( ! defined( 'MONSTERINSIGHTS_LOCAL_WIZARD_JS_URL' ) ) { |
||
| 93 | wp_enqueue_style( 'monsterinsights-vue-welcome-style-vendors', plugins_url( $version_path . '/assets/vue/css/chunk-vendors.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() ); |
||
| 94 | wp_enqueue_style( 'monsterinsights-vue-welcome-style-common', plugins_url( $version_path . '/assets/vue/css/chunk-common.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() ); |
||
| 95 | wp_enqueue_style( 'monsterinsights-vue-welcome-style', plugins_url( $version_path . '/assets/vue/css/wizard.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() ); |
||
| 96 | wp_enqueue_script( 'monsterinsights-vue-welcome-vendors', plugins_url( $version_path . '/assets/vue/js/chunk-vendors.js', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version(), true ); |
||
| 97 | wp_enqueue_script( 'monsterinsights-vue-welcome-common', plugins_url( $version_path . '/assets/vue/js/chunk-common.js', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version(), true ); |
||
| 98 | wp_register_script( 'monsterinsights-vue-welcome-script', plugins_url( $version_path . '/assets/vue/js/wizard.js', MONSTERINSIGHTS_PLUGIN_FILE ), array( |
||
| 99 | 'monsterinsights-vue-welcome-vendors', |
||
| 100 | 'monsterinsights-vue-welcome-common', |
||
| 101 | ), monsterinsights_get_asset_version(), true ); |
||
| 102 | } else { |
||
| 103 | wp_register_script( 'monsterinsights-vue-welcome-script', MONSTERINSIGHTS_LOCAL_WIZARD_JS_URL, array(), monsterinsights_get_asset_version(), true ); |
||
| 104 | } |
||
| 105 | wp_enqueue_script( 'monsterinsights-vue-welcome-script' ); |
||
| 106 | |||
| 107 | wp_localize_script( |
||
| 108 | 'monsterinsights-vue-welcome-script', |
||
| 109 | 'monsterinsights', |
||
| 110 | array( |
||
| 111 | 'ajax' => add_query_arg( 'page', 'monsterinsights-onboarding', admin_url( 'admin-ajax.php' ) ), |
||
| 112 | 'nonce' => wp_create_nonce( 'mi-admin-nonce' ), |
||
| 113 | 'network' => is_network_admin(), |
||
| 114 | 'translations' => wp_get_jed_locale_data( 'mi-vue-app' ), |
||
| 115 | 'assets' => plugins_url( $version_path . '/assets/vue', MONSTERINSIGHTS_PLUGIN_FILE ), |
||
| 116 | 'roles' => monsterinsights_get_roles(), |
||
| 117 | 'roles_manage_options' => monsterinsights_get_manage_options_roles(), |
||
| 118 | 'wizard_url' => admin_url( 'index.php?page=monsterinsights-onboarding' ), |
||
| 119 | 'shareasale_id' => monsterinsights_get_shareasale_id(), |
||
| 120 | 'shareasale_url' => monsterinsights_get_shareasale_url( monsterinsights_get_shareasale_id(), '' ), |
||
| 121 | // Used to add notices for future deprecations. |
||
| 122 | 'versions' => array( |
||
| 123 | 'php_version' => phpversion(), |
||
| 124 | 'php_version_below_54' => apply_filters( 'monsterinsights_temporarily_hide_php_52_and_53_upgrade_warnings', version_compare( phpversion(), '5.4', '<' ) ), |
||
| 125 | 'php_version_below_56' => apply_filters( 'monsterinsights_temporarily_hide_php_54_and_55_upgrade_warnings', version_compare( phpversion(), '5.6', '<' ) ), |
||
| 126 | 'php_update_link' => monsterinsights_get_url( 'settings-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-php/' ), |
||
| 127 | 'wp_version' => $wp_version, |
||
| 128 | 'wp_version_below_46' => version_compare( $wp_version, '4.6', '<' ), |
||
| 129 | 'wp_version_below_49' => version_compare( $wp_version, '4.9', '<' ), |
||
| 130 | 'wp_update_link' => monsterinsights_get_url( 'settings-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-wordpress/' ), |
||
| 131 | ), |
||
| 132 | 'plugin_version' => MONSTERINSIGHTS_VERSION, |
||
| 133 | ) |
||
| 149 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.