| Conditions | 7 |
| Paths | 7 |
| Total Lines | 70 |
| Code Lines | 53 |
| 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 |
||
| 9 | function monsterinsights_gutenberg_editor_assets() { |
||
| 10 | // stop loading gutenberg related assets/blocks/sidebars if WP version is less than 5.4 |
||
| 11 | if ( ! monsterinsights_load_gutenberg_app() ) { |
||
| 12 | return; |
||
| 13 | } |
||
| 14 | |||
| 15 | $plugins_js_path = '/assets/gutenberg/js/editor.min.js'; |
||
| 16 | $plugins_style_path = '/assets/gutenberg/css/editor.css'; |
||
| 17 | $version_path = monsterinsights_is_pro_version() ? 'pro' : 'lite'; |
||
| 18 | |||
| 19 | $js_dependencies = array( |
||
| 20 | 'wp-plugins', |
||
| 21 | 'wp-element', |
||
| 22 | 'wp-edit-post', |
||
| 23 | 'wp-i18n', |
||
| 24 | 'wp-api-request', |
||
| 25 | 'wp-data', |
||
| 26 | 'wp-hooks', |
||
| 27 | 'wp-plugins', |
||
| 28 | 'wp-components', |
||
| 29 | 'wp-blocks', |
||
| 30 | 'wp-editor', |
||
| 31 | 'wp-compose', |
||
| 32 | ); |
||
| 33 | |||
| 34 | // Enqueue our plugin JavaScript. |
||
| 35 | wp_enqueue_script( |
||
| 36 | 'monsterinsights-gutenberg-editor-js', |
||
| 37 | plugins_url( $plugins_js_path, MONSTERINSIGHTS_PLUGIN_FILE ), |
||
| 38 | $js_dependencies, |
||
| 39 | monsterinsights_get_asset_version(), |
||
| 40 | true |
||
| 41 | ); |
||
| 42 | |||
| 43 | // Enqueue our plugin JavaScript. |
||
| 44 | wp_enqueue_style( |
||
| 45 | 'monsterinsights-gutenberg-editor-css', |
||
| 46 | plugins_url( $plugins_style_path, MONSTERINSIGHTS_PLUGIN_FILE ), |
||
| 47 | array(), |
||
| 48 | monsterinsights_get_asset_version() |
||
| 49 | ); |
||
| 50 | |||
| 51 | $plugins = get_plugins(); |
||
| 52 | $install_woocommerce_url = false; |
||
| 53 | if ( current_user_can( 'install_plugins' ) ) { |
||
| 54 | $woo_key = 'woocommerce/woocommerce.php'; |
||
| 55 | if ( array_key_exists( $woo_key, $plugins ) ) { |
||
| 56 | $install_woocommerce_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $woo_key ), 'activate-plugin_' . $woo_key ); |
||
| 57 | } else { |
||
| 58 | $install_woocommerce_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' ); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | // Localize script for sidebar plugins. |
||
| 63 | wp_localize_script( |
||
| 64 | 'monsterinsights-gutenberg-editor-js', |
||
| 65 | 'monsterinsights_gutenberg_tool_vars', |
||
| 66 | array( |
||
| 67 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
||
| 68 | 'nonce' => wp_create_nonce( 'monsterinsights_gutenberg_headline_nonce' ), |
||
| 69 | 'allowed_post_types' => apply_filters( 'monsterinsights_headline_analyzer_post_types', array( 'post' ) ), |
||
| 70 | 'current_post_type' => monsterinsights_get_current_post_type(), |
||
| 71 | 'translations' => wp_get_jed_locale_data( monsterinsights_is_pro_version() ? 'ga-premium' : 'google-analytics-for-wordpress' ), |
||
| 72 | 'is_headline_analyzer_enabled' => apply_filters( 'monsterinsights_headline_analyzer_enabled', true ) && 'true' !== monsterinsights_get_option( 'disable_headline_analyzer' ), |
||
| 73 | 'reports_url' => add_query_arg( 'page', 'monsterinsights_reports', admin_url( 'admin.php' ) ), |
||
| 74 | 'vue_assets_path' => plugins_url( $version_path . '/assets/vue/', MONSTERINSIGHTS_PLUGIN_FILE ), |
||
| 75 | 'is_woocommerce_installed' => class_exists( 'WooCommerce' ), |
||
| 76 | 'license_type' => MonsterInsights()->license->get_license_type(), |
||
|
|
|||
| 77 | 'upgrade_url' => monsterinsights_get_upgrade_link( 'gutenberg', 'products' ), |
||
| 78 | 'install_woocommerce_url' => $install_woocommerce_url, |
||
| 79 | ) |
||
| 84 |