Support » Plugin: WP Post to PDF Enhanced » Clear PDF Cache on save_post Action

  • I’ve added the following action hook to save_post to make sure that the PDF cache is refreshed when the post is saved via the Admin or API.

    pdf_cache_refresh( $post_id ){
    	// Bail early if the constant isn't defined
    	if ( !defined( 'WPPT0PDFENH_CACHE_DIR' ) ) return;
    	// Get the post
    	$post = get_post( $post_id );
    	// TODO: A check to make this only apply to posts where Post to PDF is enabled?
    	// Check if the file exists in the cache
    	$filepath = WPPT0PDFENH_CACHE_DIR . '/' . $post->post_name . '.pdf';
    	if ( file_exists( $filepath ) ){
    		// Delete cached PDF
    		@unlink( $filepath );
    add_action( 'save_post', 'pdf_cache_refresh' );

Viewing 2 replies - 1 through 2 (of 2 total)
  • Vanessa


    Thank you for sharing! Where do I place this? When I put it in functions.php I got the white screen of death.

    Plugin Author Lewis Rosenthal


    Be careful of that constant, too, which was an old typo, fixed in the current release (WPPT0PDFENH_CACHE_DIR has a zero instead of the letter “O”). The correct name is WPPTOPDFENH_CACHE_DIR.

    The above looks like it should be fine in functions.php. Did you check for a missing “;” anywhere?

    This functionality will indeed make it into the next release. I’m just not sure how quickly I can get it out.


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Clear PDF Cache on save_post Action’ is closed to new replies.