post_type ) && 'revision' == $post->post_type ) { return; } if ( ! current_user_can( 'edit_product', $post_id ) ) { return; } edd_download_meta_box_fields_save( $post_id, $post ); } add_action( 'save_post', 'edd_download_meta_box_save', 10, 2 ); /** * Save post meta when the save_post action is called * * @since 3.2 * @param int $post_id Download (Post) ID. * @global array $post All the data of the the current post. * @return void */ function edd_download_meta_box_fields_save( $post_id, $post ) { if ( ! current_user_can( 'edit_product', $post_id ) ) { return; } // The default fields that get saved $fields = edd_download_metabox_fields(); foreach ( $fields as $field ) { if ( '_edd_default_price_id' == $field && edd_has_variable_prices( $post_id ) ) { if ( isset( $_POST[ $field ] ) ) { $new_default_price_id = ( ! empty( $_POST[ $field ] ) && is_numeric( $_POST[ $field ] ) ) || ( 0 === (int) $_POST[ $field ] ) ? (int) $_POST[ $field ] : 1; } else { $new_default_price_id = 1; } update_post_meta( $post_id, $field, $new_default_price_id ); } elseif ( '_edd_product_type' === $field && '0' === $_POST[ $field ] ) { // No value stored when product type is "default" ("0") for backwards compatibility. delete_post_meta( $post_id, '_edd_product_type' ); } else { $new = false; if ( ! empty( $_POST[ $field ] ) ) { $new = apply_filters( 'edd_metabox_save_' . $field, $_POST[ $field ] ); } if ( ! empty( $new ) ) { update_post_meta( $post_id, $field, $new ); } else { delete_post_meta( $post_id, $field ); } } } if ( edd_has_variable_prices( $post_id ) ) { $lowest = edd_get_lowest_price_option( $post_id ); update_post_meta( $post_id, 'edd_price', $lowest ); } do_action( 'edd_save_download', $post_id, $post ); } /** * Sanitize bundled products on save * * Ensures a user doesn't try and include a product's ID in the products bundled with that product * * @since 1.6 * * @param array $products * @return array */ function edd_sanitize_bundled_products_save( $products = array() ) { $products = array_map( function( $value ) { return preg_replace( '/[^0-9_]/', '', $value ); }, (array) $products ); foreach ( $products as $key => $value ) { $underscore_pos = strpos( $value, '_' ); if ( is_numeric( $underscore_pos ) ) { $product_id = substr( $value, 0, $underscore_pos ); } else { $product_id = $value; } if ( in_array( $product_id, array( 0, get_the_ID() ) ) ) { unset( $products[ $key ] ); } } $products = array_unique( $products ); return ! empty( $products ) ? array_combine( range( 1, count( $products ) ), array_values( $products ) ) : false; } add_filter( 'edd_metabox_save__edd_bundled_products', 'edd_sanitize_bundled_products_save' ); /** * Sanitize bundled products conditions on save * * @since 3.1 * * @param array $bundled_products_conditions * @return array */ function edd_sanitize_bundled_products_conditions_save( $bundled_products_conditions = array() ) { return ! empty( $bundled_products_conditions ) ? array_combine( range( 1, count( $bundled_products_conditions ) ), array_values( $bundled_products_conditions ) ) : false; } add_filter( 'edd_metabox_save__edd_bundled_products_conditions', 'edd_sanitize_bundled_products_conditions_save' ); /** * Don't save blank rows. * * When saving, check the price and file table for blank rows. * If the name of the price or file is empty, that row should not * be saved. * * @since 1.2.2 * @param array $new Array of all the meta values * @return array $new New meta value with empty keys removed */ function edd_metabox_save_check_blank_rows( $new ) { foreach ( $new as $key => $value ) { if ( empty( $value['name'] ) && empty( $value['amount'] ) && empty( $value['file'] ) ) unset( $new[ $key ] ); } return $new; } /** Download Configuration ****************************************************/ /** * Download Metabox * * Extensions (as well as the core plugin) can add items to the main download * configuration metabox via the `edd_meta_box_fields` action. * * @since 1.0 * @return void */ function edd_render_download_meta_box() { $post_id = get_the_ID(); /* * Output the price fields * @since 1.9 */ do_action( 'edd_meta_box_price_fields', $post_id ); /* * Output the price fields * * Left for backwards compatibility * */ do_action( 'edd_meta_box_fields', $post_id ); wp_nonce_field( basename( __FILE__ ), 'edd_download_meta_box_nonce' ); } /** * Download Files Metabox * * @since 1.9 * @return void */ function edd_render_files_meta_box() { /* * Output the files fields * @since 1.9 */ do_action( 'edd_meta_box_files_fields', get_the_ID() ); } /** * Download Settings Metabox * * @since 1.9 * @return void */ function edd_render_settings_meta_box() { /* * Output the files fields * @since 1.9 */ do_action( 'edd_meta_box_settings_fields', get_the_ID() ); } /** * Price Section * * If variable pricing is not enabled, simply output a single input box. * * If variable pricing is enabled, outputs a table of all current prices. * Extensions can add column heads to the table via the `edd_download_file_table_head` * hook, and actual columns via `edd_download_file_table_row` * * @since 1.0 * * @see edd_render_price_row() * * @param $post_id */ function edd_render_price_field( $post_id ) { $price = edd_get_download_price( $post_id ); $variable_pricing = edd_has_variable_prices( $post_id ); $prices = edd_get_variable_prices( $post_id ); $single_option_mode = edd_single_price_option_mode( $post_id ); $price_display = $variable_pricing ? ' style="display:none;"' : ''; $variable_display = $variable_pricing ? '' : ' style="display:none;"'; $currency_position = edd_get_option( 'currency_position', 'before' ); ?>

/>
>
'edd_price', 'id' => 'edd_price', 'value' => isset( $price ) ? esc_attr( edd_format_amount( $price ) ) : '', 'class' => 'edd-form-group__input edd-price-field', ); if ( 'before' === $currency_position ) { ?> html->text( $price_args ); } else { echo EDD()->html->text( $price_args ); ?>
>
html->checkbox( array( 'name' => '_edd_price_options_mode', 'current' => $single_option_mode, 'class' => 'edd-form-group__input', ) ); ?>
$value ) : $name = ( isset( $value['name'] ) && ! empty( $value['name'] ) ) ? $value['name'] : ''; $index = ( isset( $value['index'] ) && $value['index'] !== '' ) ? $value['index'] : $key; $amount = isset( $value['amount'] ) ? $value['amount'] : ''; $args = apply_filters( 'edd_price_row_args', compact( 'name', 'amount' ), $value ); ?>
null, 'amount' => null ); $args = wp_parse_args( $args, $defaults ); $default_price_id = edd_get_default_variable_price( $post_id ); $currency_position = edd_get_option( 'currency_position', 'before' ); $custom_price_options = isset( $wp_filter['edd_download_price_option_row'] ) ? true : false; ?>
' . esc_html( $key ) . '' ); ?> ' . __( 'Show advanced settings', 'easy-digital-downloads' ) . ''; } $actions['remove'] = '' . sprintf( __( 'Remove', 'easy-digital-downloads' ), esc_html( $key ) ) . '' . sprintf( __( 'Remove price option %s', 'easy-digital-downloads' ), esc_html( $key ) ) . ''; ?>
html->text( array( 'name' => 'edd_variable_prices[' . $key . '][name]', 'id' => 'edd_variable_prices-' . $key . '-name', 'value' => esc_attr( $args['name'] ), 'placeholder' => __( 'Option Name', 'easy-digital-downloads' ), 'class' => 'edd_variable_prices_name large-text' ) ); ?>
'edd_variable_prices[' . $key . '][amount]', 'id' => 'edd_variable_prices-' . $key . '-amount', 'value' => $args['amount'], 'placeholder' => edd_format_amount( 9.99 ), 'class' => 'edd-form-group__input edd-price-field', ); ?>
html->text( $price_args ); } else { echo EDD()->html->text( $price_args ); ?>
class="edd_repeatable_default_input" name="_edd_default_price_id" id="edd_default_price_id_" value="" />
html->select( array( 'options' => $types, 'name' => '_edd_product_type', 'id' => '_edd_product_type', 'selected' => $type, 'show_option_all' => false, 'show_option_none' => false, 'class' => 'edd-form-group__input', ) ); ?>
get_type(); $display = $type == 'bundle' ? '' : ' style="display:none;"'; $products = $download->get_bundled_downloads(); $variable_pricing = $download->has_variable_prices(); $variable_display = $variable_pricing ? '' : 'display:none;'; $variable_class = $variable_pricing ? ' has-variable-pricing' : ''; $prices = $download->get_prices(); $bundle_options = EDD()->html->get_products( array( 'bundles' => false, ) ); ?>
>
$product ) : ?>
html->product_dropdown( array( 'name' => '_edd_bundled_products[' . $index . ']', 'id' => 'edd_bundled_products_' . esc_attr( $index ), 'selected' => $product, 'multiple' => false, 'chosen' => true, 'products' => $bundle_options, 'variations' => true, 'show_variations_only' => false, 'class' => 'edd-form-group__input', ) ); ?>
$price ) { $options[ $price_key ] = $prices[ $price_key ]['name']; } } $price_assignments = edd_get_bundle_pricing_variations( $post_id ); if ( ! empty( $price_assignments[0] ) ) { $price_assignments = $price_assignments[0]; } $selected = isset( $price_assignments[ $index ] ) ? $price_assignments[ $index ] : null; echo EDD()->html->select( array( 'name' => '_edd_bundled_products_conditions[' . $index . ']', 'id' => 'edd_bundled_products_conditions_'. esc_attr( $index ), 'class' => 'edd_repeatable_condition_field', 'options' => $options, 'show_option_none' => false, 'selected' => $selected ) ); ?>
html->product_dropdown( array( 'name' => '_edd_bundled_products[1]', 'id' => 'edd_bundled_products_1', 'multiple' => false, 'chosen' => true, 'products' => $bundle_options, 'variations' => true, 'show_variations_only' => false, ) ); ?>
$price ) { $options[ $price_key ] = $prices[ $price_key ]['name']; } } $price_assignments = edd_get_bundle_pricing_variations( $post_id ); echo EDD()->html->select( array( 'name' => '_edd_bundled_products_conditions[1]', 'id' => 'edd_bundled_products_conditions_1', 'class' => 'edd-form-group__input edd_repeatable_condition_field', 'options' => $options, 'show_option_none' => false, 'selected' => null, ) ); ?>
>
$value ) : $index = isset( $value['index'] ) ? $value['index'] : $key; $name = isset( $value['name'] ) ? $value['name'] : ''; $file = isset( $value['file'] ) ? $value['file'] : ''; $condition = isset( $value['condition'] ) ? $value['condition'] : false; $thumbnail_size = isset( $value['thumbnail_size'] ) ? $value['thumbnail_size'] : ''; $attachment_id = isset( $value['attachment_id'] ) ? absint( $value['attachment_id'] ) : false; $args = apply_filters( 'edd_file_row_args', compact( 'name', 'file', 'condition', 'attachment_id', 'thumbnail_size' ), $value ); ?>
null, 'file' => null, 'condition' => null, 'attachment_id' => null, 'thumbnail_size' => null, ) ); $prices = edd_get_variable_prices( $post_id ); $variable_pricing = edd_has_variable_prices( $post_id ); $variable_display = $variable_pricing ? '' : ' style="display:none;"'; $variable_class = $variable_pricing ? ' has-variable-pricing' : ''; ?>
' . esc_html( $key ) . '' ); ?>
html->text( array( 'name' => 'edd_download_files[' . $key . '][name]', 'id' => 'edd_download_files-' . $key . '-name', 'value' => $args['name'], 'placeholder' => __( 'My Neat File', 'easy-digital-downloads' ), 'class' => 'edd-form-group__input edd_repeatable_name_field large-text', ) ); ?>
html->text( array( 'name' => 'edd_download_files[' . $key . '][file]', 'id' => 'edd_download_files-' . $key . '-file', 'value' => $args['file'], 'placeholder' => __( 'Enter, upload, choose from Media Library', 'easy-digital-downloads' ), 'class' => 'edd-form-group__input edd_repeatable_upload_field edd_upload_field large-text', ) ); ?>
>
$price ) { $options[ $price_key ] = $prices[ $price_key ]['name']; } } echo EDD()->html->select( array( 'name' => 'edd_download_files[' . $key . '][condition]', 'id' => 'edd_download_files-' . $key . '-condition', 'class' => 'edd-form-group__input edd_repeatable_condition_field', 'options' => $options, 'selected' => $args['condition'], 'show_option_none' => false, ) ); ?>
post_type !== 'download' ) ) { return $strings; } $downloads_object = get_post_type_object( 'download' ); $labels = $downloads_object->labels; $strings['insertIntoPost'] = sprintf( __( 'Insert into %s', 'easy-digital-downloads' ), strtolower( $labels->singular_name ) ); return $strings; } add_filter( 'media_view_strings', 'edd_download_media_strings', 10, 1 ); /** * Refund Window * * The refund window is the maximum number of days each * can be downloaded by the buyer * * @since 3.0 * @param int $post_id Download (Post) ID * @return void */ function edd_render_refund_row( $post_id ) { // Bail if user cannot manage shop settings if ( ! current_user_can( 'manage_shop_settings' ) ) { return; } $types = edd_get_refundability_types(); $global_ability = edd_get_option( 'refundability', 'refundable' ); $refundability = edd_get_download_refundability( $post_id ); $global_window = edd_get_option( 'refund_window', 30 ); $edd_refund_window = edd_get_download_refund_window( $post_id ); ?>
html->select( array( 'name' => '_edd_refundability', 'id' => 'edd_refundability', 'class' => 'edd-form-group__input', 'options' => array_merge( // Manually define a "none" option to set a blank value, vs. -1. array( '' => sprintf( /* translators: Default refund status */ esc_html_x( 'Default (%1$s)', 'Download refund status', 'easy-digital-downloads' ), ucwords( $refundability ) ), ), $types ), // Use the direct meta value to avoid falling back to default. 'selected' => get_post_meta( $post_id, '_edd_refundability', true ), 'show_option_all' => '', 'show_option_none' => false, ) ); ?>

0 for unlimited', 'easy-digital-downloads' ); ?>

>

0 for unlimited', 'easy-digital-downloads' ); ?>

html->checkbox( array( 'name' => '_edd_download_tax_exclusive', 'id' => '_edd_download_tax_exclusive', 'current' => $exclusive, 'class' => 'edd-form-group__input', ) ); ?>
html->checkbox( array( 'name' => '_edd_quantities_disabled', 'id' => '_edd_quantities_disabled', 'current' => $disabled, 'class' => 'edd-form-group__input', ) ); ?>
html->text( array( 'name' => 'edd_sku', 'id' => 'edd_sku', 'value' => $edd_sku, 'class' => 'edd-form-group__input small-text', ) ); ?>
Purchase button behavior: Add to Cart buttons follow a traditional eCommerce flow. A Buy Now button bypasses most of the process, taking the customer directly from button click to payment, greatly speeding up the process of buying the product.', 'easy-digital-downloads' ); $no_buy_now_support_tooltip = __( 'Purchase button behavior: Add to Cart buttons follow a traditional eCommerce flow. Buy Now buttons are only available for stores that have a single supported gateway active and that do not use taxes.', 'easy-digital-downloads' ); ?>
html->checkbox( array( 'name' => '_edd_hide_purchase_link', 'id' => '_edd_hide_purchase_link', 'current' => $hide_button, 'class' => 'edd-form-group__input', ) ); ?>
'_edd_button_behavior', 'id' => 'edd_button_behavior', 'selected' => $behavior, 'options' => array( 'add_to_cart' => __( 'Add to Cart', 'easy-digital-downloads' ), 'direct' => __( 'Buy Now', 'easy-digital-downloads' ), ), 'show_option_all' => null, 'show_option_none' => null, 'class' => 'edd-form-group__input', ); echo EDD()->html->select( $args ); ?>

'edd-payment-history', 'product-id' => urlencode( $post_id ) ), edd_get_admin_base_url() ); $earnings_report_url = edd_get_admin_url( array( 'page' => 'edd-reports', 'view' => 'downloads', 'products' => absint( $post_id ), ) ); ?>


'edd-tools', 'view' => 'file_downloads', 'tab' => 'logs', 'download' => absint( $post_id ), ) ); ?>