Conditions | 6 |
Paths | 32 |
Total Lines | 61 |
Code Lines | 38 |
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 |
||
36 | public function generate_connect_url() { |
||
37 | |||
38 | check_ajax_referer( 'mi-admin-nonce', 'nonce' ); |
||
39 | |||
40 | // Check for permissions. |
||
41 | if ( ! current_user_can( 'install_plugins' ) ) { |
||
42 | wp_send_json_error( array( 'message' => esc_html__( 'You are not allowed to install plugins.', 'google-analytics-for-wordpress' ) ) ); |
||
43 | } |
||
44 | |||
45 | if ( monsterinsights_is_dev_url( home_url() ) ) { |
||
46 | wp_send_json_success( array( |
||
47 | 'url' => 'https://www.monsterinsights.com/docs/go-lite-pro/#manual-upgrade', |
||
48 | ) ); |
||
49 | } |
||
50 | |||
51 | $key = ! empty( $_POST['key'] ) ? sanitize_text_field( wp_unslash( $_POST['key'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
||
52 | |||
53 | if ( empty( $key ) ) { |
||
54 | wp_send_json_error( |
||
55 | array( |
||
56 | 'message' => esc_html__( 'Please enter your license key to connect.', 'google-analytics-for-wordpress' ), |
||
57 | ) |
||
58 | ); |
||
59 | } |
||
60 | |||
61 | // Verify pro version is not installed. |
||
62 | $active = activate_plugin( 'google-analytics-premium/googleanalytics-premium.php', false, false, true ); |
||
63 | if ( ! is_wp_error( $active ) ) { |
||
64 | // Deactivate plugin. |
||
65 | deactivate_plugins( plugin_basename( MONSTERINSIGHTS_PLUGIN_FILE ) ); |
||
66 | wp_send_json_error( array( |
||
67 | 'message' => esc_html__( 'Pro version is already installed.', 'google-analytics-for-wordpress' ), |
||
68 | 'reload' => true, |
||
69 | ) ); |
||
70 | } |
||
71 | |||
72 | // Redirect. |
||
73 | $oth = hash( 'sha512', wp_rand() ); |
||
74 | update_option( 'monsterinsights_connect', array( |
||
75 | 'key' => $key, |
||
76 | 'time' => time(), |
||
77 | ) ); |
||
78 | update_option( 'monsterinsights_connect_token', $oth ); |
||
79 | $version = MonsterInsights()->version; |
||
80 | $siteurl = admin_url(); |
||
81 | $endpoint = admin_url( 'admin-ajax.php' ); |
||
82 | $redirect = admin_url( 'admin.php?page=monsterinsights_settings' ); |
||
83 | |||
84 | $url = add_query_arg( array( |
||
85 | 'key' => $key, |
||
86 | 'oth' => $oth, |
||
87 | 'endpoint' => $endpoint, |
||
88 | 'version' => $version, |
||
89 | 'siteurl' => $siteurl, |
||
90 | 'homeurl' => home_url(), |
||
91 | 'redirect' => rawurldecode( base64_encode( $redirect ) ), |
||
92 | 'v' => 2, |
||
93 | ), 'https://upgrade.monsterinsights.com' ); |
||
94 | |||
95 | wp_send_json_success( array( |
||
96 | 'url' => $url, |
||
97 | ) ); |
||
195 |