• 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' );

    https://www.ads-software.com/plugins/wp-post-to-pdf-enhanced/

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

    (@vanessajaded)

    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

    (@lewisr)

    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.

    Cheers

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