| Conditions | 6 |
| Paths | 32 |
| Total Lines | 76 |
| Code Lines | 49 |
| 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 |
||
| 6 | function monsterinsights_upgrade_license() { |
||
| 7 | |||
| 8 | check_ajax_referer( 'mi-admin-nonce', 'nonce' ); |
||
| 9 | |||
| 10 | // Check for permissions. |
||
| 11 | if ( ! current_user_can( 'install_plugins' ) ) { |
||
| 12 | wp_send_json_error( array( 'message' => esc_html__( 'You are not allowed to install plugins.', 'google-analytics-for-wordpress' ) ) ); |
||
| 13 | } |
||
| 14 | |||
| 15 | // Check license key. |
||
| 16 | $license = monsterinsights_get_license_key(); |
||
| 17 | if ( empty( $license ) ) { |
||
| 18 | wp_send_json_error( array( 'message' => esc_html__( 'You are not licensed.', 'google-analytics-for-wordpress' ) ) ); |
||
| 19 | } |
||
| 20 | |||
| 21 | if ( monsterinsights_is_pro_version() ) { |
||
| 22 | wp_send_json_error( array( 'message' => esc_html__( 'Only the Lite version can upgrade.', 'google-analytics-for-wordpress' ) ) ); |
||
| 23 | } |
||
| 24 | |||
| 25 | $url = esc_url_raw( |
||
|
|
|||
| 26 | add_query_arg( |
||
| 27 | array( |
||
| 28 | 'page' => 'monsterinsights_settings', |
||
| 29 | ), |
||
| 30 | admin_url( 'admin.php' ) |
||
| 31 | ) |
||
| 32 | ); |
||
| 33 | |||
| 34 | // Verify pro version is not installed. |
||
| 35 | $active = activate_plugin( 'google-analytics-premium/googleanalytics-premium.php', false, false, true ); |
||
| 36 | if ( ! is_wp_error( $active ) ) { |
||
| 37 | // Deactivate plugin. |
||
| 38 | deactivate_plugins( plugin_basename( MONSTERINSIGHTS_PLUGIN_FILE ) ); |
||
| 39 | wp_send_json_error( array( |
||
| 40 | 'message' => esc_html__( 'Pro version is already installed.', 'google-analytics-for-wordpress' ), |
||
| 41 | 'reload' => true, |
||
| 42 | ) ); |
||
| 43 | } |
||
| 44 | |||
| 45 | $args = array( |
||
| 46 | 'plugin_name' => 'MonsterInsights Pro', |
||
| 47 | 'plugin_slug' => 'pro', |
||
| 48 | 'plugin_path' => plugin_basename( __FILE__ ), |
||
| 49 | 'plugin_url' => trailingslashit( WP_PLUGIN_URL ) . 'pro', |
||
| 50 | 'remote_url' => 'https://monsterinsights.com/', |
||
| 51 | 'version' => MonsterInsights()->version, |
||
| 52 | 'key' => $license, |
||
| 53 | ); |
||
| 54 | |||
| 55 | $updater = new MonsterInsights_Updater( $args ); |
||
| 56 | $addons = $updater->update_plugins_filter( $updater ); |
||
| 57 | if ( empty( $addons->update->package ) ) { |
||
| 58 | wp_send_json_error(); |
||
| 59 | } |
||
| 60 | |||
| 61 | // Redirect. |
||
| 62 | $oth = hash( 'sha512', wp_rand() ); |
||
| 63 | update_option( 'monsterinsights_one_click_upgrade', $oth ); |
||
| 64 | $version = MonsterInsights()->version; |
||
| 65 | $file = $addons->update->package; |
||
| 66 | $siteurl = admin_url(); |
||
| 67 | $endpoint = admin_url( 'admin-ajax.php' ); |
||
| 68 | $redirect = admin_url( 'admin.php?page=monsterinsights_settings' ); |
||
| 69 | |||
| 70 | $url = add_query_arg( array( |
||
| 71 | 'key' => $license, |
||
| 72 | 'oth' => $oth, |
||
| 73 | 'endpoint' => $endpoint, |
||
| 74 | 'version' => $version, |
||
| 75 | 'siteurl' => $siteurl, |
||
| 76 | 'redirect' => rawurldecode( base64_encode( $redirect ) ), |
||
| 77 | 'file' => rawurldecode( base64_encode( $file ) ), |
||
| 78 | ), 'https://upgrade.monsterinsights.com' ); |
||
| 79 | |||
| 80 | wp_send_json_success( array( |
||
| 81 | 'url' => $url, |
||
| 82 | ) ); |
||
| 195 |