You appear to be a bot. Output may be restricted
Description
Retrieve a downloads drop down
Usage
$void = edd_ajax_download_search();
Parameters
Returns
void
Source
File name: easy-digital-downloads/includes/ajax-functions.php
Lines:
1 to 100 of 137
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'] ) : ''; // Bail early if the search text has not changed if ( $search['text'] === $new_search ) { echo 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' ) . ')'; }