updated plugin Easy Digital Downloads
version 3.1.1.2
This commit is contained in:
@ -18,9 +18,11 @@ function localize() {
|
||||
'wp-block-editor',
|
||||
'EDDBlocks',
|
||||
array(
|
||||
'current_user' => md5( $user->user_email ),
|
||||
'all_access' => function_exists( 'edd_all_access' ),
|
||||
'recurring' => function_exists( 'EDD_Recurring' ),
|
||||
'current_user' => md5( $user->user_email ),
|
||||
'all_access' => function_exists( 'edd_all_access' ),
|
||||
'recurring' => function_exists( 'EDD_Recurring' ),
|
||||
'is_pro' => edd_is_pro(),
|
||||
'no_redownload' => edd_no_redownload(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -28,17 +28,29 @@ function pages( $settings ) {
|
||||
|
||||
$pages = edd_get_pages();
|
||||
|
||||
// Login page.
|
||||
$settings['pages']['login_page'] = array(
|
||||
'id' => 'login_page',
|
||||
'name' => __( 'Login Page', 'easy-digital-downloads' ),
|
||||
'desc' => __( 'This page must include the EDD Login block. Setting this allows the front end form to be used for resetting passwords.', 'easy-digital-downloads' ),
|
||||
'type' => 'select',
|
||||
'options' => $pages,
|
||||
'chosen' => true,
|
||||
'placeholder' => __( 'Select a page', 'easy-digital-downloads' ),
|
||||
$login_description = __( 'This page must include the EDD Login block. Setting this allows the front end form to be used for resetting passwords.', 'easy-digital-downloads' );
|
||||
$login_description .= '<br />';
|
||||
$login_description .= sprintf(
|
||||
/* translators: 1. opening code tag, do not translate; 2. closing code tag, do not translate. */
|
||||
__( 'Do not use this with the %1$s[edd_login]%2$s shortcode; it does not support resetting passwords.', 'easy-digital-downloads' ),
|
||||
'<code>',
|
||||
'</code>'
|
||||
);
|
||||
|
||||
// Login page.
|
||||
$login_page = array(
|
||||
array(
|
||||
'id' => 'login_page',
|
||||
'name' => __( 'Login Page', 'easy-digital-downloads' ),
|
||||
'desc' => $login_description,
|
||||
'type' => 'select',
|
||||
'options' => $pages,
|
||||
'chosen' => true,
|
||||
'placeholder' => __( 'Select a page', 'easy-digital-downloads' ),
|
||||
),
|
||||
);
|
||||
array_splice( $settings['pages'], -1, 0, $login_page );
|
||||
|
||||
if ( ! empty( $settings['pages']['purchase_page']['desc'] ) ) {
|
||||
$description = __( 'This is the checkout page where customers will complete their purchases.', 'easy-digital-downloads' );
|
||||
$description .= '<br />';
|
||||
@ -169,3 +181,19 @@ function button_colors( $args ) {
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
add_filter( 'edd_settings_misc', __NAMESPACE__ . '\disable_redownload' );
|
||||
/**
|
||||
* Update the text for the `disable_redownload` setting.
|
||||
*
|
||||
* @since 2.0.4
|
||||
* @param array $settings
|
||||
* @return array
|
||||
*/
|
||||
function disable_redownload( $settings ) {
|
||||
if ( ! empty( $settings['file_downloads']['disable_redownload']['desc'] ) ) {
|
||||
$settings['file_downloads']['disable_redownload']['desc'] = __( 'Do not allow users to redownload items from their order history.', 'easy-digital-downloads' );
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
@ -86,6 +86,7 @@ function do_personal_info_forms( $block_attributes ) {
|
||||
<?php
|
||||
$forms = get_personal_info_forms( $block_attributes, $customer_info_complete );
|
||||
if ( ! empty( $forms ) && count( $forms ) > 1 ) {
|
||||
wp_enqueue_script( 'edd-blocks-checkout-forms' );
|
||||
$i = 0;
|
||||
echo '<div class="edd-blocks__checkout-forms">';
|
||||
foreach ( $forms as $id => $form ) {
|
||||
@ -165,11 +166,7 @@ function add_user_script() {
|
||||
return;
|
||||
}
|
||||
|
||||
// For guest users, enqueue the script to toggle the login/registration forms.
|
||||
$forms = get_personal_info_forms( array( 'show_register_form' => edd_get_option( 'show_register_form' ) ) );
|
||||
if ( ! empty( $forms ) && count( $forms ) > 1 ) {
|
||||
wp_enqueue_script( 'edd-blocks-checkout-forms', EDD_BLOCKS_URL . 'assets/js/checkout-forms.js', array( 'edd-checkout-global' ), EDD_VERSION, true );
|
||||
}
|
||||
wp_register_script( 'edd-blocks-checkout-forms', EDD_BLOCKS_URL . 'assets/js/checkout-forms.js', array( 'edd-checkout-global' ), EDD_VERSION, true );
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_nopriv_edd_blocks_swap_personal_info', __NAMESPACE__ . '\swap_form' );
|
||||
|
@ -148,7 +148,7 @@ function buy_button( $block_attributes = array() ) {
|
||||
wp_enqueue_style( 'edd-styles' );
|
||||
}
|
||||
|
||||
$output = sprintf( '<div class="%s">', implode( ' ', $classes ) );
|
||||
$output = sprintf( '<div class="%s">', esc_attr( implode( ' ', $classes ) ) );
|
||||
$output .= edd_get_purchase_link(
|
||||
array(
|
||||
'class' => implode( ' ', get_purchase_link_classes( $block_attributes ) ),
|
||||
|
@ -51,10 +51,13 @@ function get_block_classes( $block_attributes, $classes = array() ) {
|
||||
$classes[] = "align{$block_attributes['align']}";
|
||||
}
|
||||
if ( ! empty( $block_attributes['className'] ) ) {
|
||||
$classes[] = $block_attributes['className'];
|
||||
$additional_classes = explode( ' ', $block_attributes['className'] );
|
||||
if ( $additional_classes ) {
|
||||
$classes = array_merge( $classes, $additional_classes );
|
||||
}
|
||||
}
|
||||
|
||||
return array_filter( array_unique( $classes ) );
|
||||
return array_filter( array_unique( array_map( 'sanitize_html_class', $classes ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,3 +129,18 @@ function is_block_editor( $current_user_can = '' ) {
|
||||
|
||||
return hash_equals( md5( $user->user_email ), $is_block_editor ) && current_user_can( $current_user_can );
|
||||
}
|
||||
|
||||
add_action( 'send_headers', __NAMESPACE__ . '\update_headers' );
|
||||
/**
|
||||
* Prevents clickjacking by sending the X-Frame-Options header
|
||||
* when a page has either the checkout or login block.
|
||||
*
|
||||
* @since 2.0.5.1
|
||||
* @return void
|
||||
*/
|
||||
function update_headers() {
|
||||
if ( ! has_block( 'edd/checkout' ) && ! has_block( 'edd/login' ) && ! has_block( 'edd/register' ) ) {
|
||||
return;
|
||||
}
|
||||
header( 'X-Frame-Options: SAMEORIGIN' );
|
||||
}
|
||||
|
@ -26,15 +26,18 @@ add_action( 'init', __NAMESPACE__ . '\register' );
|
||||
*/
|
||||
function register() {
|
||||
$blocks = array(
|
||||
'order-history' => array(
|
||||
'order-history' => array(
|
||||
'render_callback' => __NAMESPACE__ . '\orders',
|
||||
),
|
||||
'confirmation' => array(
|
||||
'confirmation' => array(
|
||||
'render_callback' => __NAMESPACE__ . '\confirmation',
|
||||
),
|
||||
'receipt' => array(
|
||||
'receipt' => array(
|
||||
'render_callback' => __NAMESPACE__ . '\receipt',
|
||||
),
|
||||
'user-downloads' => array(
|
||||
'render_callback' => __NAMESPACE__ . '\downloads',
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( $blocks as $block => $args ) {
|
||||
@ -56,25 +59,7 @@ function orders( $block_attributes = array() ) {
|
||||
|
||||
if ( edd_user_pending_verification() ) {
|
||||
ob_start();
|
||||
if ( ! empty( $_GET['edd-verify-request'] ) ) :
|
||||
?>
|
||||
<p class="edd-account-pending edd_success">
|
||||
<?php esc_html_e( 'An email with an activation link has been sent.', 'easy-digital-downloads' ); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<p class="edd-account-pending">
|
||||
<?php
|
||||
printf(
|
||||
wp_kses_post(
|
||||
/* translators: 1. Opening anchor tag. 2. Closing anchor tag. */
|
||||
__( 'Your account is pending verification. Please click the link in your email to activate your account. No email? %1$sSend a new activation code.%2$s', 'easy-digital-downloads' )
|
||||
),
|
||||
'<a href="' . esc_url( edd_get_user_verification_request_url() ) . '">',
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
include EDD_BLOCKS_DIR . 'views/orders/pending.php';
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
@ -123,7 +108,7 @@ function confirmation( $block_attributes = array() ) {
|
||||
$session = Functions\get_purchase_session();
|
||||
if ( empty( $session['purchase_key'] ) ) {
|
||||
if ( Helpers\is_block_editor() ) {
|
||||
return '<p class="edd-alert edd-alert-info">' . esc_html( __( 'To view a sample confirmation screen, you need to have at least one order in your store.', 'easy-digital-downloads' ) ) . '</p>';
|
||||
return '<p class="edd-alert edd-alert-info">' . esc_html( __( 'To view a sample confirmation screen, you need to have at least one order in your store.', 'easy-digital-downloads' ) ) . '</p>';
|
||||
}
|
||||
|
||||
return '<p class="edd-alert edd-alert-error">' . esc_html( __( 'Your purchase session could not be retrieved.', 'easy-digital-downloads' ) ) . '</p>';
|
||||
@ -197,7 +182,7 @@ function receipt( $block_attributes = array() ) {
|
||||
edd_print_errors();
|
||||
|
||||
$order = edd_get_order_by( 'payment_key', $payment_key );
|
||||
$user_can_view = edd_can_view_receipt( $payment_key );
|
||||
$user_can_view = edd_can_view_receipt( $order );
|
||||
if ( ! $user_can_view ) {
|
||||
show_no_access_message( $order );
|
||||
|
||||
@ -313,3 +298,160 @@ function verify_guest_email( $data ) {
|
||||
}
|
||||
edd_set_error( 'edd-guest-error', __( 'Your email address could not be verified.', 'easy-digital-downloads' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the download history block.
|
||||
*
|
||||
* @since 2.0.5
|
||||
* @param array $block_attributes
|
||||
* @return string
|
||||
*/
|
||||
function downloads( $block_attributes = array() ) {
|
||||
if ( ! is_user_logged_in() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( edd_user_pending_verification() ) {
|
||||
ob_start();
|
||||
include EDD_BLOCKS_DIR . 'views/orders/pending.php';
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
$block_attributes = wp_parse_args(
|
||||
$block_attributes,
|
||||
array(
|
||||
'search' => false,
|
||||
'variations' => true,
|
||||
'nofiles' => __( 'No downloadable files found.', 'easy-digital-downloads' ),
|
||||
'hide_empty' => true,
|
||||
)
|
||||
);
|
||||
|
||||
$downloads = get_purchased_products( $block_attributes );
|
||||
if ( ! $downloads ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Set up classes.
|
||||
$classes = array(
|
||||
'wp-block-edd-user-downloads',
|
||||
'edd-blocks__user-downloads',
|
||||
);
|
||||
ob_start();
|
||||
?>
|
||||
<div class="<?php echo esc_attr( implode( ' ', array_filter( $classes ) ) ); ?>">
|
||||
<?php
|
||||
if ( $block_attributes['search'] && function_exists( '\\EDD\\Blocks\\Pro\\Search\\do_search' ) ) {
|
||||
\EDD\Blocks\Pro\Search\do_search();
|
||||
}
|
||||
?>
|
||||
<div class="edd-blocks__row edd-blocks__row-header edd-order-items__header">
|
||||
<div class="edd-blocks__row-label"><?php esc_html_e( 'Products', 'easy-digital-downloads' ); ?></div>
|
||||
<?php if ( ! edd_no_redownload() ) : ?>
|
||||
<div class="edd-blocks__row-label"><?php esc_html_e( 'Files', 'easy-digital-downloads' ); ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
ksort( $downloads );
|
||||
foreach ( $downloads as $name => $item ) {
|
||||
include EDD_BLOCKS_DIR . 'views/orders/downloads.php';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of products the user has purchased.
|
||||
*
|
||||
* @since 2.0.5
|
||||
* @param array The block attributes
|
||||
* @return false|array
|
||||
*/
|
||||
function get_purchased_products( $block_attributes ) {
|
||||
$args = array(
|
||||
'user_id' => get_current_user_id(),
|
||||
'fields' => 'ids',
|
||||
'status__in' => \edd_get_complete_order_statuses(),
|
||||
'number' => 9999,
|
||||
);
|
||||
if ( Helpers\is_block_editor() ) {
|
||||
$args['number'] = 50;
|
||||
unset( $args['user_id'] );
|
||||
}
|
||||
$order_ids = edd_get_orders( $args );
|
||||
if ( empty( $order_ids ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$items = edd_get_order_items(
|
||||
array(
|
||||
'order_id__in' => $order_ids,
|
||||
'number' => 99999,
|
||||
'status__in' => \edd_get_deliverable_order_item_statuses(),
|
||||
)
|
||||
);
|
||||
if ( empty( $items ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$downloads = array();
|
||||
foreach ( $items as $item ) {
|
||||
if ( edd_is_bundled_product( $item->product_id ) ) {
|
||||
$key = ! empty( $block_attributes['variations'] ) ? $item->product_name : edd_get_download_name( $item->product_id );
|
||||
if ( array_key_exists( $key, $downloads ) ) {
|
||||
continue;
|
||||
}
|
||||
$bundled_products = edd_get_bundled_products( $item->product_id, $item->price_id );
|
||||
foreach ( $bundled_products as $bundle_item ) {
|
||||
$product_id = edd_get_bundle_item_id( $bundle_item );
|
||||
$price_id = edd_get_bundle_item_price_id( $bundle_item );
|
||||
$key = edd_get_download_name( $product_id );
|
||||
$order_item_args = array(
|
||||
'order_id' => $item->order_id,
|
||||
'status' => $item->status,
|
||||
'product_id' => $product_id,
|
||||
'product_name' => $key,
|
||||
);
|
||||
if ( is_numeric( $price_id ) && edd_has_variable_prices( $product_id ) ) {
|
||||
if ( ! empty( $block_attributes['variations'] ) ) {
|
||||
$key = edd_get_download_name( $product_id, $price_id );
|
||||
$order_item_args['product_name'] = $key;
|
||||
} else {
|
||||
$download_files = edd_get_download_files( $product_id, $price_id );
|
||||
$conditions = wp_list_pluck( $download_files, 'condition' );
|
||||
if ( ! empty( $conditions ) && ! in_array( 'all', $conditions, true ) ) {
|
||||
$key = edd_get_download_name( $product_id, $price_id );
|
||||
$order_item_args['product_name'] = $key;
|
||||
}
|
||||
}
|
||||
$order_item_args['price_id'] = $price_id;
|
||||
}
|
||||
if ( array_key_exists( $key, $downloads ) ) {
|
||||
continue;
|
||||
}
|
||||
$downloads[ $key ] = new \EDD\Orders\Order_Item( $order_item_args );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$key = $item->product_name;
|
||||
if ( is_numeric( $item->price_id ) && edd_has_variable_prices( $item->product_id ) ) {
|
||||
if ( empty( $block_attributes['variations'] ) ) {
|
||||
$download_files = edd_get_download_files( $item->product_id, $item->price_id );
|
||||
$conditions = wp_list_pluck( $download_files, 'condition' );
|
||||
if ( empty( $conditions ) || in_array( 'all', $conditions, true ) ) {
|
||||
$key = edd_get_download_name( $item->product_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( array_key_exists( $key, $downloads ) ) {
|
||||
continue;
|
||||
}
|
||||
$downloads[ $key ] = $item;
|
||||
}
|
||||
|
||||
return ! empty( $downloads ) ? $downloads : false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user