ADBC_PLUGIN_VERSION, 'license' => $license_key, 'item_id' => ADBC_EDD_ITEM_ID, 'author' => 'Younes JFR.', 'beta' => false, ) ); } add_action( 'init', 'aDBc_edd_sl_plugin_updater' ); /** * License page * * @return void */ function aDBc_edd_license_page() { $license = get_option('aDBc_edd_license_key'); $status = get_option('aDBc_edd_license_status'); if ( $status !== false && $status == 'valid' ) { $license_key_hidden = substr( $license, 0, 4 ) . "************************" . substr( $license, -4 ); $license_status = __( 'Active', 'advanced-database-cleaner' ); $color = "color:green"; $activate_btn_style = "display:none"; $deactivate_btn_style = ""; $input_disabled = " disabled"; } else { $license_key_hidden = ""; $license_status = __( 'Inactive', 'advanced-database-cleaner' ); $color = "color:red"; $activate_btn_style = ""; $deactivate_btn_style = "display:none"; $input_disabled = ""; } ?>
$edd_action, 'license' => $license, 'item_id' => ADBC_EDD_ITEM_ID, 'item_name' => rawurlencode( ADBC_EDD_ITEM_NAME ), 'url' => home_url(), 'environment' => function_exists( 'wp_get_environment_type' ) ? wp_get_environment_type() : 'production', ); // Call the custom API $response = wp_remote_post( ADBC_EDD_STORE_URL, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params, ) ); // make sure the response came back okay if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { if ( is_wp_error( $response ) ) { wp_send_json_error( $response->get_error_message() ); } else { wp_send_json_error( __( 'An error occurred, please try again.', 'advanced-database-cleaner' ) ); } } $license_data = json_decode( wp_remote_retrieve_body( $response ) ); if ( $edd_action == "activate_license" ) { if ( false === $license_data->success ) { switch ( $license_data->error ) { case 'expired': $message = sprintf( /* translators: the license key expiration date */ __( 'Your license key expired on %s.', 'advanced-database-cleaner' ), date_i18n( get_option( 'date_format' ), strtotime( $license_data->expires, current_time( 'timestamp' ) ) ) ); break; case 'disabled': case 'revoked': $message = __( 'Your license key has been disabled.', 'advanced-database-cleaner' ); break; case 'missing': $message = __( 'Invalid license.', 'advanced-database-cleaner' ); break; case 'invalid': case 'site_inactive': $message = __( 'Your license is not active for this URL.', 'advanced-database-cleaner' ); break; case 'item_name_mismatch': /* translators: the plugin name */ $message = sprintf( __( 'This appears to be an invalid license key for %s.', 'advanced-database-cleaner' ), ADBC_EDD_ITEM_NAME ); break; case 'no_activations_left': $message = __( 'Your license key has reached its activation limit.', 'advanced-database-cleaner' ); break; default: $message = __( 'An error has occurred, please try again.', 'advanced-database-cleaner' ); break; } wp_send_json_error( sanitize_text_field( $message ) ); } // $license_data->license will be either "valid" or "invalid" if ( 'valid' === $license_data->license ) { update_option( 'aDBc_edd_license_key', $license, 'no' ); update_option( 'aDBc_edd_license_status', $license_data->license, 'no' ); wp_send_json_success( __( 'Activated!', 'advanced-database-cleaner' ) ); } else { wp_send_json_error( __( 'License cannot be activated.', 'advanced-database-cleaner' ) ); } } else if ( $edd_action == "check_license" ) { // $license_data->license will be either "valid" or "invalid" if ( 'valid' === $license_data->license ) { wp_send_json_success( __( 'Your license is valid.', 'advanced-database-cleaner' ) ); } else { wp_send_json_error( __( 'Your license is no longer valid.', 'advanced-database-cleaner' ) ); } } else if ( $edd_action == "deactivate_license" ) { // $license_data->license will be either "deactivated" or "failed" // if ( 'deactivated' === $license_data->license ) { delete_option( 'aDBc_edd_license_key' ); delete_option( 'aDBc_edd_license_status' ); wp_send_json_success( __( 'Deactivated!', 'advanced-database-cleaner' ) ); // } else { // wp_send_json_error( __( 'License cannot be deactivated, please try again.', 'advanced-database-cleaner' ) ); // } } // If we are here, maybe un unknown error occurred wp_send_json_error( __( 'Unknown error occurred, please try again.', 'advanced-database-cleaner' ) ); } /** * Checks if a license has been activated * * @return bool true if activated, false if not */ function aDBc_edd_is_license_activated() { $license_status = trim( get_option( 'aDBc_edd_license_status') ); if ( $license_status == 'valid' ) { return true; } else { return false; } } /** * Deactivate a license key after uninstall. This will descrease the site count * * @return void */ function aDBc_edd_deactivate_license_after_uninstall() { $license = trim( sanitize_text_field( get_option( 'aDBc_edd_license_key' ) ) ); // data to send in our API request $api_params = array( 'edd_action' => 'deactivate_license', 'license' => $license, 'item_id' => ADBC_EDD_ITEM_ID, 'item_name' => rawurlencode( ADBC_EDD_ITEM_NAME ), 'url' => home_url(), 'environment' => function_exists( 'wp_get_environment_type' ) ? wp_get_environment_type() : 'production', ); // Call the custom API. $response = wp_remote_post( ADBC_EDD_STORE_URL, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); }