Last active
March 13, 2023 16:01
-
-
Save dryan1144/eade626f3826ebe654503e6c112deff8 to your computer and use it in GitHub Desktop.
Add custom metadata to Easy Digital Downloads (EDD) file downloads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function drw_edd_create_file_row($post_id, $key, $args) { ?> | |
<div class="edd-form-group edd-your_meta_key"> | |
<label for="edd_download_files-<?php echo esc_attr( $key ); ?>-your_meta_key" class="edd-form-group__label edd-repeatable-row-setting-label"><?php esc_html_e( 'Your Meta Title', 'easy-digital-downloads' ); ?></label> | |
<div class="edd-form-group__control"> | |
<?php | |
$select_args = array( | |
'options' => array( | |
'option_1' => 'Your Option', | |
'option_2' => 'Your Second Option' | |
), | |
'name' => 'edd_download_files[' . $key . '][your_meta_key]', | |
'class' => 'edd-form-group__input edd_repeatable_your_meta_key_field', | |
'id' => 'edd_download_files-' . $key . '-your_meta_key', | |
'selected' => isset($args['your_meta_key']) ? $args['your_meta_key'] : null, | |
'value' => isset($args['your_meta_key']) ? $args['your_meta_key'] : null, | |
'placeholder' => __( 'Your Custom Meta Title', 'easy-digital-downloads' ), | |
'show_option_all' => false, | |
'show_option_none' => false, | |
); | |
// can use EDD()->html->text or any method from the EDD_HTML_Elements class | |
// https://easydigitaldownloads.com/docs/edd_html_elements/ | |
echo EDD()->html->select( $select_args ); | |
?> | |
</div> | |
</div> | |
<?php | |
} | |
add_action('edd_download_file_table_row', 'drw_edd_create_file_row', 10, 3); | |
function drw_edd_file_row_args($variables, $value) { | |
$your_meta_key = isset( $value['your_meta_key'] ) ? $value['your_meta_key'] : ''; | |
$variables['your_meta_key'] = $your_meta_key; | |
return $variables; | |
} | |
add_filter('edd_file_row_args', 'drw_edd_file_row_args', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment