Conditions | 28 |
Paths | 316 |
Total Lines | 182 |
Code Lines | 132 |
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 |
||
111 | public function admin_scripts() { |
||
112 | |||
113 | // Our Common Admin JS. |
||
114 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
||
115 | |||
116 | wp_enqueue_script( 'monsterinsights-admin-common-script', plugins_url( 'assets/js/admin-common' . $suffix . '.js', MONSTERINSIGHTS_PLUGIN_FILE ), array( 'jquery' ), monsterinsights_get_asset_version(), true ); |
||
117 | |||
118 | wp_localize_script( |
||
119 | 'monsterinsights-admin-common-script', |
||
120 | 'monsterinsights_admin_common', |
||
121 | array( |
||
122 | 'ajax' => admin_url( 'admin-ajax.php' ), |
||
123 | 'dismiss_notice_nonce' => wp_create_nonce( 'monsterinsights-dismiss-notice' ), |
||
124 | ) |
||
125 | ); |
||
126 | |||
127 | // Get current screen. |
||
128 | $screen = get_current_screen(); |
||
129 | |||
130 | // Bail if we're not on a MonsterInsights screen. |
||
131 | if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) { |
||
132 | return; |
||
133 | } |
||
134 | |||
135 | $version_path = monsterinsights_is_pro_version() ? 'pro' : 'lite'; |
||
136 | |||
137 | // For the settings page, load the Vue app. |
||
138 | if ( monsterinsights_is_settings_page() ) { |
||
139 | $app_js_url = self::get_js_url( 'src/modules/settings/settings.js' ); |
||
140 | wp_register_script( 'monsterinsights-vue-script', $app_js_url, array( 'wp-i18n' ), monsterinsights_get_asset_version(), true ); |
||
141 | wp_enqueue_script( 'monsterinsights-vue-script' ); |
||
142 | |||
143 | $plugins = get_plugins(); |
||
144 | $install_amp_url = false; |
||
145 | if ( monsterinsights_can_install_plugins() ) { |
||
146 | $amp_key = 'amp/amp.php'; |
||
147 | if ( array_key_exists( $amp_key, $plugins ) ) { |
||
148 | $install_amp_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $amp_key ), 'activate-plugin_' . $amp_key ); |
||
149 | } else { |
||
150 | $install_amp_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=amp' ), 'install-plugin_amp' ); |
||
151 | } |
||
152 | } |
||
153 | |||
154 | $install_woocommerce_url = false; |
||
155 | if ( monsterinsights_can_install_plugins() ) { |
||
156 | $woo_key = 'woocommerce/woocommerce.php'; |
||
157 | if ( array_key_exists( $woo_key, $plugins ) ) { |
||
158 | $install_woocommerce_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $woo_key ), 'activate-plugin_' . $woo_key ); |
||
159 | } else { |
||
160 | $install_woocommerce_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' ); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | $prepared_dimensions = array(); |
||
165 | if ( class_exists( 'MonsterInsights_Admin_Custom_Dimensions' ) ) { |
||
166 | $dimensions = new MonsterInsights_Admin_Custom_Dimensions(); |
||
167 | $dimensions = $dimensions->custom_dimensions(); |
||
168 | $prepared_dimensions = array(); |
||
169 | foreach ( $dimensions as $dimension_type => $dimension ) { |
||
170 | $dimension['type'] = $dimension_type; |
||
171 | $prepared_dimensions[] = $dimension; |
||
172 | } |
||
173 | } |
||
174 | |||
175 | $is_authed = ( MonsterInsights()->auth->is_authed() || MonsterInsights()->auth->is_network_authed() ); |
||
176 | |||
177 | wp_localize_script( |
||
178 | 'monsterinsights-vue-script', |
||
179 | 'monsterinsights', |
||
180 | array( |
||
181 | 'ajax' => admin_url( 'admin-ajax.php' ), |
||
182 | 'nonce' => wp_create_nonce( 'mi-admin-nonce' ), |
||
183 | 'network' => is_network_admin(), |
||
184 | 'assets' => plugins_url( $version_path . '/assets/vue', MONSTERINSIGHTS_PLUGIN_FILE ), |
||
185 | 'roles' => monsterinsights_get_roles(), |
||
186 | 'roles_manage_options' => monsterinsights_get_manage_options_roles(), |
||
187 | 'shareasale_id' => monsterinsights_get_shareasale_id(), |
||
188 | 'shareasale_url' => monsterinsights_get_shareasale_url( monsterinsights_get_shareasale_id(), '' ), |
||
189 | 'addons_url' => is_multisite() ? network_admin_url( 'admin.php?page=monsterinsights_network#/addons' ) : admin_url( 'admin.php?page=monsterinsights_settings#/addons' ), |
||
190 | 'seo_settings_page_url' => is_multisite() ? network_admin_url( 'admin.php?page=monsterinsights_network#/seo' ) : admin_url( 'admin.php?page=monsterinsights_settings#/seo' ), |
||
191 | 'aioseo_dashboard_url' => is_multisite() ? network_admin_url( 'admin.php?page=aioseo' ) : admin_url( 'admin.php?page=aioseo' ), |
||
192 | 'wp_plugins_page_url' => is_multisite() ? network_admin_url( 'plugins.php' ) : admin_url( 'plugins.php' ), |
||
193 | 'email_summary_url' => admin_url( 'admin.php?monsterinsights_email_preview&monsterinsights_email_template=summary' ), |
||
194 | 'install_amp_url' => $install_amp_url, |
||
195 | 'install_woo_url' => $install_woocommerce_url, |
||
196 | 'dimensions' => $prepared_dimensions, |
||
197 | 'wizard_url' => is_network_admin() ? network_admin_url( 'index.php?page=monsterinsights-onboarding' ) : admin_url( 'index.php?page=monsterinsights-onboarding' ), |
||
198 | 'install_plugins' => monsterinsights_can_install_plugins(), |
||
199 | 'unfiltered_html' => current_user_can( 'unfiltered_html' ), |
||
200 | 'activate_nonce' => wp_create_nonce( 'monsterinsights-activate' ), |
||
201 | 'deactivate_nonce' => wp_create_nonce( 'monsterinsights-deactivate' ), |
||
202 | 'install_nonce' => wp_create_nonce( 'monsterinsights-install' ), |
||
203 | // Used to add notices for future deprecations. |
||
204 | 'versions' => monsterinsights_get_php_wp_version_warning_data(), |
||
205 | 'plugin_version' => MONSTERINSIGHTS_VERSION, |
||
206 | 'is_admin' => true, |
||
207 | 'admin_email' => get_option( 'admin_email' ), |
||
208 | 'site_url' => get_site_url(), |
||
209 | 'reports_url' => add_query_arg( 'page', 'monsterinsights_reports', admin_url( 'admin.php' ) ), |
||
210 | 'ecommerce_report_url' => add_query_arg( 'page', 'monsterinsights_reports#/ecommerce', admin_url( 'admin.php' ) ), |
||
211 | 'ecommerce_settings_tab_url' => add_query_arg( 'page', 'monsterinsights_settings#/ecommerce', admin_url( 'admin.php' ) ), |
||
212 | 'first_run_notice' => apply_filters( 'monsterinsights_settings_first_time_notice_hide', monsterinsights_get_option( 'monsterinsights_first_run_notice' ) ), |
||
213 | 'getting_started_url' => is_network_admin() ? network_admin_url( 'admin.php?page=monsterinsights_network#/about' ) : admin_url( 'admin.php?page=monsterinsights_settings#/about/getting-started' ), |
||
214 | 'authed' => $is_authed, |
||
215 | 'new_pretty_link_url' => admin_url( 'post-new.php?post_type=pretty-link' ), |
||
216 | 'wpmailsmtp_admin_url' => admin_url( 'admin.php?page=wp-mail-smtp' ), |
||
217 | 'load_headline_analyzer_settings' => monsterinsights_load_gutenberg_app() ? 'true' : 'false', |
||
218 | 'exit_url' => add_query_arg( 'page', 'monsterinsights_settings', admin_url( 'admin.php' ) ), |
||
219 | 'timezone' => date( 'e' ), |
||
220 | 'funnelkit_stripe_woo_page_url' => admin_url( 'admin.php?page=wc-settings&tab=fkwcs_api_settings' ), |
||
221 | 'funnelkit_stripe_woo_nonce' => wp_create_nonce( 'monsterinsights-funnelkit-stripe-woo-nonce' ), |
||
222 | ) |
||
223 | ); |
||
224 | |||
225 | // Don't load other scripts on the settings page. |
||
226 | return; |
||
227 | } |
||
228 | |||
229 | // For the report pages, load the Vue app. |
||
230 | if ( monsterinsights_is_reports_page() ) { |
||
231 | |||
232 | $app_js_url = self::get_js_url( 'src/modules/reports/reports.js' ); |
||
233 | wp_register_script( 'monsterinsights-vue-reports', $app_js_url, array( 'wp-i18n' ), monsterinsights_get_asset_version(), true ); |
||
234 | wp_enqueue_script( 'monsterinsights-vue-reports' ); |
||
235 | |||
236 | // We do not have a current auth. |
||
237 | $auth = MonsterInsights()->auth; |
||
238 | $site_auth = $auth->get_viewname(); |
||
239 | $ms_auth = is_multisite() && $auth->get_network_viewname(); |
||
240 | |||
241 | // Localize the script with the necessary data. |
||
242 | wp_localize_script( |
||
243 | 'monsterinsights-vue-reports', |
||
244 | 'monsterinsights', |
||
245 | array( |
||
246 | 'ajax' => admin_url( 'admin-ajax.php' ), |
||
247 | 'nonce' => wp_create_nonce( 'mi-admin-nonce' ), |
||
248 | 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
||
249 | 'rest_url' => get_rest_url(), |
||
250 | 'network' => is_network_admin(), |
||
251 | 'translations' => wp_get_jed_locale_data( monsterinsights_is_pro_version() ? 'ga-premium' : 'google-analytics-for-wordpress' ), |
||
252 | 'assets' => plugins_url( $version_path . '/assets/vue', MONSTERINSIGHTS_PLUGIN_FILE ), |
||
253 | 'pro_assets' => plugins_url( $version_path . '/assets', MONSTERINSIGHTS_PLUGIN_FILE ), |
||
254 | 'shareasale_id' => monsterinsights_get_shareasale_id(), |
||
255 | 'shareasale_url' => monsterinsights_get_shareasale_url( monsterinsights_get_shareasale_id(), '' ), |
||
256 | 'addons_url' => is_multisite() ? network_admin_url( 'admin.php?page=monsterinsights_network#/addons' ) : admin_url( 'admin.php?page=monsterinsights_settings#/addons' ), |
||
257 | 'timezone' => date('e'), // phpcs:ignore |
||
258 | 'authed' => $site_auth || $ms_auth, |
||
259 | 'settings_url' => add_query_arg( 'page', 'monsterinsights_settings', admin_url( 'admin.php' ) ), |
||
260 | // Used to add notices for future deprecations. |
||
261 | 'versions' => monsterinsights_get_php_wp_version_warning_data(), |
||
262 | 'plugin_version' => MONSTERINSIGHTS_VERSION, |
||
263 | 'is_admin' => true, |
||
264 | 'admin_email' => get_option( 'admin_email' ), |
||
265 | 'site_url' => get_site_url(), |
||
266 | 'wizard_url' => is_network_admin() ? network_admin_url( 'index.php?page=monsterinsights-onboarding' ) : admin_url( 'index.php?page=monsterinsights-onboarding' ), |
||
267 | 'install_nonce' => wp_create_nonce( 'monsterinsights-install' ), |
||
268 | 'activate_nonce' => wp_create_nonce( 'monsterinsights-activate' ), |
||
269 | 'deactivate_nonce' => wp_create_nonce( 'monsterinsights-deactivate' ), |
||
270 | 'update_settings' => current_user_can( 'monsterinsights_save_settings' ), |
||
271 | 'migrated' => monsterinsights_get_option( 'gadwp_migrated', 0 ), |
||
272 | 'yearinreview' => monsterinsights_yearinreview_dates(), |
||
273 | 'reports_url' => add_query_arg( 'page', 'monsterinsights_reports', admin_url( 'admin.php' ) ), |
||
274 | 'feedback' => MonsterInsights_Feature_Feedback::get_settings(), |
||
275 | 'addons_pre_check' => array( |
||
276 | 'ai_insights' => is_plugin_active( 'monsterinsights-ai-insights/monsterinsights-ai-insights.php' ), |
||
277 | ), |
||
278 | ) |
||
279 | ); |
||
280 | |||
281 | // Load the script with specific translations. |
||
282 | wp_set_script_translations( |
||
283 | 'monsterinsights-vue-reports', |
||
284 | monsterinsights_is_pro_version() ? 'ga-premium' : 'google-analytics-for-wordpress', |
||
285 | MONSTERINSIGHTS_PLUGIN_DIR . 'languages' |
||
286 | ); |
||
287 | |||
288 | return; |
||
289 | } |
||
290 | |||
291 | // ublock notice |
||
292 | add_action( 'admin_print_footer_scripts', array( $this, 'monsterinsights_settings_ublock_error_js' ), 9999999 ); |
||
293 | } |
||
428 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.