You appear to be a bot. Output may be restricted
Description
Retrieve a states drop down
Usage
$void = edd_ajax_download_search();
Parameters
Returns
void
Source
File name: easy-digital-downloads/includes/ajax-functions.php
Lines:
1 to 98 of 98
function edd_ajax_download_search() { global $wpdb; $search = esc_sql( sanitize_text_field( $_GET['s'] ) ); $excludes = ( isset( $_GET['current_id'] ) ? (array) $_GET['current_id'] : array() ); $no_bundles = isset( $_GET['no_bundles'] ) ? filter_var( $_GET['no_bundles'], FILTER_VALIDATE_BOOLEAN ) : false; if( true === $no_bundles ) { $bundles = $wpdb->get_results( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_edd_product_type' AND meta_value = 'bundle';", ARRAY_A ); $bundles = wp_list_pluck( $bundles, 'post_id' ); $excludes = array_merge( $excludes, $bundles ); } $variations = isset( $_GET['variations'] ) ? filter_var( $_GET['variations'], FILTER_VALIDATE_BOOLEAN ) : false; $excludes = array_unique( array_map( 'absint', $excludes ) ); $exclude = implode( ",", $excludes ); $results = array(); // Setup the SELECT statement $select = "SELECT ID,post_title FROM $wpdb->posts "; // Setup the WHERE clause $where = "WHERE `post_type` = 'download' and `post_title` LIKE '%s' "; // If we have items to exclude, exclude them if( ! empty( $exclude ) ) { $where .= "AND `ID` NOT IN (" . $exclude . ") "; } if ( ! current_user_can( 'edit_products' ) ) { $status = apply_filters( 'edd_product_dropdown_status_nopriv', array( 'publish' ) ); } else { $status = apply_filters( 'edd_product_dropdown_status', array( 'publish', 'draft', 'private', 'future' ) ); } if ( is_array( $status ) && ! empty( $status ) ) { $status = array_map( 'sanitize_text_field', $status ); $status_in = "'" . join( "', '", $status ) . "'"; $where .= "AND `post_status` IN ({$status_in}) "; } else { $where .= "AND `post_status` = `publish` "; } // Limit the result sets $limit = "LIMIT 50"; $sql = $select . $where . $limit; $prepared_statement = $wpdb->prepare( $sql, '%' . $search . '%' ); $items = $wpdb->get_results( $prepared_statement ); if( $items ) { foreach( $items as $item ) { $results[] = array( 'id' => $item->ID, 'name' => $item->post_title ); if ( $variations && edd_has_variable_prices( $item->ID ) ) { $prices = edd_get_variable_prices( $item->ID ); foreach ( $prices as $key => $value ) { $name = ! empty( $value['name'] ) ? $value['name'] : ''; $amount = ! empty( $value['amount'] ) ? $value['amount'] : ''; $index = ! empty( $value['index'] ) ? $value['index'] : $key; if ( $name && $index ) { $results[] = array( 'id' => $item->ID . '_' . $key, 'name' => esc_html( $item->post_title . ': ' . $name ), ); } } } } } else { $results[] = array( 'id' => 0, 'name' => __( 'No results found', 'easy-digital-downloads' ) ); } echo json_encode( $results ); edd_die(); }