"Last Updated" Date and Version on Downloads
Shows when a download was last updated and an optional version number above its content, reassuring buyers that the product is maintained.
Opens WPIDE on
Code
add_action( 'add_meta_boxes_download', function () {
add_meta_box( 'wpide-edd-version', 'Version', function ( $post ) {
wp_nonce_field( 'wpide_edd_version', 'wpide_edd_version_nonce' );
printf( '<label class="screen-reader-text" for="wpide-edd-version-field">%1$s</label><input type="text" id="wpide-edd-version-field" name="wpide_edd_version" value="%2$s" placeholder="1.0.0" style="width:100%%">', esc_html( 'Version' ), esc_attr( get_post_meta( $post->ID, '_wpide_edd_version', true ) ) );
}, 'download', 'side' );
} );
add_action( 'save_post_download', function ( $post_id ) {
if ( ! isset( $_POST['wpide_edd_version_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['wpide_edd_version_nonce'] ), 'wpide_edd_version' ) || ! current_user_can( 'edit_post', $post_id ) || wp_is_post_autosave( $post_id ) ) {
return;
}
update_post_meta( $post_id, '_wpide_edd_version', sanitize_text_field( wp_unslash( $_POST['wpide_edd_version'] ?? '' ) ) );
} );
add_action( 'edd_before_download_content', function ( $download_id ) {
$version = get_post_meta( $download_id, '_wpide_edd_version', true );
$parts = array( sprintf( 'Last updated: %s', get_the_modified_date( '', $download_id ) ) );
if ( $version ) {
$parts[] = sprintf( 'Version %s', $version );
}
printf( '<p class="wpide-edd-updated" style="font-size:.9em;opacity:.8">%s</p>', esc_html( implode( ' · ', $parts ) ) );
} );
Notes
Enter a version in the "Version" box on the download edit screen; the date comes from the last time you saved the download.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.