updated plugin Easy Digital Downloads
version 3.1.1.4.2
This commit is contained in:
@ -19,6 +19,7 @@ class Core extends EventManagement\Subscribers {
|
||||
return array(
|
||||
new Admin\PassHandler\Ajax( $this->pass_handler ),
|
||||
new Admin\Extensions\Extension_Manager(),
|
||||
new Customers\Recalculations(),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Handles scheduling recalculations for a customer.
|
||||
*/
|
||||
namespace EDD\Customers;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use EDD\EventManagement\SubscriberInterface;
|
||||
|
||||
class Recalculations implements SubscriberInterface {
|
||||
|
||||
/**
|
||||
* Returns an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return array(
|
||||
'edd_order_added' => array( 'maybe_schedule_recalculation', 10, 2 ),
|
||||
'edd_order_updated' => array( 'maybe_schedule_recalculation', 10, 3 ),
|
||||
'edd_order_deleted' => 'maybe_schedule_recalculation',
|
||||
'edd_recalculate_customer_deferred' => 'recalculate',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* When an order is added, updated, or changed, the customer stats may need to be recalculated.
|
||||
*
|
||||
* @param int $order_id The order ID.
|
||||
* @param array $data The array of order data.
|
||||
* @param bool|EDD\Orders|Order $previous_order The previous order object (when updating).
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_schedule_recalculation( $order_id, $data = array(), $previous_order = false ) {
|
||||
|
||||
// Recalculations do not need to run when the order item is first being added to the database if it's pending.
|
||||
if ( 'edd_order_added' === current_action() && ( empty( $data['status'] ) || 'pending' === $data['status'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the order item data being updated doesn't affect sales/earnings, recalculations do not need to be run.
|
||||
if ( $previous_order instanceof EDD\Orders\Order ) {
|
||||
$columns_affecting_stats = array( 'status', 'total', 'subtotal', 'discount', 'tax', 'rate', 'customer_id' );
|
||||
|
||||
// If the data being updated isn't one of these columns then we don't need to recalculate.
|
||||
if ( empty( array_intersect( array_keys( $data ), $columns_affecting_stats ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the data exists but matches, we don't need to recalculate.
|
||||
if (
|
||||
( empty( $data['status'] ) || $previous_order->status === $data['status'] ) &&
|
||||
( ! isset( $data['total'] ) || $previous_order->total == $data['total'] ) &&
|
||||
( ! isset( $data['subtotal'] ) || $previous_order->subtotal == $data['subtotal'] ) &&
|
||||
( ! isset( $data['discount'] ) || $previous_order->discount == $data['discount'] ) &&
|
||||
( ! isset( $data['tax'] ) || $previous_order->tax == $data['tax'] ) &&
|
||||
( ! isset( $data['rate'] ) || $previous_order->rate == $data['rate'] ) &&
|
||||
( empty( $data['customer_id'] ) || $previous_order->customer_id == $data['customer_id'] )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Recalculate the previous product values if the product ID has changed.
|
||||
if ( ! empty( $data['customer_id'] ) && $previous_order->customer_id != $data['customer_id'] ) {
|
||||
$this->schedule_recalculation( $previous_order->customer_id );
|
||||
}
|
||||
}
|
||||
|
||||
$order = edd_get_order( $order_id );
|
||||
if ( empty( $order->customer_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->schedule_recalculation( $order->customer_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculate the value of a customer.
|
||||
*
|
||||
* @since 3.1.1.4
|
||||
* @param int $customer_id
|
||||
* @return void
|
||||
*/
|
||||
public function recalculate( $customer_id ) {
|
||||
$customer = edd_get_customer( $customer_id );
|
||||
if ( ! $customer instanceof \EDD_Customer ) {
|
||||
return;
|
||||
}
|
||||
$customer->recalculate_stats();
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe schedule the customer recalculation--it will be skipped if already scheduled.
|
||||
*
|
||||
* @since 3.1.1.4
|
||||
* @param int $customer_id
|
||||
* @return void
|
||||
*/
|
||||
private function schedule_recalculation( $customer_id ) {
|
||||
$is_scheduled = wp_next_scheduled( 'edd_recalculate_customer_deferred', array( $customer_id ) );
|
||||
$bypass_cron = apply_filters( 'edd_recalculate_bypass_cron', false );
|
||||
|
||||
// Check if the recalculation has already been scheduled.
|
||||
if ( $is_scheduled && ! $bypass_cron ) {
|
||||
edd_debug_log( 'Recalculation is already scheduled for customer ' . $customer_id . ' at ' . edd_date_i18n( $is_scheduled, 'datetime' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are intentionally bypassing cron somehow, recalculate now and return.
|
||||
if ( $bypass_cron || ( defined( 'EDD_DOING_TESTS' ) && EDD_DOING_TESTS ) || ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ) {
|
||||
$this->recalculate( $customer_id );
|
||||
return;
|
||||
}
|
||||
|
||||
edd_debug_log( 'Scheduling recalculation for customer ' . $customer_id );
|
||||
wp_schedule_single_event(
|
||||
time() + ( 5 * MINUTE_IN_SECONDS ),
|
||||
'edd_recalculate_customer_deferred',
|
||||
array( $customer_id )
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* License Registry
|
||||
*
|
||||
* Responsible for holding information about premium EDD extensions in use on this site.
|
||||
*
|
||||
* @package easy-digital-downloads
|
||||
* @copyright Copyright (c) 2021, Easy Digital Downloads
|
||||
* @license GPL2+
|
||||
* @since 2.11.4
|
||||
*/
|
||||
|
||||
namespace EDD\Extensions;
|
||||
|
||||
class ExtensionRegistry extends \ArrayObject {
|
||||
|
||||
/**
|
||||
* Adds an extension to the registry.
|
||||
*
|
||||
* @since 2.11.4
|
||||
*
|
||||
* @param string $pluginFile Path to the plugin's main file.
|
||||
* @param string $pluginName Display name of the plugin.
|
||||
* @param int $pluginId EDD product ID for the plugin.
|
||||
* @param string $currentVersion Current version number.
|
||||
* @param string|null $optionName Option name where the license key is stored. If omitted, automatically generated.
|
||||
*/
|
||||
public function addExtension( $pluginFile, $pluginName, $pluginId, $currentVersion, $optionName = null ) {
|
||||
if ( $this->offsetExists( $pluginId ) ) {
|
||||
throw new \InvalidArgumentException( sprintf(
|
||||
'The extension %d is already registered.',
|
||||
$pluginId
|
||||
) );
|
||||
}
|
||||
|
||||
$this->offsetSet(
|
||||
$pluginId,
|
||||
new Handler( $pluginFile, $pluginId, $pluginName, $currentVersion, $optionName )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all registered extensions, regardless of whether they have licenses activated.
|
||||
*
|
||||
* At some point we could make this public, just making it private for now so that we have
|
||||
* flexibility to change exactly what it returns in the future.
|
||||
*
|
||||
* @since 2.11.4
|
||||
* @return Handler[]
|
||||
*/
|
||||
private function getExtensions() {
|
||||
return $this->getArrayCopy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of licensed extensions active on this site.
|
||||
* Note: This only looks at extensions registered via this registry, then filters down
|
||||
* to those that have a license key entered. It does not check to verify if the license
|
||||
* key is actually valid / not expired.
|
||||
*
|
||||
* @since 2.11.4
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countLicensedExtensions() {
|
||||
$licensedExtensions = array_filter( $this->getExtensions(), function ( Handler $license ) {
|
||||
return ! empty( $license->license_key );
|
||||
} );
|
||||
|
||||
return count( $licensedExtensions );
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,407 @@
|
||||
<?php
|
||||
/**
|
||||
* License handler for extensions using the ExtensionRegistry.
|
||||
*
|
||||
* @since 3.1.1.4
|
||||
*/
|
||||
|
||||
namespace EDD\Extensions;
|
||||
|
||||
use EDD\Licensing\API;
|
||||
use EDD\Licensing\License;
|
||||
use EDD\Admin\Pass_Manager;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Handler Class
|
||||
*/
|
||||
class Handler {
|
||||
|
||||
/**
|
||||
* The license key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $license_key;
|
||||
|
||||
/**
|
||||
* The plugin file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* The extension name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $item_name;
|
||||
|
||||
/**
|
||||
* The extension item ID.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $item_id;
|
||||
|
||||
/**
|
||||
* The extension shortname.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $item_shortname;
|
||||
|
||||
/**
|
||||
* The extension version.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* The pass manager.
|
||||
*
|
||||
* @var \EDD\Admin\Pass_Manager
|
||||
*/
|
||||
private $pass_manager;
|
||||
|
||||
/**
|
||||
* The EDD license object.
|
||||
* This contains standard license data (from the API response) and the license key.
|
||||
*
|
||||
* @var \EDD\Licensing\License
|
||||
*/
|
||||
private $edd_license;
|
||||
|
||||
/**
|
||||
* Whether the license being checked is a pro license.
|
||||
*
|
||||
* @since 3.1.1
|
||||
* @var bool
|
||||
*/
|
||||
private $is_pro_license = false;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $_file
|
||||
* @param int $_item_id
|
||||
* @param string $_item_name
|
||||
* @param string $_version
|
||||
* @param string $_optname
|
||||
*/
|
||||
public function __construct( $_file, $_item_id, $_item_name, $_version, $_optname = null ) {
|
||||
$this->file = $_file;
|
||||
$this->item_id = absint( $_item_id );
|
||||
$this->item_name = $_item_name;
|
||||
$this->item_shortname = $this->get_shortname();
|
||||
$this->version = $_version;
|
||||
$this->edd_license = new License( $this->item_name, $_optname );
|
||||
if ( empty( $this->edd_license->key ) || empty( $this->edd_license->license ) ) {
|
||||
$pro_license = new License( 'pro' );
|
||||
if ( ! empty( $pro_license->key ) ) {
|
||||
$this->is_pro_license = true;
|
||||
$this->edd_license = $pro_license;
|
||||
}
|
||||
}
|
||||
$this->license_key = $this->edd_license->key;
|
||||
$this->pass_manager = new Pass_Manager();
|
||||
|
||||
$this->hooks();
|
||||
$this->update_global();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up hooks.
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function hooks() {
|
||||
|
||||
// Register settings.
|
||||
add_filter( 'edd_settings_licenses', array( $this, 'settings' ), 1 );
|
||||
|
||||
// Check that license is valid once per week.
|
||||
if ( ! $this->is_pro_license || ! $this->is_included_in_pass() ) {
|
||||
add_action( 'edd_weekly_scheduled_events', array( $this, 'weekly_license_check' ) );
|
||||
}
|
||||
|
||||
// Updater.
|
||||
add_action( 'init', array( $this, 'auto_updater' ) );
|
||||
|
||||
// Display notices to admins.
|
||||
add_action( 'admin_notices', array( $this, 'notices' ) );
|
||||
add_action( 'in_plugin_update_message-' . plugin_basename( $this->file ), array( $this, 'plugin_row_license_missing' ), 10, 2 );
|
||||
|
||||
// Register plugins for beta support.
|
||||
add_filter( 'edd_beta_enabled_extensions', array( $this, 'register_beta_support' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto updater
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function auto_updater() {
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) && ! edd_doing_cron() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fall back to the highest license key if one is not saved for this extension or there isn't a pro license.
|
||||
if ( empty( $this->license_key ) ) {
|
||||
if ( $this->pass_manager->highest_license_key ) {
|
||||
$this->license_key = $this->pass_manager->highest_license_key;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't check for updates if there isn't a license key.
|
||||
if ( empty( $this->license_key ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'version' => $this->version,
|
||||
'license' => $this->license_key,
|
||||
'item_id' => $this->item_id,
|
||||
'beta' => function_exists( 'edd_extension_has_beta_support' ) && edd_extension_has_beta_support( $this->item_shortname ),
|
||||
);
|
||||
|
||||
// Set up the updater.
|
||||
new Updater(
|
||||
$this->file,
|
||||
$args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add license field to settings, unless the extension is included in the user's pass.
|
||||
*
|
||||
* @param array $settings
|
||||
* @return array
|
||||
*/
|
||||
public function settings( $settings ) {
|
||||
if ( $this->is_pro_license && $this->is_included_in_pass() ) {
|
||||
return $settings;
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
$settings,
|
||||
array(
|
||||
array(
|
||||
'id' => "{$this->item_shortname}_license_key",
|
||||
'name' => $this->item_name,
|
||||
'type' => 'license_key',
|
||||
'options' => array(
|
||||
'is_valid_license_option' => "{$this->item_shortname}_license_active",
|
||||
'item_id' => $this->item_id,
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if license key is valid once per week
|
||||
*
|
||||
* @since 2.5
|
||||
* @return void
|
||||
*/
|
||||
public function weekly_license_check() {
|
||||
|
||||
// Don't fire when saving settings.
|
||||
if ( ! empty( $_POST['edd_settings'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( empty( $this->license_key ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! edd_doing_cron() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// data to send in our API request
|
||||
$api_params = array(
|
||||
'edd_action' => 'check_license',
|
||||
'license' => $this->license_key,
|
||||
'item_name' => urlencode( $this->item_name ),
|
||||
'item_id' => $this->item_id,
|
||||
);
|
||||
|
||||
$api_handler = new API();
|
||||
$license_data = $api_handler->make_request( $api_params );
|
||||
if ( ! $license_data ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->pass_manager->maybe_set_pass_flag( $this->license_key, $license_data );
|
||||
$this->edd_license->save( $license_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin notices for errors.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function notices() {
|
||||
if ( ! $this->should_show_error_notice() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
EDD()->notices->add_notice(
|
||||
array(
|
||||
'id' => 'edd-missing-license',
|
||||
'class' => "error {$this->item_shortname}-license-error",
|
||||
'message' => sprintf(
|
||||
/* translators: 1. opening anchor tag; 2. closing anchor tag */
|
||||
__( 'You have invalid or expired license keys for Easy Digital Downloads. %1$sActivate License(s)%2$s', 'easy-digital-downloads' ),
|
||||
'<a href="' . esc_url( $this->get_license_tab_url() ) . '" class="button button-secondary">',
|
||||
'</a>'
|
||||
),
|
||||
'is_dismissible' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays message inline on plugin row that the license key is missing
|
||||
*
|
||||
* @since 2.5
|
||||
* @return void
|
||||
*/
|
||||
public function plugin_row_license_missing( $plugin_data, $version_info ) {
|
||||
static $showed_imissing_key_message = array();
|
||||
|
||||
if ( ! $this->is_license_valid() && empty( $showed_imissing_key_message[ $this->item_shortname ] ) ) {
|
||||
echo ' <strong><a href="' . esc_url( $this->get_license_tab_url() ) . '">' . esc_html__( 'Enter valid license key for automatic updates.', 'easy-digital-downloads' ) . '</a></strong>';
|
||||
$showed_imissing_key_message[ $this->item_shortname ] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds this plugin to the beta page
|
||||
*
|
||||
* @param array $products
|
||||
* @since 2.6.11
|
||||
* @return array
|
||||
*/
|
||||
public function register_beta_support( $products ) {
|
||||
$products[ $this->item_shortname ] = $this->item_name;
|
||||
|
||||
return $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL for the licensing tab.
|
||||
*
|
||||
* @since 3.1.1.4
|
||||
* @return string
|
||||
*/
|
||||
private function get_license_tab_url() {
|
||||
return edd_get_admin_url(
|
||||
array(
|
||||
'page' => 'edd-settings',
|
||||
'tab' => 'licenses',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the license is valid.
|
||||
*
|
||||
* @since 3.1.1.4
|
||||
* @return bool
|
||||
*/
|
||||
private function is_license_valid() {
|
||||
return ! empty( $this->license_key ) && 'valid' === $this->edd_license->license;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extension shortname.
|
||||
*
|
||||
* @since 3.1.1.4
|
||||
* @return string
|
||||
*/
|
||||
private function get_shortname() {
|
||||
return 'edd_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->item_name ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Maintain an array of active, licensed plugins that have a license key entered.
|
||||
* This is to help us more easily determine if the site has a license key entered
|
||||
* at all. Initializing it this way helps us limit the data to activated plugins only.
|
||||
* If we relied on the options table (`edd_%_license_active`) then we could accidentally
|
||||
* be picking up plugins that have since been deactivated.
|
||||
*
|
||||
* @see \EDD\Admin\Promos\Notices\License_Upgrade_Notice::__construct()
|
||||
*/
|
||||
private function update_global() {
|
||||
if ( empty( $this->license_key ) ) {
|
||||
return;
|
||||
}
|
||||
global $edd_licensed_products;
|
||||
if ( ! is_array( $edd_licensed_products ) ) {
|
||||
$edd_licensed_products = array();
|
||||
}
|
||||
$edd_licensed_products[] = $this->item_shortname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a given product is included in the customer's active pass.
|
||||
* Note this is nearly a copy of what's in EDD\Licensing\Traits\Controls\is_included_in_pass().
|
||||
*
|
||||
* @since 3.1.1.4
|
||||
* @return bool
|
||||
*/
|
||||
private function is_included_in_pass() {
|
||||
// All Access and lifetime passes can access everything.
|
||||
if ( $this->pass_manager->hasAllAccessPass() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$api = new \EDD\Admin\Extensions\ExtensionsAPI();
|
||||
$product_data = $api->get_product_data( array(), $this->item_id );
|
||||
if ( ! $product_data || empty( $product_data->categories ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->pass_manager->can_access_categories( $product_data->categories );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to determine if we should show the error notice.
|
||||
*
|
||||
* @since 3.1.1.4
|
||||
* @return bool
|
||||
*/
|
||||
private function should_show_error_notice() {
|
||||
|
||||
// Included in pass.
|
||||
if ( $this->is_included_in_pass() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Not a pro license, but valid.
|
||||
if ( ! $this->is_pro_license && $this->is_license_valid() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Current user lacks permissions.
|
||||
if ( ! current_user_can( 'manage_shop_settings' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// It's the licenses tab.
|
||||
if ( ! empty( $_GET['tab'] ) && 'licenses' === $_GET['tab'] ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,605 @@
|
||||
<?php
|
||||
/**
|
||||
* Custom update handler for EDD extensions.
|
||||
* Forked from the EDD_SL_Updater class, but customized for EDD.
|
||||
*
|
||||
* @since 3.1.1.4
|
||||
*/
|
||||
namespace EDD\Extensions;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Updater {
|
||||
|
||||
private $api_handler;
|
||||
private $api_url = '';
|
||||
private $api_data = array();
|
||||
private $plugin_file = '';
|
||||
private $name = '';
|
||||
private $slug = '';
|
||||
private $version = '';
|
||||
private $wp_override = false;
|
||||
private $beta = false;
|
||||
private $failed_request_cache_key;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @uses plugin_basename()
|
||||
* @uses hook()
|
||||
*
|
||||
* @param string $_plugin_file Path to the plugin file.
|
||||
* @param array $_api_data Optional data to send with API calls.
|
||||
*/
|
||||
public function __construct( $_plugin_file, $_api_data = null ) {
|
||||
|
||||
global $edd_plugin_data;
|
||||
|
||||
$this->api_handler = new \EDD\Licensing\API();
|
||||
$this->api_url = trailingslashit( $this->api_handler->get_url() );
|
||||
$this->api_data = $_api_data;
|
||||
$this->plugin_file = $_plugin_file;
|
||||
$this->name = plugin_basename( $_plugin_file );
|
||||
$this->slug = basename( $_plugin_file, '.php' );
|
||||
$this->version = $_api_data['version'];
|
||||
$this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false;
|
||||
$this->beta = ! empty( $this->api_data['beta'] ) ? true : false;
|
||||
$this->failed_request_cache_key = 'edd_sl_failed_http_' . md5( $this->api_url );
|
||||
|
||||
$edd_plugin_data[ $this->slug ] = $this->api_data;
|
||||
|
||||
// Set up hooks.
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up WordPress filters to hook into WP's update process.
|
||||
*
|
||||
* @uses add_filter()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
|
||||
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
|
||||
add_action( 'after_plugin_row', array( $this, 'show_update_notification' ), 10, 2 );
|
||||
add_action( 'admin_init', array( $this, 'show_changelog' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for Updates at the defined API endpoint and modify the update array.
|
||||
*
|
||||
* This function dives into the update API just when WordPress creates its update array,
|
||||
* then adds a custom API call and injects the custom plugin data retrieved from the API.
|
||||
* It is reassembled from parts of the native WordPress plugin update code.
|
||||
* See wp-includes/update.php line 121 for the original wp_update_plugins() function.
|
||||
*
|
||||
* @uses api_request()
|
||||
*
|
||||
* @param array $_transient_data Update array build by WordPress.
|
||||
* @return array Modified update array with custom plugin data.
|
||||
*/
|
||||
public function check_update( $_transient_data ) {
|
||||
|
||||
if ( ! is_object( $_transient_data ) ) {
|
||||
$_transient_data = new \stdClass();
|
||||
}
|
||||
|
||||
if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
|
||||
return $_transient_data;
|
||||
}
|
||||
|
||||
$current = $this->get_repo_api_data();
|
||||
if ( false !== $current && is_object( $current ) && isset( $current->new_version ) ) {
|
||||
if ( version_compare( $this->version, $current->new_version, '<' ) ) {
|
||||
$_transient_data->response[ $this->name ] = $current;
|
||||
} else {
|
||||
// Populating the no_update information is required to support auto-updates in WordPress 5.5.
|
||||
$_transient_data->no_update[ $this->name ] = $current;
|
||||
}
|
||||
}
|
||||
$_transient_data->last_checked = time();
|
||||
$_transient_data->checked[ $this->name ] = $this->version;
|
||||
|
||||
return $_transient_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get repo API data from store.
|
||||
* Save to cache.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_repo_api_data() {
|
||||
$version_info = $this->get_cached_version_info();
|
||||
|
||||
if ( false === $version_info ) {
|
||||
$version_info = $this->api_request(
|
||||
'plugin_latest_version',
|
||||
array(
|
||||
'slug' => $this->slug,
|
||||
'beta' => $this->beta,
|
||||
)
|
||||
);
|
||||
if ( ! $version_info ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// This is required for your plugin to support auto-updates in WordPress 5.5.
|
||||
$version_info->plugin = $this->name;
|
||||
$version_info->id = $this->name;
|
||||
$version_info->tested = $this->get_tested_version( $version_info );
|
||||
|
||||
$this->set_version_info_cache( $version_info );
|
||||
}
|
||||
|
||||
return $version_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin's tested version.
|
||||
*
|
||||
* @since 1.9.2
|
||||
* @param object $version_info
|
||||
* @return null|string
|
||||
*/
|
||||
private function get_tested_version( $version_info ) {
|
||||
|
||||
// There is no tested version.
|
||||
if ( empty( $version_info->tested ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Strip off extra version data so the result is x.y or x.y.z.
|
||||
list( $current_wp_version ) = explode( '-', get_bloginfo( 'version' ) );
|
||||
|
||||
// The tested version is greater than or equal to the current WP version, no need to do anything.
|
||||
if ( version_compare( $version_info->tested, $current_wp_version, '>=' ) ) {
|
||||
return $version_info->tested;
|
||||
}
|
||||
$current_version_parts = explode( '.', $current_wp_version );
|
||||
$tested_parts = explode( '.', $version_info->tested );
|
||||
|
||||
// The current WordPress version is x.y.z, so update the tested version to match it.
|
||||
if ( isset( $current_version_parts[2] ) && $current_version_parts[0] === $tested_parts[0] && $current_version_parts[1] === $tested_parts[1] ) {
|
||||
$tested_parts[2] = $current_version_parts[2];
|
||||
}
|
||||
|
||||
return implode( '.', $tested_parts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the update notification on multisite subsites.
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $plugin
|
||||
*/
|
||||
public function show_update_notification( $file, $plugin ) {
|
||||
|
||||
// Return early if in the network admin, or if this is not a multisite install.
|
||||
if ( is_network_admin() || ! is_multisite() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Allow single site admins to see that an update is available.
|
||||
if ( ! current_user_can( 'activate_plugins' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->name !== $file ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not print any message if update does not exist.
|
||||
$update_cache = get_site_transient( 'update_plugins' );
|
||||
|
||||
if ( ! isset( $update_cache->response[ $this->name ] ) ) {
|
||||
if ( ! is_object( $update_cache ) ) {
|
||||
$update_cache = new \stdClass();
|
||||
}
|
||||
$update_cache->response[ $this->name ] = $this->get_repo_api_data();
|
||||
}
|
||||
|
||||
// Return early if this plugin isn't in the transient->response or if the site is running the current or newer version of the plugin.
|
||||
if ( empty( $update_cache->response[ $this->name ] ) || version_compare( $this->version, $update_cache->response[ $this->name ]->new_version, '>=' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf(
|
||||
'<tr class="plugin-update-tr %3$s" id="%1$s-update" data-slug="%1$s" data-plugin="%2$s">',
|
||||
$this->slug,
|
||||
$file,
|
||||
in_array( $this->name, $this->get_active_plugins(), true ) ? 'active' : 'inactive'
|
||||
);
|
||||
|
||||
echo '<td colspan="3" class="plugin-update colspanchange">';
|
||||
echo '<div class="update-message notice inline notice-warning notice-alt"><p>';
|
||||
|
||||
$changelog_link = '';
|
||||
if ( ! empty( $update_cache->response[ $this->name ]->sections->changelog ) ) {
|
||||
$changelog_link = add_query_arg(
|
||||
array(
|
||||
'edd_sl_action' => 'view_plugin_changelog',
|
||||
'plugin' => urlencode( $this->name ),
|
||||
'slug' => urlencode( $this->slug ),
|
||||
'TB_iframe' => 'true',
|
||||
'width' => 77,
|
||||
'height' => 911,
|
||||
),
|
||||
self_admin_url( 'index.php' )
|
||||
);
|
||||
}
|
||||
$update_link = add_query_arg(
|
||||
array(
|
||||
'action' => 'upgrade-plugin',
|
||||
'plugin' => urlencode( $this->name ),
|
||||
),
|
||||
self_admin_url( 'update.php' )
|
||||
);
|
||||
|
||||
printf(
|
||||
/* translators: the plugin name. */
|
||||
esc_html__( 'There is a new version of %1$s available.', 'easy-digital-downloads' ),
|
||||
esc_html( $plugin['Name'] )
|
||||
);
|
||||
|
||||
if ( ! current_user_can( 'update_plugins' ) ) {
|
||||
echo ' ';
|
||||
esc_html_e( 'Contact your network administrator to install the update.', 'easy-digital-downloads' );
|
||||
} elseif ( empty( $update_cache->response[ $this->name ]->package ) && ! empty( $changelog_link ) ) {
|
||||
echo ' ';
|
||||
printf(
|
||||
/* translators: 1. opening anchor tag, do not translate 2. the new plugin version 3. closing anchor tag, do not translate. */
|
||||
__( '%1$sView version %2$s details%3$s.', 'easy-digital-downloads' ),
|
||||
'<a target="_blank" class="thickbox open-plugin-details-modal" href="' . esc_url( $changelog_link ) . '">',
|
||||
esc_html( $update_cache->response[ $this->name ]->new_version ),
|
||||
'</a>'
|
||||
);
|
||||
} elseif ( ! empty( $changelog_link ) ) {
|
||||
echo ' ';
|
||||
printf(
|
||||
__( '%1$sView version %2$s details%3$s or %4$supdate now%5$s.', 'easy-digital-downloads' ),
|
||||
'<a target="_blank" class="thickbox open-plugin-details-modal" href="' . esc_url( $changelog_link ) . '">',
|
||||
esc_html( $update_cache->response[ $this->name ]->new_version ),
|
||||
'</a>',
|
||||
'<a target="_blank" class="update-link" href="' . esc_url( wp_nonce_url( $update_link, 'upgrade-plugin_' . $file ) ) . '">',
|
||||
'</a>'
|
||||
);
|
||||
} else {
|
||||
printf(
|
||||
' %1$s%2$s%3$s',
|
||||
'<a target="_blank" class="update-link" href="' . esc_url( wp_nonce_url( $update_link, 'upgrade-plugin_' . $file ) ) . '">',
|
||||
esc_html__( 'Update now.', 'easy-digital-downloads' ),
|
||||
'</a>'
|
||||
);
|
||||
}
|
||||
|
||||
do_action( "in_plugin_update_message-{$file}", $plugin, $plugin );
|
||||
|
||||
echo '</p></div></td></tr>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugins active in a multisite network.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_active_plugins() {
|
||||
$active_plugins = (array) get_option( 'active_plugins' );
|
||||
$active_network_plugins = (array) get_site_option( 'active_sitewide_plugins' );
|
||||
|
||||
return array_merge( $active_plugins, array_keys( $active_network_plugins ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates information on the "View version x.x details" page with custom data.
|
||||
*
|
||||
* @uses api_request()
|
||||
*
|
||||
* @param mixed $_data
|
||||
* @param string $_action
|
||||
* @param object $_args
|
||||
* @return object $_data
|
||||
*/
|
||||
public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
|
||||
|
||||
if ( 'plugin_information' !== $_action ) {
|
||||
return $_data;
|
||||
}
|
||||
|
||||
if ( ! isset( $_args->slug ) || ( $_args->slug !== $this->slug ) ) {
|
||||
return $_data;
|
||||
}
|
||||
|
||||
$to_send = array(
|
||||
'slug' => $this->slug,
|
||||
'is_ssl' => is_ssl(),
|
||||
'fields' => array(
|
||||
'banners' => array(),
|
||||
'reviews' => false,
|
||||
'icons' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
// Get the transient where we store the api request for this plugin for 24 hours
|
||||
$edd_api_request_transient = $this->get_cached_version_info();
|
||||
|
||||
//If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
|
||||
if ( empty( $edd_api_request_transient ) ) {
|
||||
|
||||
$api_response = $this->api_request( 'plugin_information', $to_send );
|
||||
|
||||
// Expires in 3 hours
|
||||
$this->set_version_info_cache( $api_response );
|
||||
|
||||
if ( false !== $api_response ) {
|
||||
$_data = $api_response;
|
||||
}
|
||||
} else {
|
||||
$_data = $edd_api_request_transient;
|
||||
}
|
||||
|
||||
// Convert sections into an associative array, since we're getting an object, but Core expects an array.
|
||||
if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
|
||||
$_data->sections = $this->convert_object_to_array( $_data->sections );
|
||||
}
|
||||
|
||||
// Convert banners into an associative array, since we're getting an object, but Core expects an array.
|
||||
if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
|
||||
$_data->banners = $this->convert_object_to_array( $_data->banners );
|
||||
}
|
||||
|
||||
// Convert icons into an associative array, since we're getting an object, but Core expects an array.
|
||||
if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) {
|
||||
$_data->icons = $this->convert_object_to_array( $_data->icons );
|
||||
}
|
||||
|
||||
// Convert contributors into an associative array, since we're getting an object, but Core expects an array.
|
||||
if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) {
|
||||
$_data->contributors = $this->convert_object_to_array( $_data->contributors );
|
||||
}
|
||||
|
||||
if ( ! isset( $_data->plugin ) ) {
|
||||
$_data->plugin = $this->name;
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert some objects to arrays when injecting data into the update API
|
||||
*
|
||||
* Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON
|
||||
* decoding, they are objects. This method allows us to pass in the object and return an associative array.
|
||||
*
|
||||
* @since 3.6.5
|
||||
*
|
||||
* @param stdClass $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function convert_object_to_array( $data ) {
|
||||
if ( ! is_array( $data ) && ! is_object( $data ) ) {
|
||||
return array();
|
||||
}
|
||||
$new_data = array();
|
||||
foreach ( $data as $key => $value ) {
|
||||
$new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value;
|
||||
}
|
||||
|
||||
return $new_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the API and, if successfull, returns the object delivered by the API.
|
||||
*
|
||||
* @uses get_bloginfo()
|
||||
* @uses wp_remote_get()
|
||||
* @uses is_wp_error()
|
||||
*
|
||||
* @param string $_action The requested action.
|
||||
* @param array $_data Parameters for the API action.
|
||||
* @return false|object
|
||||
*/
|
||||
private function api_request( $_action, $_data ) {
|
||||
$data = array_merge( $this->api_data, $_data );
|
||||
|
||||
if ( $data['slug'] !== $this->slug ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->request_recently_failed() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->get_version_from_remote();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a request has recently failed.
|
||||
*
|
||||
* @since 1.9.1
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function request_recently_failed() {
|
||||
$failed_request_details = get_option( $this->failed_request_cache_key );
|
||||
|
||||
// Request has never failed.
|
||||
if ( empty( $failed_request_details ) || ! is_numeric( $failed_request_details ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Request previously failed, but the timeout has expired.
|
||||
* This means we're allowed to try again.
|
||||
*/
|
||||
if ( time() > $failed_request_details ) {
|
||||
delete_option( $this->failed_request_cache_key );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a failed HTTP request for this API URL.
|
||||
* We set a timestamp for 1 hour from now. This prevents future API requests from being
|
||||
* made to this domain for 1 hour. Once the timestamp is in the past, API requests
|
||||
* will be allowed again. This way if the site is down for some reason we don't bombard
|
||||
* it with failed API requests.
|
||||
*
|
||||
* @see EDD_SL_Plugin_Updater::request_recently_failed
|
||||
*
|
||||
* @since 1.9.1
|
||||
*/
|
||||
private function log_failed_request() {
|
||||
update_option( $this->failed_request_cache_key, strtotime( '+1 hour' ), false );
|
||||
}
|
||||
|
||||
/**
|
||||
* If available, show the changelog for sites in a multisite install.
|
||||
*/
|
||||
public function show_changelog() {
|
||||
|
||||
if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' !== $_REQUEST['edd_sl_action'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( empty( $_REQUEST['plugin'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( empty( $_REQUEST['slug'] ) || $this->slug !== $_REQUEST['slug'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'update_plugins' ) ) {
|
||||
wp_die( esc_html__( 'You do not have permission to install plugin updates', 'easy-digital-downloads' ), esc_html__( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
$version_info = $this->get_repo_api_data();
|
||||
if ( isset( $version_info->sections ) ) {
|
||||
$sections = $this->convert_object_to_array( $version_info->sections );
|
||||
if ( ! empty( $sections['changelog'] ) ) {
|
||||
echo '<div style="background:#fff;padding:10px;">' . wp_kses_post( $sections['changelog'] ) . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current version information from the remote site.
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
private function get_version_from_remote() {
|
||||
|
||||
$request = $this->api_handler->make_request( $this->get_api_params() );
|
||||
|
||||
if ( $request && isset( $request->sections ) ) {
|
||||
$request->sections = maybe_unserialize( $request->sections );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( isset( $request->banners ) ) {
|
||||
$request->banners = maybe_unserialize( $request->banners );
|
||||
}
|
||||
|
||||
if ( isset( $request->icons ) ) {
|
||||
$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, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parameters for the API request.
|
||||
*
|
||||
* @since 3.1.1.4
|
||||
* @return array
|
||||
*/
|
||||
private function get_api_params() {
|
||||
return array(
|
||||
'edd_action' => 'get_version',
|
||||
'license' => ! empty( $this->api_data['license'] ) ? $this->api_data['license'] : '',
|
||||
'item_id' => isset( $this->api_data['item_id'] ) ? $this->api_data['item_id'] : false,
|
||||
'version' => isset( $this->api_data['version'] ) ? $this->api_data['version'] : false,
|
||||
'slug' => $this->slug,
|
||||
'beta' => $this->beta,
|
||||
'php_version' => phpversion(),
|
||||
'wp_version' => get_bloginfo( 'version' ),
|
||||
'easy-digital-downloads_version' => EDD_VERSION,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ) );
|
||||
}
|
||||
}
|
@ -22,6 +22,18 @@ class API {
|
||||
*/
|
||||
private $api_url = 'https://easydigitaldownloads.com/edd-sl-api';
|
||||
|
||||
/**
|
||||
* The class constructor.
|
||||
*
|
||||
* @since 3.1.1.4
|
||||
* @param null|string $url Optional; used only for requests to non-EDD sites.
|
||||
*/
|
||||
public function __construct( $url = null ) {
|
||||
if ( ! empty( $url ) ) {
|
||||
$this->api_url = $url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the API URL.
|
||||
*
|
||||
|
@ -63,15 +63,16 @@ class Ajax implements SubscriberInterface {
|
||||
);
|
||||
}
|
||||
|
||||
$this->name = filter_input( INPUT_POST, 'item_name', FILTER_SANITIZE_SPECIAL_CHARS );
|
||||
$api_params = array(
|
||||
'edd_action' => 'activate_license',
|
||||
'license' => $this->license_key,
|
||||
'item_name' => $this->name,
|
||||
'item_id' => filter_input( INPUT_POST, 'item_id', FILTER_SANITIZE_NUMBER_INT ),
|
||||
$this->name = filter_input( INPUT_POST, 'item_name', FILTER_SANITIZE_SPECIAL_CHARS );
|
||||
$api_params = array(
|
||||
'edd_action' => 'activate_license',
|
||||
'license' => $this->license_key,
|
||||
'item_name' => $this->name,
|
||||
'item_id' => filter_input( INPUT_POST, 'item_id', FILTER_SANITIZE_NUMBER_INT ),
|
||||
'environment' => function_exists( 'wp_get_environment_type' ) ? wp_get_environment_type() : 'production',
|
||||
);
|
||||
|
||||
$api = new API();
|
||||
$custom_api = filter_input( INPUT_POST, 'api', FILTER_SANITIZE_URL );
|
||||
$api = new API( $custom_api );
|
||||
$license_data = $api->make_request( $api_params );
|
||||
|
||||
if ( empty( $license_data->success ) ) {
|
||||
@ -141,11 +142,13 @@ class Ajax implements SubscriberInterface {
|
||||
$this->license = new License( $this->name );
|
||||
$this->license_key = $this->license->key;
|
||||
$api_params = array(
|
||||
'edd_action' => 'deactivate_license',
|
||||
'license' => $this->license_key,
|
||||
'item_id' => urlencode( $item_id ),
|
||||
'edd_action' => 'deactivate_license',
|
||||
'license' => $this->license_key,
|
||||
'item_id' => urlencode( $item_id ),
|
||||
'environment' => function_exists( 'wp_get_environment_type' ) ? wp_get_environment_type() : 'production',
|
||||
);
|
||||
$api = new API();
|
||||
$custom_api = filter_input( INPUT_POST, 'api', FILTER_SANITIZE_URL );
|
||||
$api = new API( $custom_api );
|
||||
$license_data = $api->make_request( $api_params );
|
||||
|
||||
$this->license->save( $license_data );
|
||||
|
@ -186,21 +186,7 @@ class Messages {
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( ! empty( $this->license_data['license_key'] ) ) {
|
||||
$error = ! empty( $this->license->error ) ? $this->license->error : __( 'unknown_error', 'easy-digital-downloads' );
|
||||
$message = sprintf(
|
||||
/* translators: 1. the error code; 2. opening link tag; 3. closing link tag. */
|
||||
__( 'There was an error with this license key: %1$s. Please %2$scontact our support team%3$s.', 'easy-digital-downloads' ),
|
||||
'<code>' . $error . '</code>',
|
||||
'<a href="https://easydigitaldownloads.com/support">',
|
||||
'</a>'
|
||||
);
|
||||
} else {
|
||||
$message = sprintf(
|
||||
/* translators: the extension name. */
|
||||
__( 'Unlicensed: currently not receiving updates.', 'easy-digital-downloads' )
|
||||
);
|
||||
}
|
||||
$message = __( 'Unlicensed: currently not receiving updates.', 'easy-digital-downloads' );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -89,8 +89,12 @@ class Settings {
|
||||
data-name="<?php echo esc_attr( $this->args['name'] ); ?>"
|
||||
data-key="<?php echo esc_attr( $this->args['id'] ); ?>"
|
||||
/>
|
||||
|
||||
<?php
|
||||
if ( ! empty( $this->args['options']['api_url'] ) ) {
|
||||
?>
|
||||
<input type="hidden" name="apiurl" value="<?php echo esc_url( $this->args['options']['api_url'] ); ?>" />
|
||||
<?php
|
||||
}
|
||||
$this->get_actions( $this->license->license, true );
|
||||
?>
|
||||
</div>
|
||||
|
@ -207,7 +207,7 @@ trait Controls {
|
||||
private function is_included_in_pass() {
|
||||
$pass_manager = $this->get_pass_manager();
|
||||
// All Access and lifetime passes can access everything.
|
||||
if ( $pass_manager->hasAllAccessPass() ) {
|
||||
if ( $pass_manager->hasAllAccessPass() && empty( $this->args['options']['api_url'] ) ) {
|
||||
return true;
|
||||
}
|
||||
// If we don't know the item ID we can't assume anything.
|
||||
|
Reference in New Issue
Block a user