Conditions | 13 |
Paths | 98 |
Total Lines | 67 |
Code Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
142 | public function widget_scripts() { |
||
143 | $version_path = 'lite'; |
||
144 | $rtl = is_rtl() ? '.rtl' : ''; |
||
145 | |||
146 | $screen = get_current_screen(); |
||
147 | if ( isset( $screen->id ) && 'dashboard' === $screen->id ) { |
||
148 | global $wp_version; |
||
149 | if ( ! defined( 'MONSTERINSIGHTS_LOCAL_WIDGET_JS_URL' ) ) { |
||
150 | wp_enqueue_style( 'monsterinsights-vue-style-vendors', plugins_url( $version_path . '/assets/vue/css/chunk-vendors' . $rtl . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() ); |
||
151 | wp_enqueue_style( 'monsterinsights-vue-widget-style', plugins_url( $version_path . '/assets/vue/css/widget' . $rtl . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() ); |
||
152 | wp_enqueue_script( 'monsterinsights-vue-vendors', plugins_url( $version_path . '/assets/vue/js/chunk-vendors.js', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version(), true ); |
||
153 | wp_enqueue_script( 'monsterinsights-vue-common', plugins_url( $version_path . '/assets/vue/js/chunk-common.js', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version(), true ); |
||
154 | } |
||
155 | $widget_js_url = defined( 'MONSTERINSIGHTS_LOCAL_WIDGET_JS_URL' ) && MONSTERINSIGHTS_LOCAL_WIDGET_JS_URL ? MONSTERINSIGHTS_LOCAL_WIDGET_JS_URL : plugins_url( $version_path . '/assets/vue/js/widget.js', MONSTERINSIGHTS_PLUGIN_FILE ); |
||
156 | wp_register_script( 'monsterinsights-vue-widget', $widget_js_url, array(), monsterinsights_get_asset_version(), true ); |
||
157 | wp_enqueue_script( 'monsterinsights-vue-widget' ); |
||
158 | |||
159 | $plugins = get_plugins(); |
||
160 | $wp_forms_url = false; |
||
161 | $wpforms_installed = false; |
||
162 | if ( current_user_can( 'install_plugins' ) ) { |
||
163 | $wpforms_key = 'wpforms-lite/wpforms.php'; |
||
164 | if ( array_key_exists( $wpforms_key, $plugins ) ) { |
||
165 | $wp_forms_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $wpforms_key ), 'activate-plugin_' . $wpforms_key ); |
||
166 | $wpforms_installed = true; |
||
167 | } else { |
||
168 | $wp_forms_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=wpforms-lite' ), 'install-plugin_wpforms-lite' ); |
||
169 | } |
||
170 | } |
||
171 | $is_authed = ( MonsterInsights()->auth->is_authed() || MonsterInsights()->auth->is_network_authed() ); |
||
172 | wp_localize_script( |
||
173 | 'monsterinsights-vue-widget', |
||
174 | 'monsterinsights', |
||
175 | array( |
||
176 | 'ajax' => admin_url( 'admin-ajax.php' ), |
||
177 | 'nonce' => wp_create_nonce( 'mi-admin-nonce' ), |
||
178 | 'network' => is_network_admin(), |
||
179 | 'translations' => wp_get_jed_locale_data( monsterinsights_is_pro_version() ? 'ga-premium' : 'google-analytics-for-wordpress' ), |
||
180 | 'assets' => plugins_url( $version_path . '/assets/vue', MONSTERINSIGHTS_PLUGIN_FILE ), |
||
181 | 'shareasale_id' => monsterinsights_get_shareasale_id(), |
||
182 | 'shareasale_url' => monsterinsights_get_shareasale_url( monsterinsights_get_shareasale_id(), '' ), |
||
183 | 'addons_url' => is_multisite() ? network_admin_url( 'admin.php?page=monsterinsights_network#/addons' ) : admin_url( 'admin.php?page=monsterinsights_settings#/addons' ), |
||
184 | 'widget_state' => $this->get_options(), |
||
185 | 'wpforms_enabled' => function_exists( 'wpforms' ), |
||
186 | 'wpforms_installed' => $wpforms_installed, |
||
187 | 'wpforms_url' => $wp_forms_url, |
||
188 | 'authed' => $is_authed, |
||
189 | // Used to add notices for future deprecations. |
||
190 | 'versions' => array( |
||
191 | 'php_version' => phpversion(), |
||
192 | 'php_version_below_54' => apply_filters( 'monsterinsights_temporarily_hide_php_52_and_53_upgrade_warnings', version_compare( phpversion(), '5.4', '<' ) ), |
||
193 | 'php_version_below_56' => apply_filters( 'monsterinsights_temporarily_hide_php_54_and_55_upgrade_warnings', version_compare( phpversion(), '5.6', '<' ) ), |
||
194 | 'php_update_link' => monsterinsights_get_url( 'settings-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-php/' ), |
||
195 | 'wp_version' => $wp_version, |
||
196 | 'wp_version_below_46' => version_compare( $wp_version, '4.6', '<' ), |
||
197 | 'wp_version_below_49' => version_compare( $wp_version, '4.9', '<' ), |
||
198 | 'wp_update_link' => monsterinsights_get_url( 'settings-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-wordpress/' ), |
||
199 | ), |
||
200 | 'plugin_version' => MONSTERINSIGHTS_VERSION, |
||
201 | 'is_admin' => true, |
||
202 | 'reports_url' => add_query_arg( 'page', 'monsterinsights_reports', admin_url( 'admin.php' ) ), |
||
203 | 'getting_started_url' => is_multisite() ? network_admin_url( 'admin.php?page=monsterinsights_network#/about/getting-started' ) : admin_url( 'admin.php?page=monsterinsights_settings#/about/getting-started' ), |
||
204 | 'wizard_url' => admin_url( 'index.php?page=monsterinsights-onboarding' ), |
||
205 | ) |
||
206 | ); |
||
207 | |||
208 | $this->remove_conflicting_asset_files(); |
||
209 | } |
||
325 |