Admin_Menu::update_automator_connect()
Source
File: src/core/admin/class-admin-menu.php
public function update_automator_connect() { if ( isset( $_GET['action'] ) && 'update_free_key' === $_GET['action'] && isset( $_GET['uap_automator_free_license_key'] ) && ! empty( $_GET['uap_automator_free_license_key'] ) ) { update_option( 'uap_automator_free_license_key', $_GET['uap_automator_free_license_key'] ); $license = trim( $_GET['uap_automator_free_license_key'] ); // data to send in our API request $api_params = array( 'edd_action' => 'activate_license', 'license' => $license, 'item_name' => urlencode( AUTOMATOR_FREE_ITEM_NAME ), // the name of our product in uo 'url' => home_url(), ); // Call the custom API. $response = wp_remote_post( AUTOMATOR_FREE_STORE_URL, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params, ) ); // make sure the response came back okay if ( is_wp_error( $response ) ) { delete_option( 'uap_automator_free_license_key' ); $license = false; } else { // decode the license data $license_data = json_decode( wp_remote_retrieve_body( $response ) ); if ( $license_data ) { // $license_data->license will be either "valid" or "invalid" update_option( 'uap_automator_free_license_status', $license_data->license_check ); // $license_data->license_check will be either "valid", "invalid", "expired", "disabled", "inactive", or "site_inactive" update_option( 'uap_automator_free_license_status', $license_data->license ); // License data update_option( 'uap_automator_free_license_data', (array) $license_data ); } wp_safe_redirect( remove_query_arg( [ 'action', 'uap_automator_free_license_key' ] ) ); die; } } elseif ( isset( $_GET['action'] ) && 'discount_automator_connect' === $_GET['action'] ) { $license = get_option( 'uap_automator_free_license_key' ); if ( $license ) { // data to send in our API request $api_params = [ 'edd_action' => 'deactivate_license', 'license' => $license, 'item_name' => urlencode( AUTOMATOR_FREE_ITEM_NAME ), // the name of our product in uo 'url' => home_url(), ]; // Call the custom API. $response = wp_remote_post( AUTOMATOR_FREE_STORE_URL, [ 'timeout' => 15, 'sslverify' => false, 'body' => $api_params, ] ); } delete_option( 'uap_automator_free_license_status' ); delete_option( 'uap_automator_free_license_key' ); delete_option( 'uap_automator_free_license_data' ); wp_safe_redirect( remove_query_arg( [ 'action' ] ) ); die; } }
Expand full source code Collapse full source code View on Github