• Resolved wattsyourwebsite

    (@wattsyourwebsite)


    I had this code working fine to generate a PDF.

    User’s would click a link such as

    https://dev.catonline.tv/my-profile/certificate/?pdf=5003

    and the PDF would be generated. Now a PHO FATAL ERROR is generated with this in the error_log

    [11-Nov-2025 04:27:16 UTC] PHP Fatal error: Uncaught Exception: Post not found or not published: 5003 in /home/catonlin/dev.catonline.tv/wp-content/plugins/dk-pdf220/modules/PDF/ContextManager.php:67
    Stack trace: 0 /home/catonlin/dev.catonline.tv/wp-content/plugins/dk-pdf220/modules/PDF/ContextManager.php(54): Dinamiko\DKPDF\PDF\ContextManager->setupPostContext() 1 /home/catonlin/dev.catonline.tv/wp-content/plugins/dk-pdf220/modules/PDF/Generator.php(36): Dinamiko\DKPDF\PDF\ContextManager->setupContext() 2 /home/catonlin/dev.catonline.tv/wp-content/plugins/dk-pdf220/modules/PDF/PDFModule.php(35): Dinamiko\DKPDF\PDF\Generator->handle_pdf_request() 3 /home/catonlin/dev.catonline.tv/wp-includes/class-wp-hook.php(324): Dinamiko\DKPDF\PDF\PDFModule->Dinamiko\DKPDF\PDF{closure}() 4 /home/catonlin/dev.catonline.tv/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() 5 /home/catonlin/dev.catonline.tv/wp-includes/plugin.php(565): WP_Hook->do_action() 6 /home/catonlin/dev.catonline.tv/wp-includes/class-wp.php(835): do_action_ref_array() 7 /home/catonlin/dev.catonline.tv/wp-includes/functions.php(1342): WP->main() 8 /home/catonlin/dev.catonline.tv/wp-blog-header.php(16): wp() 9 /home/catonlin/dev.catonline.tv/index.php(17): require(‘/home/catonlin/…’) 10 {main}

    thrown in /home/catonlin/dev.catonline.tv/wp-content/plugins/dk-pdf220/modules/PDF/ContextManager.php on line 67
    [11-Nov-2025 04:27:19 UTC] PHP Fatal error: Uncaught Exception: Post not found or not published: 5003 in /home/catonlin/dev.catonline.tv/wp-content/plugins/dk-pdf220/modules/PDF/ContextManager.php:67
    Stack trace: 0 /home/catonlin/dev.catonline.tv/wp-content/plugins/dk-pdf220/modules/PDF/ContextManager.php(54): Dinamiko\DKPDF\PDF\ContextManager->setupPostContext() 1 /home/catonlin/dev.catonline.tv/wp-content/plugins/dk-pdf220/modules/PDF/Generator.php(36): Dinamiko\DKPDF\PDF\ContextManager->setupContext() 2 /home/catonlin/dev.catonline.tv/wp-content/plugins/dk-pdf220/modules/PDF/PDFModule.php(35): Dinamiko\DKPDF\PDF\Generator->handle_pdf_request() 3 /home/catonlin/dev.catonline.tv/wp-includes/class-wp-hook.php(324): Dinamiko\DKPDF\PDF\PDFModule->Dinamiko\DKPDF\PDF{closure}() 4 /home/catonlin/dev.catonline.tv/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() 5 /home/catonlin/dev.catonline.tv/wp-includes/plugin.php(565): WP_Hook->do_action() 6 /home/catonlin/dev.catonline.tv/wp-includes/class-wp.php(835): do_action_ref_array() 7 /home/catonlin/dev.catonline.tv/wp-includes/functions.php(1342): WP->main() 8 /home/catonlin/dev.catonline.tv/wp-blog-header.php(16): wp() 9 /home/catonlin/dev.catonline.tv/index.php(17): require(‘/home/catonlin/…’) 10 {main}

    thrown in /home/catonlin/dev.catonline.tv/wp-content/plugins/dk-pdf220/modules/PDF/ContextManager.php on line 67

    Please help!
    If I revert to version 2.0.2 it works fine

    Tania

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author dinamiko

    (@dinamiko)

    Hello @wattsyourwebsite,

    It seems the issue was caused by the plugin not handling non public posts correctly, I’ve added a fix and also improved the errors to not display fatal error but a user friendly message in cases where is not possible to display the PDF.

    I would really appreciate if you can give it a try to confirm if the issue is fixed before I release it, here you have the plugin with the fix: https://github.com/Dinamiko/dk-pdf/releases/download/2.2.1-rc1/dk-pdf.zip

    Thread Starter wattsyourwebsite

    (@wattsyourwebsite)

    Hi @dinamiko,

    I just tested it out and it all worked perfectly.

    Thanks

    Plugin Author dinamiko

    (@dinamiko)

    Perfect, thanks for confirming! I’ll include it in the upcoming release then, you can use it for now and then just update the plugin when next upgrade notice arrive.

    Thread Starter wattsyourwebsite

    (@wattsyourwebsite)

    Actually – my apologies! Upon further testing it is returning this error to the screen:

    The requested content was not found.

    https://ibb.co/Psrw3txd

    Plugin Author dinamiko

    (@dinamiko)

    Hello @wattsyourwebsite,

    It seems that the post is not found by the plugin for some reason… I added a fix, when you have time can you please give it a try with this and let me know: https://github.com/Dinamiko/dk-pdf/releases/download/2.2.1-rc1/dk-pdf.zip

    Thread Starter wattsyourwebsite

    (@wattsyourwebsite)

    I have tried that version and I still get this error:

    The requested content was not found.

    Plugin Author dinamiko

    (@dinamiko)

    Hello @wattsyourwebsite,

    The problem seems caused by a stronger post permissions validation introduced in 2.2.0, while in 2.0.2 it have been more permissive… I suggest you to try to generate the PDF logged as a user with the capability to see the content (assuming you have to be registered to access the content), and if it still fails then just rollback to 2.0.2.

    Thread Starter wattsyourwebsite

    (@wattsyourwebsite)

    Even if I log in as admin I can’t generate a PDF.

    It shows this error:

    PDF Generation Error

    The requested content was not found.

    The content is definitely there.

    You said:

    “caused by a stronger post permissions validation introduced in 2.2.0”

    How do I set the permissions to allow any logged in user access?

    Plugin Author dinamiko

    (@dinamiko)

    Hello @wattsyourwebsite,

    It’s difficult for me to figure out what could be the root of problem without knowing more about how all is created and configured on your site.

    As a workaround you can either rollback to and use 2.0.2 or if you know the post ids (and they are not many) that are causing the issue, you can add this code snippet which would force the retrieval of specific posts:

      add_filter( 'dkpdf_get_post_for_pdf', function( $post, $post_id ) {
    // Add post IDs, separated by comma
    $allowed_post_ids = array( 5003 );

    if ( in_array( $post_id, $allowed_post_ids, true ) && ! $post ) {
    $post = get_post( $post_id );
    }

    return $post;
    }, 10, 2 );
    Thread Starter wattsyourwebsite

    (@wattsyourwebsite)

    The post in question is 5922 but even adding your code does not work.

    $allowed_post_ids = array( 5003, 5922 ); 
    Thread Starter wattsyourwebsite

    (@wattsyourwebsite)

    I found the right code fix.

      add_filter( 'dkpdf_get_post_for_pdf', function( $post, $post_id ) {      
    // Add post IDs, separated by comma
    $allowed_post_ids = array( 5003 ); // This is what is in the URL ?pdf=5003
    if ( in_array( $post_id, $allowed_post_ids, true ) && ! $post ) {
    $post = get_post( 5922 ); // This is the ID of the certificate page =
    }
    return $post;
    }, 10, 2 );


Viewing 11 replies - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.