Change the default .pdf name on a pro report (bis)

I may be a total newbie on this one,

but i find a previous topic witht the following custom code

add_filter( ‘mainwp_pro_reports_pdf_filename’, ‘mycustom_mainwp_pro_reports_pdf_filename’, 10, 3 );
if ( !function_exists( ‘mycustom_mainwp_pro_reports_pdf_filename’ ) ) {
function mycustom_mainwp_pro_reports_pdf_filename( $filename, $report, $site_id ) {
return ‘new-file-name.pdf’;
}
}

But it just remove the file name by ‘new-file-name.pdf’ How can we make it so it include the website ide + the date for exemple ?

Hi @heavestudio,

Can you tell me what is the exact format that you want to use?

Sure, would be nice to have

website name - date

You can try with this:

add_filter( ‘mainwp_pro_reports_pdf_filename’, ‘mycustom_mainwp_pro_reports_pdf_filename’, 10, 3 );

function mycustom_mainwp_pro_reports_pdf_filename( $filename, $report, $site_id ) {
	global $mainWPProReportsExtensionActivator;
	$website = apply_filters( 'mainwp_getsites', $mainWPProReportsExtensionActivator->get_child_file(), $mainWPProReportsExtensionActivator->get_child_key(), $site_id );
	if ( $website && is_array( $website ) ) {
		$website = current( $website );
		return $website['name'] . '-' . date( 'Y-m-d', $report->date_from ) . '-' . date( 'Y-m-d', $report->date_to ) . '.pdf';
	}
	return $filename;        
}
1 Like

Thanks @Bogdan, but nothing happen :frowning:

Can you please confirm that you have this snippet saved to the PHP section of the Custom Dashboard extension? I have seen in some cases that users save it to the CSS section by accident.

I confirm i pasted it in php section

Would you mind opening a private Help Desk ticket so we can collect some additional information & investigate further?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.