s ) ) { $request->icons = maybe_unserialize( $request->icons ); } if ( ! empty( $request->sections ) ) { foreach ( $request->sections as $key => $section ) { $request->$key = (array) $section; } } return $request; } /** * Get the version info from the cache, if it exists. * * @param string $cache_key * @return object */ public function get_cached_version_info( $cache_key = '' ) { if ( empty( $cache_key ) ) { $cache_key = $this->get_cache_key(); } $cache = get_option( $cache_key ); // Cache is expired if ( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) { return false; } // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point. $cache['value'] = json_decode( $cache['value'] ); if ( ! empty( $cache['value']->icons ) ) { $cache['value']->icons = (array) $cache['value']->icons; } return $cache['value']; } /** * Adds the plugin version information to the database. * * @param string $value * @param string $cache_key */ public function set_version_info_cache( $value = '', $cache_key = '' ) { if ( empty( $cache_key ) ) { $cache_key = $this->get_cache_key(); } $data = array( 'timeout' => strtotime( '+3 hours', time() ), 'value' => wp_json_encode( $value ), ); update_option( $cache_key, $data, 'no' ); // Delete the duplicate option delete_option( 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ) ); } /** * Returns if the SSL of the store should be verified. * * @since 1.6.13 * @return bool */ private function verify_ssl() { return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this ); } /** * Gets the unique key (option name) for a plugin. * * @since 1.9.0 * @return string */ private function get_cache_key() { $string = $this->slug . $this->api_data['license'] . $this->beta; return 'edd_sl_' . md5( serialize( $string ) ); } /** * Activates the license key. * * @return array */ function activate_license() { // retrieve the license from the database $license = $this->api_data['license']; // data to send in our API request $api_params = array( 'edd_action' => 'activate_license', 'license' => $license, 'item_id' => $this->api_data['item_id'], 'item_name' => $this->api_data['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( $this->api_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 ) ) { $message = $response->get_error_message(); } else { $message = __( 'An error occurred, please try again.' ); } } else { $license_data = json_decode( wp_remote_retrieve_body( $response ) ); if ( !$license_data->success ) { switch ( $license_data->error ) { case 'expired': $message = sprintf( /* translators: the license key expiration date */ __( 'Your license key expired on %s.', 'gutentor-pro' ), 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.', 'gutentor-pro' ); break; case 'missing': $message = __( 'Invalid license.', 'gutentor-pro' ); break; case 'invalid': case 'site_inactive': $message = __( 'Your license is not active for this URL.', 'gutentor-pro' ); break; case 'item_name_mismatch': /* translators: the plugin name */ $message = sprintf( __( 'This appears to be an invalid license key for %s.', 'gutentor-pro' ), GUTENTOR_PRO_ITEM_NAME ); break; case 'no_activations_left': $message = __( 'Your license key has reached its activation limit.', 'gutentor-pro' ); break; default: $message = __( 'An error occurred, please try again.', 'gutentor-pro' ); break; } } } // $license_data->license will be either "valid" or "invalid" if ( 'valid' === $license_data->license ) { update_option( $this->slug . '_license_key', $license ); $license_status = array( 'is_activated' => true, 'msg' => __( 'License is valid.', 'gutentor-pro' ), ); } else { $license_status = array( 'is_activated' => false, 'msg' => $message, ); } update_option( $this->slug . '_license_status', $license_data->license ); return $license_status; } /** * Checks if a license key is still valid. * The updater does this for you, so this is only needed if you want * to do somemthing custom. * * @return boolean||void */ function check_license() { $license = trim( get_option( $this->slug . '_license_key' ) ); if ( ! $license ) { return false; } // data to send in our API request $api_params = array( 'edd_action' => 'check_license', 'license' => $license, 'item_id' => $this->api_data['item_id'], 'item_name' => $this->api_data['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( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params, ) ); if ( is_wp_error( $response ) ) { return false; } return json_decode( wp_remote_retrieve_body( $response ) ); } } /** * Begins execution of the hooks. * * @since 1.0.0 */ function gutentor_pro_edd_plugin_installer() { return Gutentor_Pro_Edd_Plugin_Installer::get_instance(); }