• Resolved Jameth12

    (@jameth12)


    Hi there

    Thank you for creating what looks to be an incredibly useful plugin, that will be helping many folks with CSP-related headaches!

    When I enable tag capture, our website crashes with a ‘HTTP ERROR 500’ message. From a lot of trial and error I established that removing this ‘show_content_snippet’ function from functions.php stops the crash happening, but it is pretty crucial to our site working properly. Do you have any ideas why this would be interfering with your plugin? Many thanks!

    */ function show_content_snippet( $post, $amount = 100 ) {
    $post = (array)$post;
    if( $post[‘post_excerpt’] !== ” ) {
    echo apply_filters( ‘the_excerpt’, $post[‘post_excerpt’] );
    }elseif( preg_match( ‘##is’, $post[‘post_content’] ) ) {
    $moreSplit = explode( ”, apply_filters( ‘the_content’, $post[‘post_content’] ) );
    echo $moreSplit[0];
    }else{
    echo ” . substr( strip_tags( $post[‘post_content’] ), 0, $amount ) . ‘…’;
    }
    }

    • This topic was modified 7 months, 3 weeks ago by Jameth12.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Giuseppe

    (@mociofiletto)

    How this function is hooked/called in wp?

    Thread Starter Jameth12

    (@jameth12)

    It appears in about 8 php templates, like search.php, index.php, archive.php and the home page template to show a short text excerpt

    e.g. https://www.tsl.com/?s=MC67

    <div class="entry-content">
    	<?php show_content_snippet( $post, 200 ); ?>
    </div>

    Plugin Author Giuseppe

    (@mociofiletto)

    Hi @Jameth, i have tested your function in a couple o standard themes, and it doesn’t create any error if capture is enabled or not.

    Can you try to extend the amount of memory allowed in your php.ini? Do you have any server report of the crash?

    Maybe it’s just a typo, but I think there is an error in your code:

    i guess that

    $moreSplit = explode( '', apply_filters( 'the_content', $post['post_content'] ) );

    should be:

    $moreSplit = explode( ' ', apply_filters( 'the_content', $post['post_content'] ) );

    For me your code generates an error:

    Uncaught ValueError: explode(): Argument #1 ($separator) cannot be empty

    But this is completely unrelated to No unsafe-inline

    Thread Starter Jameth12

    (@jameth12)

    Apologies for the late reply, and thank you for your help! I did try extending memory limit but still experienced the same crash. I also checked the error log file but couldn’t see anything being reported at the time of the crash. I’ll do some further tests to make sure I haven’t missed something.

    Thank you for pointing out the unrelated error, thats very kind of you. We will look further into that.

    Plugin Author Giuseppe

    (@mociofiletto)

    Hi @jameth12, please test the development version of the plugin and tell me if the issue is still present.

    The new version should spare some memory when protection is enabled; however the new code has to be considered experimental until the new version will be released.

    Thread Starter Jameth12

    (@jameth12)

    Thank you, but same crash with the developer version unfortunately. Learning as I go, the error logs within CP File Manager weren’t the right ones to be looking at, I needed to be looking at the latest error messages at a higher level in cPanel tools. It shows a handful of logs all with identical content, here’s one:

    [Tue Apr 23 02:02:12.070337 2024] [lsapi:error] [pid 4086348:tid 23349990254336] [remote 94.192.115.19:63537] [host www.tsl.com] Backend fatal error: PHP Fatal error:  Uncaught League\\Uri\\Exceptions\\SyntaxError: The port unpkg.com is invalid in /home/cosnvb59uf13/public_html/web.tsl-hid.com/wp-content/plugins/no-unsafe-inline/vendor/league/uri/src/UriString.php:382\nStack trace:\n#0 /home/cosnvb59uf13/public_html/web.tsl-hid.com/wp-content/plugins/no-unsafe-inline/vendor/league/uri/src/UriString.php(359): League\\Uri\\UriString::filterPort('unpkg.com')\n#1 /home/cosnvb59uf13/public_html/web.tsl-hid.com/wp-content/plugins/no-unsafe-inline/vendor/league/uri/src/UriString.php(323): League\\Uri\\UriString::parseAuthority('www.tsl.comhttp...')\n#2 /home/cosnvb59uf13/public_html/web.tsl-hid.com/wp-content/plugins/no-unsafe-inline/vendor/league/uri/src/Uri.php(468): League\\Uri\\UriString::parse('https://www.tsl...')\n#3 /home/cosnvb59uf13/public_html/web.tsl-hid.com/wp-content/plugins/no-unsafe-inline/src/Nunil_Capture.php(894): League\\Uri\\Uri::createFromString('https://www.tsl...')\n#4 /home/cosnvb59uf13/public_html/web.tsl-hid.com/wp-content/plugins/no-unsafe-inline/src/Nunil_Capture.php in /home/cosnvb59uf13/public_html/web.tsl-hid.com/wp-content/plugins/no-unsafe-inline/vendor/league/uri/src/UriString.php on line 382\n
    Plugin Author Giuseppe

    (@mociofiletto)

    Nice shot!

    What happens here is that your page contains an invalid url in the src property of a <script> tag, maybe badly created by the snippet you showed.

    the interested line (in the example url you posted) is 782:

    <script type="text/javascript" src="https://www.tsl.comhttps:unpkg.com/isotope-layout@3/dist/isotope.pkgd.js" id="isotope-js"></script>

    I will fix the code, because the plugins should not crash when it finds an invalid url but simply it should not process it, however I think you should fix your page.

    The bug wil be fixed in next release.

    Thread Starter Jameth12

    (@jameth12)

    The tag capture is working now! That invalid URL was being generated by an incorrectly enqueued script within functions.php.

    Thank you so much for your help and for pinpointing the issue!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘HTTP ERROR 500 – troubleshooting functions.php’ is closed to new replies.