How to add a new Column Header inside WPUF Dashboard Table

In this post, I’m going to serve how to add a new Column Header on your WP User Front-end Dashboard Table.

Before stepping tell me why/when do you need this?

Okay, imagine you are working on a site where you will get information alongside any File/Media info. So by default, in WPUF dashboard you it won’t let you draw all of your custom fields meta.

In this case, you will need to customize the table dashboard to place any custom fields meta info.In most cases, showing custom fields with WordPress get_post_meta() is easy to manipulate but it’s getting a bit complicated once you are going to show the File/Media direct URL/Link.

So I will show you how you can get and show the File/Media link on your dashboard table.

Process

This is a default view of WPUF Dashboard Table.

As you can see, the Dashboard is consist with 04 Heading Element- Title, Status, Payment, Options

image

And after the final touch of our work-aground it will be look like this.

image

Things to do

Don’t forget that the associated Download File Link is coming from the post meta so first you need to assure that the File Upload field is predefined on the Post/Form.

So to make this whole process well decorated, let’s say I don’t have any WPUF Post Form or associated Field so first I’m creating a post form with File Upload field and creating a post so that it populated the associated File Upload field’s link on the Dashboard Table.

How to add a new Column Header inside WPUF Dashboard Table 1
Play Video

Code-base

This below code snippets will add a column header on the Dashboard Table.

							
							
					/**
* @Add a new column header in dashboard table
* @param array $args dashboard query arguments
* @return void
*/
function wpufe_dashboard_change_head( $args ) {
printf( '<th>%s</th>', __( 'Download File', 'wpuf' ) );
}
add_action( 'wpuf_dashboard_head_col', 'wpufe_dashboard_change_head', 10, 2 );
				
			

This below code snippets will add a column header on the Dashboard Table.

image

Now, we need to call & retrieve the Download File to make it appear on the Frontend Dashboard

							
							
					
/** Add a new table cell to the dashboard table rows.
* It adds a form for changing the post status of each posts via ajax call.
* @param array $args dashboard query arguments
* @param object $post current rows post object
* @return void
* @output of the below code will be like https://prnt.sc/tapb0o
*/


function wpufe_dashboard_row_col( $args, $post ) {
?>
<td>
<?php
 // retrieve file of the custom field (you need to modify the custom filed meta_key on your own)
if ( $file = get_post_meta(get_the_ID(), 'download_file', true) ) {

//get the file attachment link
$filelink = wp_get_attachment_link($file);

//Print-Show the File link on the dashbaord
echo $filelink;


} else {

echo '—';

}
?>
</td>
<?php
}
add_action( 'wpuf_dashboard_row_col', 'wpufe_dashboard_row_col', 10, 2 );				
			

Now, the above code will make the Downloadable file appear on the front-end dashboard

image

Side Note

  • Make sure the custom field meta_key name is according to your custom field’s meta name- How to add a new Column Header inside WPUF Dashboard Table 2
  • And you call the file attachment link of the file with wp_get_attachment_link otherwise it will let the user download the file throughout the link.

Wrapping-up

So this is fair enough to push the brain harder for today! 😀

I hope this will help you to make the file download link appear on the front-end dashboard.

Default image
MM Aurangajeb
Support Engineer, Blogger. Learning Web Design & Developing, Tech & WordPress Enthusiast, WordPress Lover. Always try to learn new things, new hacks, new techs.

Newsletter Updates

Enter your email address below to subscribe to our newsletter

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.