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-tools',
'view' => 'file_downloads',
'tab' => 'logs',
'download' => absint( $post_id ),
)
);
?>