updated plugin Easy Digital Downloads version 3.1.1.2

This commit is contained in:
2023-03-17 22:34:04 +00:00
committed by Gitium
parent e8a66564bd
commit 19e086d1c4
647 changed files with 20986 additions and 27305 deletions

View File

@ -1,172 +0,0 @@
<?php
/**
* Promo Handler
*
* Handles logic for displaying and dismissing promotional notices.
*
* @package easy-digital-downloads
* @copyright Copyright (c) 2021, Sandhills Development, LLC
* @license GPL2+
* @since 2.10.6
*/
namespace EDD\Admin\Promos;
use EDD\Admin\Promos\Notices\Notice;
use Sandhills\Utils\Persistent_Dismissible;
class PromoHandler {
/**
* Registered notices.
*
* @var string[]
*/
private $notices = array(
'\\EDD\\Admin\\Promos\\Notices\\License_Upgrade_Notice',
'\\EDD\\Admin\\Promos\\Notices\\Five_Star_Review_Dashboard',
'\\EDD\\Admin\\Promos\\Notices\\Five_Star_Review_Settings',
);
/**
* Notices constructor.
*/
public function __construct() {
add_action( 'wp_ajax_edd_dismiss_promo_notice', array( $this, 'dismiss_notice' ) );
$this->load_notices();
}
/**
* Loads and displays all registered promotional notices.
*
* @since 2.10.6
*/
private function load_notices() {
require_once EDD_PLUGIN_DIR . 'includes/admin/promos/notices/abstract-notice.php';
foreach ( $this->notices as $notice_class_name ) {
if ( ! class_exists( $notice_class_name ) ) {
$file_name = strtolower( str_replace( '_', '-', basename( str_replace( '\\', '/', $notice_class_name ) ) ) );
$file_path = EDD_PLUGIN_DIR . 'includes/admin/promos/notices/class-' . $file_name . '.php';
if ( file_exists( $file_path ) ) {
require_once $file_path;
}
}
if ( ! class_exists( $notice_class_name ) ) {
continue;
}
add_action( $notice_class_name::DISPLAY_HOOK, function () use ( $notice_class_name ) {
/** @var Notice $notice */
$notice = new $notice_class_name();
if ( $notice->should_display() ) {
$notice->display();
}
}, $notice_class_name::DISPLAY_PRIORITY );
}
}
/**
* Determines whether or not a notice has been dismissed.
*
* @since 2.10.6
*
* @param string $id ID of the notice to check.
*
* @return bool
*/
public static function is_dismissed( $id ) {
$is_dismissed = (bool) Persistent_Dismissible::get( array(
'id' => 'edd-' . $id
) );
return true === $is_dismissed;
}
/**
* Dismisses a notice.
*
* @since 2.10.6
*
* @param string $id ID of the notice to dismiss.
* @param int $dismissal_length Number of seconds to dismiss the notice for, or `0` for forever.
*/
public static function dismiss( $id, $dismissal_length = 0 ) {
Persistent_Dismissible::set( array(
'id' => 'edd-' . $id,
'life' => $dismissal_length
) );
}
/**
* AJAX callback for dismissing a notice.
*
* @since 2.10.6
*/
public function dismiss_notice() {
$notice_id = ! empty( $_POST['notice_id'] ) ? sanitize_text_field( $_POST['notice_id'] ) : false;
if ( empty( $notice_id ) ) {
wp_send_json_error( __( 'Missing notice ID.', 'easy-digital-downloads' ), 400 );
}
if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'edd-dismiss-notice-' . sanitize_key( $_POST['notice_id'] ) ) ) {
wp_send_json_error( __( 'You do not have permission to perform this action.', 'easy-digital-downloads' ), 403 );
}
$notice_class_name = $this->get_notice_class_name( $notice_id );
// No matching notice class was found.
if ( ! $notice_class_name ) {
wp_send_json_error( __( 'You do not have permission to perform this action.', 'easy-digital-downloads' ), 403 );
}
// Check whether the current user can dismiss the notice.
if ( ! defined( $notice_class_name . '::CAPABILITY' ) || ! current_user_can( $notice_class_name::CAPABILITY ) ) {
wp_send_json_error( __( 'You do not have permission to perform this action.', 'easy-digital-downloads' ), 403 );
}
$dismissal_length = ! empty( $_POST['lifespan'] ) ? absint( $_POST['lifespan'] ) : 0;
self::dismiss( sanitize_key( $_POST['notice_id'] ), $dismissal_length );
wp_send_json_success();
}
/**
* Gets the notice class name for a given notice ID.
*
* @since 2.11.4
* @param string $notice_id The notice ID to match.
* @return bool|string The class name or false if no matching class was found.
*/
private function get_notice_class_name( $notice_id ) {
$notice_class_name = false;
// Look through the registered notice classes for the one being dismissed.
foreach ( $this->notices as $notice_class_to_check ) {
if ( ! class_exists( $notice_class_to_check ) ) {
$file_name = strtolower( str_replace( '_', '-', basename( str_replace( '\\', '/', $notice_class_to_check ) ) ) );
$file_path = EDD_PLUGIN_DIR . 'includes/admin/promos/notices/class-' . $file_name . '.php';
if ( file_exists( $file_path ) ) {
require_once $file_path;
}
}
if ( ! class_exists( $notice_class_to_check ) ) {
continue;
}
$notice = new $notice_class_to_check();
if ( $notice->get_id() === $notice_id ) {
$notice_class_name = $notice_class_to_check;
break;
}
}
return $notice_class_name;
}
}
new PromoHandler();

View File

@ -1,125 +0,0 @@
<?php
/**
* Notice
*
* @package easy-digital-downloads
* @copyright Copyright (c) 2021, Sandhills Development, LLC
* @license GPL2+
* @since 2.10.6
*/
namespace EDD\Admin\Promos\Notices;
use EDD\Admin\Promos\PromoHandler;
abstract class Notice {
/**
* Action hook for displaying the notice.
*/
const DISPLAY_HOOK = 'admin_notices';
/**
* The priority for the display hook.
*/
const DISPLAY_PRIORITY = 10;
/**
* Type of promotional notice.
*/
const TYPE = 'top-of-page';
/**
* Whether or not the notice can be dismissed.
*/
const DISMISSIBLE = true;
/**
* The capability required to view/dismiss the notice.
*/
const CAPABILITY = 'manage_options';
/**
* Displays the notice content.
*
* @return void
*/
abstract protected function _display();
/**
* Generates a unique ID for this notice.
* It's the class name (without the namespace) and with underscores converted to hyphens.
*
* @since 2.10.6
*
* @return string
*/
public function get_id() {
return strtolower( str_replace( '_', '-', basename( str_replace( '\\', '/', get_class( $this ) ) ) ) );
}
/**
* Determines whether or not the notice should be displayed.
* Typically individual notices should not override this method, as it combines
* a dismissal check and custom display logic (`_should_display()`). Custom logic
* should go in `_should_display()`.
*
* @since 2.10.6
*
* @return bool
*/
public function should_display() {
return current_user_can( static::CAPABILITY ) && ! PromoHandler::is_dismissed( $this->get_id() ) && $this->_should_display();
}
/**
* Duration (in seconds) that the notice is dismissed for.
* `0` means it's dismissed permanently.
*
* @return int
*/
public static function dismiss_duration() {
return 0;
}
/**
* Individual notices can override this method to control display logic.
*
* @since 2.10.6
*
* @return bool
*/
protected function _should_display() {
return true;
}
/**
* Displays the notice.
* Individual notices typically should not override this method, as it contains
* all the notice wrapper logic. Instead, notices should override `_display()`
*
* @since 2.10.6
* @return void
*/
public function display() {
?>
<div
id="edd-admin-notice-<?php echo esc_attr( $this->get_id() ); ?>"
class="edd-admin-notice-<?php echo esc_attr( sanitize_html_class( static::TYPE ) ); ?> edd-promo-notice"
data-nonce="<?php echo esc_attr( wp_create_nonce( 'edd-dismiss-notice-' . $this->get_id() ) ); ?>"
data-id="<?php echo esc_attr( $this->get_id() ); ?>"
data-lifespan="<?php echo esc_attr( static::dismiss_duration() ); ?>"
>
<?php $this->_display(); ?>
<?php if ( static::DISMISSIBLE ) : ?>
<button class="button-link edd-promo-notice-dismiss">
&times;
<span class="screen-reader-text"><?php esc_html_e( 'Dismiss notice', 'easy-digital-downloads' ); ?></span>
</button>
<?php endif; ?>
</div>
<?php
}
}

View File

@ -160,10 +160,14 @@ class Five_Star_Review_Dashboard extends Notice {
if ( ! is_numeric( $activated ) || ( $activated + ( DAY_IN_SECONDS * 30 ) ) > time() ) {
return false;
}
// @todo Change this to edd_count_orders in 3.0
$payments = edd_count_payments();
$orders = edd_count_orders(
array(
'type' => 'sale',
'status__in' => edd_get_complete_order_statuses(),
)
);
return isset( $payments->publish ) && $payments->publish >= 15;
return $orders >= 15;
}
/**

View File

@ -1,266 +0,0 @@
<?php
/**
* License Upgrade Notice
*
* @package easy-digital-downloads
* @copyright Copyright (c) 2021, Sandhills Development, LLC
* @license GPL2+
* @since 2.10.6
*/
namespace EDD\Admin\Promos\Notices;
use EDD\Admin\Pass_Manager;
class License_Upgrade_Notice extends Notice {
const DISPLAY_HOOK = 'in_admin_header';
/**
* Number of EDD license keys that have been entered.
* Not validated to make sure they're actually active; this is
* just an indicator if any licenses exist at all.
*
* @var array
*/
private $number_license_keys;
/**
* @var Pass_Manager
*/
private $pass_manager;
/**
* License_Upgrade_Notice constructor.
*/
public function __construct() {
global $edd_licensed_products;
$this->number_license_keys = is_array( $edd_licensed_products ) ? count( $edd_licensed_products ) : 0;
$this->pass_manager = new Pass_Manager();
}
/**
* This notice lasts 90 days.
*
* @return int
*/
public static function dismiss_duration() {
return 3 * MONTH_IN_SECONDS;
}
/**
* Determines if the current page is an EDD admin page.
*
* @return bool
*/
private function is_edd_admin_page() {
if ( defined( 'EDD_DOING_TESTS' ) && EDD_DOING_TESTS ) {
return true;
}
$screen = get_current_screen();
if ( ! $screen instanceof \WP_Screen || 'dashboard' === $screen->id || ! edd_is_admin_page( '', '', false ) ) {
return false;
}
return true;
}
/**
* @inheritDoc
*
* @return bool
*/
protected function _should_display() {
if ( ! $this->is_edd_admin_page() ) {
return false;
}
// Someone with no license keys entered always sees a notice.
if ( 0 === $this->number_license_keys ) {
return true;
}
// If we have no pass data yet, don't show the notice because we don't yet know what it should say.
if ( ! $this->pass_manager->has_pass_data ) {
return false;
}
// If someone has an extended pass or higher, and has an active AffiliateWP license, don't show.
try {
if (
$this->pass_manager->has_pass() &&
Pass_Manager::pass_compare( $this->pass_manager->highest_pass_id, Pass_Manager::EXTENDED_PASS_ID, '>=' ) &&
$this->has_affiliate_wp_license() &&
$this->has_mi_license()
) {
return false;
}
} catch ( \Exception $e ) {
return true;
}
return true;
}
/**
* Determines whether or not AffiliateWP is installed and has a license key.
*
* @since 2.10.6
*
* @return bool
*/
private function has_affiliate_wp_license() {
if ( ! function_exists( 'affiliate_wp' ) ) {
return false;
}
return (bool) affiliate_wp()->settings->get( 'license_key' );
}
/**
* Determines whether or not MonsterInsights is installed and has a license key.
*
* @since 2.11.6
*
* @return bool
*/
private function has_mi_license() {
if ( ! class_exists( 'MonsterInsights' ) ) {
return false;
}
$mi_license = \MonsterInsights::$instance->license->get_license_key();
return ! empty( $mi_license );
}
/**
* @inheritDoc
*/
protected function _display() {
try {
if ( 0 === $this->number_license_keys ) {
$utm_parameters = $this->query_args( 'core' );
$link_url = $this->build_url(
'https://easydigitaldownloads.com/lite-upgrade/',
$utm_parameters
);
$help_url = edd_link_helper(
'https://easydigitaldownloads.com/what-is-an-edd-pass/',
array(
'utm_medium' => 'top-promo',
'utm_content' => 'what-is-a-pass',
)
);
// No license keys active at all.
printf(
/* Translators: %1$s opening anchor tag; %2$s closing anchor tag */
__( 'You are using the free version of Easy Digital Downloads. %1$sPurchase a pass%2$s to get email marketing tools and recurring payments. %3$sAlready have a Pass?%4$s', 'easy-digital-downloads' ),
'<a href="' . $link_url . '" target="_blank">',
'</a>',
'<a href="' . $help_url . '" target="_blank">',
'</a>'
);
} elseif ( ! $this->pass_manager->highest_pass_id ) {
$utm_parameters = $this->query_args( 'extension-license' );
$link_url = $this->build_url(
'https://easydigitaldownloads.com/your-account/',
$utm_parameters
);
// Individual product license active, but no pass.
printf(
/* Translators: %1$s opening anchor tag; %2$s closing anchor tag */
__( 'For access to additional Easy Digital Downloads extensions to grow your store, consider %1$spurchasing a pass%2$s.', 'easy-digital-downloads' ),
'<a href="' . $link_url . '" target="_blank">',
'</a>'
);
} elseif ( Pass_Manager::pass_compare( $this->pass_manager->highest_pass_id, Pass_Manager::PERSONAL_PASS_ID, '=' ) ) {
$utm_parameters = $this->query_args( 'personal-pass' );
$link_url = $this->build_url(
'https://easydigitaldownloads.com/your-account/',
$utm_parameters
);
// Personal pass active.
printf(
/* Translators: %1$s opening anchor tag; %2$s closing anchor tag */
__( 'You are using Easy Digital Downloads with a Personal Pass. Consider %1$supgrading%2$s to get recurring payments and more.', 'easy-digital-downloads' ),
'<a href="' . $link_url . '" target="_blank">',
'</a>'
);
} elseif ( Pass_Manager::pass_compare( $this->pass_manager->highest_pass_id, Pass_Manager::EXTENDED_PASS_ID, '>=' ) ) {
if ( ! $this->has_affiliate_wp_license() ) {
$link_url = edd_link_helper(
'https://affiliatewp.com',
array(
'utm_medium' => 'top-promo',
'utm_content' => 'affiliate-wp',
)
);
printf(
/* Translators: %1$s opening anchor tag; %2$s closing anchor tag */
__( 'Grow your business and make more money with affiliate marketing. %1$sGet AffiliateWP%2$s', 'easy-digital-downloads' ),
'<a href="' . $link_url . '" target="_blank">',
'</a>'
);
} elseif( ! $this->has_mi_license() ) {
printf(
/* Translators: %1$s opening anchor tag; %2$s closing anchor tag */
__( 'Gain access to powerful insights to grow your traffic and revenue. %1$sGet MonsterInsights%2$s', 'easy-digital-downloads' ),
'<a href="' . esc_url( 'https://monsterinsights.com?utm_campaign=xsell&utm_source=eddplugin&utm_content=top-promo' ) . '" target="_blank">',
'</a>'
);
}
}
} catch ( \Exception $e ) {
// If we're in here, that means we have an invalid pass ID... what should we do? :thinking:.
}
}
/**
* Builds the UTM parameters for the URLs.
*
* @since 2.10.6
*
* @param string $upgrade_from License type upgraded from.
* @param string $source Current page.
*
* @return string[]
*/
private function query_args( $upgrade_from, $source = '' ) {
return array(
'utm_medium' => 'top-promo',
'utm_content' => 'upgrade-from-' . urlencode( $upgrade_from ),
);
}
/**
* Build a link with UTM parameters
*
* @since 3.1
*
* @param string $url The Base URL.
* @param array $utm_parameters The UTM tags for the URL.
*
* @return string
*/
private function build_url( $url, $utm_parameters ) {
return esc_url(
edd_link_helper(
$url,
$utm_parameters
)
);
}
}