); } /** * Deactivate license. * * @param string $license License to deactivate. * @return void */ public function deactivate_license( $license ) { $args = array( 'license' => $license, 'name' => 'Pronamic Pay', 'url' => home_url(), ); $args = urlencode_deep( $args ); $response = wp_remote_get( add_query_arg( $args, 'https://api.pronamic.eu/licenses/deactivate/1.0/' ), array( 'timeout' => 20, ) ); } /** * Activate license. * * @param string $license License to activate. * @return void */ public function activate_license( $license ) { // Request. $args = array( 'license' => $license, 'name' => 'Pronamic Pay', 'url' => home_url(), ); $args = urlencode_deep( $args ); $response = wp_remote_get( add_query_arg( $args, 'https://api.pronamic.eu/licenses/activate/1.0/' ), array( 'timeout' => 20, ) ); if ( $response instanceof WP_Error ) { return; } $data = json_decode( wp_remote_retrieve_body( $response ) ); if ( $data ) { set_transient( 'pronamic_pay_license_data', $data, 30 ); } } /** * Get license status text. * * @return string */ public function get_formatted_license_status() { $license_status = get_option( 'pronamic_pay_license_status' ); switch ( $license_status ) { case 'valid': return __( 'Valid', 'pronamic_ideal' ); case 'invalid': return __( 'Invalid', 'pronamic_ideal' ); case 'site_inactive': return __( 'Site Inactive', 'pronamic_ideal' ); } return $license_status; } /** * Get next scheduled license check text. * * @return string */ public function get_formatted_next_license_check() { $next_license_check = esc_html__( 'Not scheduled', 'pronamic_ideal' ); $timestamp = wp_next_scheduled( 'pronamic_pay_license_check' ); if ( false !== $timestamp ) { try { $date = new DateTime( '@' . $timestamp, new DateTimeZone( 'UTC' ) ); $next_license_check = $date->format_i18n(); } catch ( \Exception $e ) { return $next_license_check; } } return $next_license_check; } }