esc_url_raw( edd_get_ajax_url() ),
'checkout_nonce' => wp_create_nonce( 'edd_checkout_nonce' ),
'checkout_error_anchor' => '#edd_purchase_submit',
'currency_sign' => edd_currency_filter(''),
'currency_pos' => edd_get_option( 'currency_position', 'before' ),
'decimal_separator' => edd_get_option( 'decimal_separator', '.' ),
'thousands_separator' => edd_get_option( 'thousands_separator', ',' ),
'no_gateway' => __( 'Please select a payment method', 'easy-digital-downloads' ),
'no_discount' => __( 'Please enter a discount code', 'easy-digital-downloads' ), // Blank discount code message
'enter_discount' => __( 'Enter discount', 'easy-digital-downloads' ),
'discount_applied' => __( 'Discount Applied', 'easy-digital-downloads' ), // Discount verified message
'no_email' => __( 'Please enter an email address before applying a discount code', 'easy-digital-downloads' ),
'no_username' => __( 'Please enter a username before applying a discount code', 'easy-digital-downloads' ),
'purchase_loading' => __( 'Please Wait...', 'easy-digital-downloads' ),
'complete_purchase' => edd_get_checkout_button_purchase_label(),
'taxes_enabled' => edd_use_taxes() ? '1' : '0',
'edd_version' => $version,
'current_page' => get_the_ID(),
) ) );
}
// Load AJAX scripts, if enabled
if ( ! edd_is_ajax_disabled() ) {
// Get position in cart of current download
$position = isset( $post->ID )
? edd_get_item_position_in_cart( $post->ID )
: -1;
if ( ( ! empty( $post->post_content ) && ( has_shortcode( $post->post_content, 'purchase_link' ) || has_shortcode( $post->post_content, 'downloads' ) ) ) || is_post_type_archive( 'download' ) ) {
$has_purchase_links = true;
} else {
$has_purchase_links = false;
}
wp_localize_script( 'edd-ajax', 'edd_scripts', apply_filters( 'edd_ajax_script_vars', array(
'ajaxurl' => esc_url_raw( edd_get_ajax_url() ),
'position_in_cart' => $position,
'has_purchase_links' => $has_purchase_links,
'already_in_cart_message' => __('You have already added this item to your cart','easy-digital-downloads' ), // Item already in the cart message
'empty_cart_message' => __('Your cart is empty','easy-digital-downloads' ), // Item already in the cart message
'loading' => __('Loading','easy-digital-downloads' ) , // General loading message
'select_option' => __('Please select an option','easy-digital-downloads' ) , // Variable pricing error with multi-purchase option enabled
'is_checkout' => edd_is_checkout() ? '1' : '0',
'default_gateway' => edd_get_default_gateway(),
'redirect_to_checkout' => ( edd_straight_to_checkout() || edd_is_checkout() ) ? '1' : '0',
'checkout_page' => esc_url_raw( edd_get_checkout_uri() ),
'permalinks' => get_option( 'permalink_structure' ) ? '1' : '0',
'quantities_enabled' => edd_item_quantities_enabled(),
'taxes_enabled' => edd_use_taxes() ? '1' : '0', // Adding here for widget, but leaving in checkout vars for backcompat
'current_page' => get_the_ID(),
) ) );
}
}
/**
* Load head styles
*
* Ensures download styling is still shown correctly if a theme is using the CSS template file
*
* @since 2.5
* @global $post
*/
function edd_load_head_styles() {
global $post;
// Bail if styles are disabled
if ( edd_get_option( 'disable_styles', false ) || ! is_object( $post ) ) {
return;
}
// Use minified libraries not debugging scripts
$suffix = is_rtl() ? '-rtl' : '';
$suffix .= edd_doing_script_debug() ? '' : '.min';
$file = 'edd' . $suffix . '.css';
$templates_dir = edd_get_theme_template_dir_name();
$child_theme_style_sheet = trailingslashit( get_stylesheet_directory() ) . $templates_dir . $file;
$child_theme_style_sheet_2 = trailingslashit( get_stylesheet_directory() ) . $templates_dir . 'edd.css';
$parent_theme_style_sheet = trailingslashit( get_template_directory() ) . $templates_dir . $file;
$parent_theme_style_sheet_2 = trailingslashit( get_template_directory() ) . $templates_dir . 'edd.css';
if ( has_shortcode( $post->post_content, 'downloads' ) &&
file_exists( $child_theme_style_sheet ) ||
file_exists( $child_theme_style_sheet_2 ) ||
file_exists( $parent_theme_style_sheet ) ||
file_exists( $parent_theme_style_sheet_2 )
) {
$has_css_template = apply_filters( 'edd_load_head_styles', true );
} else {
$has_css_template = false;
}
// Bail if no template
if ( empty( $has_css_template ) ) {
return;
}
?>
array(
'edd-admin-tools-export'
),
'dashboard' => array(),
'discounts' => array(),
'downloads' => array(),
'tools-export' => array(),
'tools-import' => array(),
'notes' => array(),
'orders' => array(
'edd-admin-notes',
'wp-util',
'wp-backbone',
),
// Backwards compatibility.
'payments' => array(),
'reports' => array(
'edd-chart-js',
),
'settings' => array(),
'tools' => array(
'edd-admin-tools-export'
),
'upgrades' => array()
);
foreach ( $admin_pages as $page => $deps ) {
wp_register_script(
'edd-admin-' . $page,
$js_dir . 'edd-admin-' . $page . '.js',
array_merge( $admin_deps, $deps ),
$version
);
}
}
add_action( 'admin_init', 'edd_register_admin_scripts' );
/**
* Register all admin area styles
*
* @since 3.0
*/
function edd_register_admin_styles() {
$css_dir = EDD_PLUGIN_URL . 'assets/css/';
$css_suffix = is_rtl() ? '-rtl.min.css' : '.min.css';
$version = edd_admin_get_script_version();
$deps = array( 'edd-admin' );
// Register styles
wp_register_style( 'jquery-chosen', $css_dir . 'chosen' . $css_suffix, array(), $version );
wp_register_style( 'jquery-ui-css', $css_dir . 'jquery-ui-fresh' . $css_suffix, array(), $version );
wp_register_style( 'edd-admin', $css_dir . 'edd-admin' . $css_suffix, array(), $version );
wp_register_style( 'edd-admin-menu', $css_dir . 'edd-admin-menu' . $css_suffix, array(), $version );
wp_register_style( 'edd-admin-chosen', $css_dir . 'edd-admin-chosen' . $css_suffix, $deps, $version );
wp_register_style( 'edd-admin-email-tags', $css_dir . 'edd-admin-email-tags' . $css_suffix, $deps, $version );
wp_register_style( 'edd-admin-datepicker', $css_dir . 'edd-admin-datepicker' . $css_suffix, $deps, $version );
wp_register_style( 'edd-admin-tax-rates', $css_dir . 'edd-admin-tax-rates' . $css_suffix, $deps, $version );
}
add_action( 'admin_init', 'edd_register_admin_styles' );
/**
* Print admin area scripts
*
* @since 3.0
*/
function edd_enqueue_admin_scripts( $hook = '' ) {
// Bail if not an EDD admin page
if ( ! edd_should_load_admin_scripts( $hook ) ) {
return;
}
// Enqueue media on EDD admin pages
wp_enqueue_media();
// Scripts to enqueue
$scripts = array(
'edd-admin-scripts',
'jquery-chosen',
'jquery-form',
'jquery-ui-datepicker',
'jquery-ui-dialog',
'jquery-ui-tooltip',
'media-upload',
'thickbox',
'wp-ajax-response',
'wp-color-picker',
);
// Loop through and enqueue the scripts
foreach ( $scripts as $script ) {
wp_enqueue_script( $script );
}
// Downloads page.
if ( edd_is_admin_page( 'download' ) ) {
wp_enqueue_script( 'edd-admin-downloads' );
}
// Upgrades Page
if ( in_array( $hook, array( 'edd-admin-upgrades', 'download_page_edd-tools' ) ) ) {
wp_enqueue_script( 'edd-admin-tools-export' );
wp_enqueue_script( 'edd-admin-upgrades' );
}
}
add_action( 'admin_enqueue_scripts', 'edd_enqueue_admin_scripts' );
/**
* Enqueue admin area styling.
*
* Always enqueue the menu styling. Only enqueue others on EDD pages.
*
* @since 3.0
*/
function edd_enqueue_admin_styles( $hook = '' ) {
// Always enqueue the admin menu CSS
wp_enqueue_style( 'edd-admin-menu' );
// Bail if not an EDD admin page
if ( ! edd_should_load_admin_scripts( $hook ) ) {
return;
}
// Styles to enqueue (in priority order)
$styles = array(
'jquery-chosen',
'thickbox',
'wp-jquery-ui-dialog',
'wp-color-picker',
'edd-admin',
'edd-admin-chosen',
'edd-admin-datepicker'
);
// Loop through and enqueue the scripts
foreach ( $styles as $style ) {
wp_enqueue_style( $style );
}
}
add_action( 'admin_enqueue_scripts', 'edd_enqueue_admin_styles' );
/**
* Localize all admin scripts
*
* @since 3.0
*/
function edd_localize_admin_scripts() {
$currency = edd_get_currency();
// Customize the currency on a few individual pages.
if ( function_exists( 'edd_is_admin_page' ) ) {
if ( edd_is_admin_page( 'reports' ) ) {
/*
* For reports, use the currency currently being filtered.
*/
$currency_filter = \EDD\Reports\get_filter_value( 'currencies' );
if ( ! empty( $currency_filter ) && array_key_exists( strtoupper( $currency_filter ), edd_get_currencies() ) ) {
$currency = strtoupper( $currency_filter );
}
} elseif ( edd_is_admin_page( 'payments' ) && ! empty( $_GET['id'] ) ) {
/*
* For orders & refunds, use the currency of the current order.
*/
$order = edd_get_order( absint( $_GET['id'] ) );
if ( $order instanceof \EDD\Orders\Order ) {
$currency = $order->currency;
}
}
}
// Admin scripts
wp_localize_script( 'edd-admin-scripts', 'edd_vars', array(
'post_id' => get_the_ID(),
'edd_version' => edd_admin_get_script_version(),
'currency' => $currency,
'currency_sign' => edd_currency_filter( '', $currency ),
'currency_pos' => edd_get_option( 'currency_position', 'before' ),
'currency_decimals' => edd_currency_decimal_filter( 2, $currency ),
'decimal_separator' => edd_get_option( 'decimal_separator', '.' ),
'thousands_separator' => edd_get_option( 'thousands_separator', ',' ),
'date_picker_format' => edd_get_date_picker_format( 'js' ),
'add_new_download' => __( 'Add New Download', 'easy-digital-downloads' ),
'use_this_file' => __( 'Use This File', 'easy-digital-downloads' ),
'quick_edit_warning' => __( 'Sorry, not available for variable priced products.', 'easy-digital-downloads' ),
'delete_payment' => __( 'Are you sure you want to delete this order?', 'easy-digital-downloads' ),
'delete_order_item' => __( 'Are you sure you want to delete this item?', 'easy-digital-downloads' ),
'delete_order_adjustment' => __( 'Are you sure you want to delete this adjustment?', 'easy-digital-downloads' ),
'delete_note' => __( 'Are you sure you want to delete this note?', 'easy-digital-downloads' ),
'delete_tax_rate' => __( 'Are you sure you want to delete this tax rate?', 'easy-digital-downloads' ),
'revoke_api_key' => __( 'Are you sure you want to revoke this API key?', 'easy-digital-downloads' ),
'regenerate_api_key' => __( 'Are you sure you want to regenerate this API key?', 'easy-digital-downloads' ),
'resend_receipt' => __( 'Are you sure you want to resend the purchase receipt?', 'easy-digital-downloads' ),
'disconnect_customer' => __( 'Are you sure you want to disconnect the WordPress user from this customer record?', 'easy-digital-downloads' ),
'copy_download_link_text' => __( 'Copy these links to your clipboard and give them to your customer', 'easy-digital-downloads' ),
'delete_payment_download' => sprintf( __( 'Are you sure you want to delete this %s?', 'easy-digital-downloads' ), edd_get_label_singular() ),
'type_to_search' => sprintf( __( 'Type to search %s', 'easy-digital-downloads' ), edd_get_label_plural() ),
'one_option' => sprintf( __( 'Choose a %s', 'easy-digital-downloads' ), edd_get_label_singular() ),
'one_or_more_option' => sprintf( __( 'Choose one or more %s', 'easy-digital-downloads' ), edd_get_label_plural() ),
'one_price_min' => __( 'You must have at least one price', 'easy-digital-downloads' ),
'one_field_min' => __( 'You must have at least one field', 'easy-digital-downloads' ),
'one_download_min' => __( 'Payments must contain at least one item', 'easy-digital-downloads' ),
'no_results_text' => __( 'No match for:', 'easy-digital-downloads'),
'numeric_item_price' => __( 'Item price must be numeric', 'easy-digital-downloads' ),
'numeric_item_tax' => __( 'Item tax must be numeric', 'easy-digital-downloads' ),
'numeric_quantity' => __( 'Quantity must be numeric', 'easy-digital-downloads' ),
'remove_text' => __( 'Remove', 'easy-digital-downloads' ),
'batch_export_no_class' => __( 'You must choose a method.', 'easy-digital-downloads' ),
'batch_export_no_reqs' => __( 'Required fields not completed.', 'easy-digital-downloads' ),
'reset_stats_warn' => __( 'Are you sure you want to reset your store? This process is not reversible. Please be sure you have a recent backup.', 'easy-digital-downloads' ),
'unsupported_browser' => __( 'We are sorry but your browser is not compatible with this kind of file upload. Please upgrade your browser.', 'easy-digital-downloads' ),
'show_advanced_settings' => __( 'Show advanced settings', 'easy-digital-downloads' ),
'hide_advanced_settings' => __( 'Hide advanced settings', 'easy-digital-downloads' ),
'no_downloads_error' => __( 'There are no downloads attached to this payment', 'easy-digital-downloads' ),
'wait' => __( 'Please wait …', 'easy-digital-downloads' ),
'test_email_save_changes' => __( 'You must save your changes to send the test email.', 'easy-digital-downloads' ),
// Features
'quantities_enabled' => edd_item_quantities_enabled(),
'taxes_enabled' => edd_use_taxes(),
'taxes_included' => edd_use_taxes() && edd_prices_include_tax(),
'new_media_ui' => apply_filters( 'edd_use_35_media_ui', 1 ),
'restBase' => rest_url( \EDD\API\v3\Endpoint::$namespace ),
'restNonce' => wp_create_nonce( 'wp_rest' ),
) );
wp_localize_script( 'edd-admin-upgrades', 'edd_admin_upgrade_vars', array(
'migration_complete' => esc_html__( 'Migration complete', 'easy-digital-downloads' )
) );
}
add_action( 'admin_enqueue_scripts', 'edd_localize_admin_scripts' );
/**
* Add `defer` to the AlpineJS script tag.
*/
add_filter( 'script_loader_tag', function( $url ) {
if ( false !== strpos( $url, EDD_PLUGIN_URL . 'assets/js/alpine.min.js' ) ) {
$url = str_replace( ' src', ' defer src', $url );
}
return $url;
} );
/**
* Admin Downloads Icon
*
* Echoes the CSS for the downloads post type icon.
*
* @since 1.0
* @since 2.6.11 Removed globals and CSS for custom icon
*/
function edd_admin_downloads_icon() {
$images_url = EDD_PLUGIN_URL . 'assets/images/';
$menu_icon = '\f316';
$icon_cpt_url = $images_url . 'edd-cpt.png';
$icon_cpt_2x_url = $images_url . 'edd-cpt-2x.png';
?>