• Resolved jlanpheer

    (@jlanpheer)


    I am dealing with a plugin that i wrote for a client site some years ago now, no code changes and last night, i received a call, the plugin suddenly stopped working and I’m baffled by it and wondering if anyone might have an idea to jiggle the handle here.

    The plugin that i built essentially has a login page, which once validated, takes you to a screen with a couple of options. If you choose one of the options (button press), it redirects the user to another WP page which only contains a shortcode which runs the PHP that i’d written years ago.

    This is the code of that button:

    <button id="statsBtn" name="submit" class="submit-btn" type="submit" onclick="location.href=document.location.href='/mypage-setup'" value="submit">Enter App</button>

    The WP page is entitled “mypage-setup” and it only contains a shortcode which contains PHP and external JS code. Last night (again, no code changes), the button press only displays a blank page. I’ve debugged and the button press does not execute the shortcode at all (when i put debug messages in the PHP file containing the shortcode, those messages DO display in the error log). I’ve removed the shortcode from the page entirely and replaced it with a simple paragraph, still no dice. Perhaps something to do with the onclick redirect? However, when i’m in the WP page editor for the page containing the shortcode and i choose ‘View Page’, the intended plugin code displays properly.

    When i scrape the above ‘View Page’ URL and put it in another browser tab or different browser entirely, it displays as I would expect. However, if i attempt to access the page itself thru the plugin, it displays a blank page (no plugin output and debugging shows it never executes any plugin code), however the URL is the exact same URL as when i choose ‘View Page’.

    I’m unsure what to check or try at this point. The intended shortcode doesn’t execute (hence no errors) and i’m not getting any Javascript console errors either. All of this code was used this past Sunday with no issues and it works 100% as it did on my local server. Frankly, i’m a bit baffled. Can anyone point out some possible candidates of things to try?

Viewing 5 replies - 1 through 5 (of 5 total)
  • 00chriswilson00

    (@00chriswilson00)

    Gotcha! Here’s a more casual approach:

    It sounds like something’s gone a bit wonky, even though no code changed. Here are a few things that could be going wrong:

    1. Caching Issues – Sometimes caching can mess with things, so try clearing your site’s cache and your browser cache. You can also add a query string to the URL like /mypage-setup?nocache=1 and see if that helps.
    2. Button Redirect – The onclick code seems a bit strange. I’d suggest swapping it out for a simpler approach:
       <button id="statsBtn" class="submit-btn" onclick="window.location.href='/mypage-setup'">Enter App</button>

    This might help clean up any redirect issues.

    1. Shortcode Issue – Maybe the shortcode isn’t firing correctly. Check that it’s properly registered in your plugin using add_shortcode(). If it works on a different page, then it could be something specific to that page.
    2. Hosting/Server Stuff – If your server recently updated PHP or made other changes, that could be messing things up. Make sure your plugin is compatible with the current PHP version. Also, check any server logs for clues.
    3. Plugin or Theme Conflicts – It could be that something else is interfering with your plugin. Try disabling other plugins or switching to a default theme (like Twenty Twenty-Three) to rule that out.
    4. HTTP vs. HTTPS – If the site is running on HTTPS but the redirect is going to HTTP, that could cause issues. Make sure everything is set to HTTPS across the board.
    5. Permissions – Maybe there’s a permission issue blocking the page or plugin from running. Double-check your file permissions on the server.

    For troubleshooting, try turning on WP debugging by adding this to wp-config.php:

       define('WP_DEBUG', true);
       define('WP_DEBUG_LOG', true);
       define('WP_DEBUG_DISPLAY', false);

    Then check the debug.log file for errors. Also, you can use your browser’s developer tools to check for any network errors in the console.

    Hope something in here helps you figure it out!

    Thread Starter jlanpheer

    (@jlanpheer)

    Hey, thanks for the suggestions, I’ll check the “no-cache-ing” option, thanks, i hadn’t tried that.

    2. Button code, i actually started with your simpler version, the same as your suggestion, but i will add the no-cache.

    3. Good suggestion to try the shortcode on a different page, thanks i will try that. I have registered it properly. (and this plugin has been working without issue for several years, which is what is truly baffling about this).

    4. The hosting company HAD switched to php8 recently, and we had troubles (not with this) last week and they switched us back to 7.3.4 and this has worked for a week…. until tonight. Could .htaccess be an issue?

    5. It MIGHT be this, the problem is that the theme has been SO heavily customized that going to a default theme will make this functionality unavailable. But, i will check that.

    6. Everything’s running https, i checked that first thing.

    7. Also checked permissions, also all good.

    I’ve been debugging all day, no directly relevant errors in the debug log and nothing in the browser console at all.

    I’m wondering about the php8 shift and then back to 7.3.4 myself….. Thank you for some ideas to try, i was running out of them.

    • This reply was modified 4 months ago by jlanpheer. Reason: adding info
    Thread Starter jlanpheer

    (@jlanpheer)

    Oh, i had also tried changing the button link to this form:

    onclick="<?php echo get_permalink( xxxx ); ?>"

    No dice…..

    Thread Starter jlanpheer

    (@jlanpheer)

    I actually found the solution. By debugging, i trapped the url that was being called and saved that. I also captured the url of the “View Page” that WAS working. I found them to be different by a SINGLE character: the one that worked had a trailing “/” on the end. So, the two lines of code that i compared were:

    https://mysite.com/stats-app
    https://mysite.com/stats-app/

    The second one worked, the first did not. Not sure why that is, i’d be curious if anyone has an explanation. It’s also a mystery why the code has worked for YEARS using version #1 and suddenly, not this past Sunday.

    Thanks for any theories about the slash, but the problem is resolved and thanks for the helpful suggestions!

    Moderator bcworkz

    (@bcworkz)

    WP generally likes to have a trailing slash in its permalinks. There are few rare exceptions just to keep things confusing X-) WP will normally automatically redirect non-trailing slash requests to the trailing slash version. For some reason this is not happening with your redirect, resulting in a blank page. Without knowing what code is involved, it’s difficult to speculate what went wrong.

    After getting a blank page, did you check your server’s error log for clues about what actually went wrong? Apologies if you already stated this earlier, I read through this thread quite quickly and could have missed it.

    In any case it’s a good practice to make HTTPS requests using the trailing slash version. It saves WP and the server from needing to make a separate redirect. Notably, the site and home URLs in general settings must not include the trailing slash, one of the rare exceptions.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.