Customizing pdf file pro report

Hi,
I tried a code from another topic

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;        
}

This one doesn’t work because the global variable is not recognized, so nothing changes.

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';
  }
}

This code works but there is not date

I did everything from the custom dashboard extension MainWP

Can you try 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

@596485iohu To extend on @bogdan 's response ~ it looks like your Quotations in your version of the code snippet have been replaced during Copy & Paste. Please double check your version against @bogdan 's and make sure your quotes are correct.

I have tested this snippet and it works as intended:

image

1 Like

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