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

@ -344,12 +344,20 @@ function edd_ajax_update_cart_item_quantity() {
EDD()->cart->set_item_quantity( $download_id, $quantity, $options );
$subtotal = EDD()->cart->get_subtotal();
$taxes = EDD()->cart->get_tax();
$total = EDD()->cart->get_total();
$return = array(
'download_id' => $download_id,
'quantity' => EDD()->cart->get_item_quantity( $download_id, $options ),
'subtotal' => html_entity_decode( edd_currency_filter( edd_format_amount( EDD()->cart->get_subtotal() ) ), ENT_COMPAT, 'UTF-8' ),
'taxes' => html_entity_decode( edd_currency_filter( edd_format_amount( EDD()->cart->get_tax() ) ), ENT_COMPAT, 'UTF-8' ),
'total' => html_entity_decode( edd_currency_filter( edd_format_amount( EDD()->cart->get_total() ) ), ENT_COMPAT, 'UTF-8' )
'download_id' => $download_id,
'quantity' => EDD()->cart->get_item_quantity( $download_id, $options ),
'subtotal_raw' => $subtotal,
'taxes_raw' => $taxes,
'total_raw' => $total,
'subtotal' => html_entity_decode( edd_currency_filter( edd_format_amount( $subtotal ) ), ENT_COMPAT, 'UTF-8' ),
'taxes' => html_entity_decode( edd_currency_filter( edd_format_amount( $taxes ) ), ENT_COMPAT, 'UTF-8' ),
'total' => html_entity_decode( edd_currency_filter( edd_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ),
'discounts' => edd_get_cart_discounts_html(),
);
// Allow for custom cart item quantity handling
@ -588,174 +596,18 @@ add_action( 'wp_ajax_nopriv_edd_get_shop_states', 'edd_ajax_get_states_field' );
*
* @since 1.6
* @since 3.0 Use `get_posts()` instead of multiple direct queries (yay caching)
* @since 3.1.0.5 Uses EDD\Downloads\Search.
*
* @return void
*/
function edd_ajax_download_search() {
// We store the last search in a transient for 30 seconds. This _might_
// result in a race condition if 2 users are looking at the exact same time,
// but we'll worry about that later if that situation ever happens.
$args = get_transient( 'edd_download_search' );
// Parse args.
$search = wp_parse_args(
(array) $args,
array(
'text' => '',
'results' => array(),
)
);
// Get the search string.
$new_search = isset( $_GET['s'] )
? sanitize_text_field( $_GET['s'] )
: '';
// Limit to only alphanumeric characters, including unicode and spaces.
$new_search = preg_replace( '/[^\pL^\pN\pZ]/', ' ', $new_search );
// Bail early if the search text has not changed.
if ( $search['text'] === $new_search ) {
echo wp_json_encode( $search['results'] );
edd_die();
}
// Set the local static search variable.
$search['text'] = $new_search;
// Are we excluding the current ID?
$excludes = isset( $_GET['current_id'] )
? array_unique( array_map( 'absint', (array) $_GET['current_id'] ) )
: array();
// Are we excluding bundles?
$no_bundles = isset( $_GET['no_bundles'] )
? filter_var( $_GET['no_bundles'], FILTER_VALIDATE_BOOLEAN )
: false;
// Are we including variations?
$variations = isset( $_GET['variations'] )
? filter_var( $_GET['variations'], FILTER_VALIDATE_BOOLEAN )
: false;
$variations_only = isset( $_GET['variations_only'] )
? filter_var( $_GET['variations_only'], FILTER_VALIDATE_BOOLEAN )
: false;
// Are we including all statuses, or only public ones?
$status = ! current_user_can( 'edit_products' )
? apply_filters( 'edd_product_dropdown_status_nopriv', array( 'publish' ) )
: apply_filters( 'edd_product_dropdown_status', array( 'publish', 'draft', 'private', 'future' ) );
// Default query arguments.
$args = array(
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'download',
'posts_per_page' => 50,
'post_status' => implode( ',', $status ), // String.
'post__not_in' => $excludes, // Array.
'edd_search' => $new_search, // String.
'suppress_filters' => false,
);
// Maybe exclude bundles.
if ( true === $no_bundles ) {
$args['meta_query'] = array(
'relation' => 'OR',
array(
'key' => '_edd_product_type',
'value' => 'bundle',
'compare' => '!=',
),
array(
'key' => '_edd_product_type',
'value' => 'bundle',
'compare' => 'NOT EXISTS',
),
);
}
add_filter( 'posts_where', 'edd_ajax_filter_download_where', 10, 2 );
// Get downloads.
$items = get_posts( $args );
remove_filter( 'posts_where', 'edd_ajax_filter_download_where', 10, 2 );
// Pluck title & ID.
if ( ! empty( $items ) ) {
$items = wp_list_pluck( $items, 'post_title', 'ID' );
// Loop through all items...
foreach ( $items as $post_id => $title ) {
$product_title = $title;
// Look for variable pricing.
$prices = edd_get_variable_prices( $post_id );
if ( ! empty( $prices ) && ( false === $variations || ! $variations_only ) ) {
$title .= ' (' . __( 'All Price Options', 'easy-digital-downloads' ) . ')';
}
if ( empty( $prices ) || ! $variations_only ) {
// Add item to results array.
$search['results'][] = array(
'id' => $post_id,
'name' => $title,
);
}
// Maybe include variable pricing.
if ( ! empty( $variations ) && ! empty( $prices ) ) {
foreach ( $prices as $key => $value ) {
$name = ! empty( $value['name'] ) ? $value['name'] : '';
if ( ! empty( $name ) ) {
$search['results'][] = array(
'id' => $post_id . '_' . $key,
'name' => esc_html( $product_title . ': ' . $name ),
);
}
}
}
}
} else {
// Empty the results array.
$search['results'] = array();
}
// Update the transient.
set_transient( 'edd_download_search', $search, 30 );
// Output the results.
echo wp_json_encode( $search['results'] );
// Done!
edd_die();
$search = new EDD\Downloads\Search();
$search->ajax_search();
}
add_action( 'wp_ajax_edd_download_search', 'edd_ajax_download_search' );
add_action( 'wp_ajax_nopriv_edd_download_search', 'edd_ajax_download_search' );
/**
* Filters the WHERE SQL query for the edd_download_search.
* This searches the download titles only, not the excerpt/content.
*
* @since 3.1.0.2
* @param string $where
* @param WP_Query $wp_query
* @return string
*/
function edd_ajax_filter_download_where( $where, $wp_query ) {
$search = $wp_query->get( 'edd_search' );
if ( $search ) {
global $wpdb;
$search = $wpdb->esc_like( $search );
$where .= " AND {$wpdb->posts}.post_title LIKE '%{$search}%'";
}
return $where;
}
/**
* Search the customers database via AJAX
*