• Resolved chrstna

    (@chrstna)


    Hi,

    So there is a custom plugin that was being used on http://www.brownlowtracker.com.au that displays a horizontal scroll of AFL scores above the header.

    I changed the theme it was using, and now the plugin doesn’t work.

    I am using code <?php do_shortcode(‘[matchesscore]’); ?> (this was in the original theme file of header.php that worked) in the new theme’s header.php file, but it just returns a white screen.

    I’m not sure where the issue is. Is it is the new theme’s header?

    Let me know what code/files you need to see.

    Thanks for your help.

    Regards,

    Christina

Viewing 12 replies - 1 through 12 (of 12 total)
  • Moderator bcworkz

    (@bcworkz)

    The error is almost certainly how you edited the new theme’s header.php. Probably a syntax error. For example, maybe you inserted the <?php do_shortcode('[matchesscore]'); ?> inside an existing block of PHP code? Nested PHP blocks are illegal – don’t do this:

    <?php // some php code
       <?php do_shortcode('[matchesscore]'); ?>
       // more php code
    ?>

    All just speculation of course. Define WP_DEBUG as true in wp-config.php, then reload your page with the modified theme. You’ll now see an error message telling you what the error is, what file, and what line. You may be able to figure it out from those clues. If not, post that line and several lines before and after for context, along with the error message. Note which line is flagged by the error message since line numbers are meaningless with code snippets. Someone here should be able to point out the problem.

    Thread Starter chrstna

    (@chrstna)

    I need to add a few more issues now.

    1. I was working on the site until late last night perfectly fine, and this morning when I tried to view the homepage/login to backend I’m getting a “This webpage is not available ERR_CONNECTION_REFUSED” from Google Chrome. Internet is fine. When viewing on my phone using data I simply get a white page. I can’t access my cpanel but FTP works alright.

    2. I tried to troubleshoot the plugin issue by changing WP_DEBUG false to true last night. Is that all is required to make it show on the page? When I insert the php do_shortcode all I get is a white page even with the debug activated.

    3. I also tried to use the shortcode for the plugin [matchesscore] on a page and gave it a menu of its own. Once again, only a white page. There are other plugins that are working just fine (well not until this morning since the error) like ‘your votes’ and ‘leaderboard’ on the site. Does this mean there is something in the plugin code that refuses to work with the new theme?

    So, here’s a few lines of code from the header.php of the new theme that is not working with the plugin that used to work on the old theme:

    <div class="row bkaTopmenu bka_menu <?php echo ( !is_front_page() ? '' : ( $hgr_options['menu-style'] == 1 ? 'hidden' : '') ); ?>">
    
               <?php do_shortcode('[matchesscore]'); ?>
    
                          <div class="btn-logreg">
                                <?php
                                if ( is_user_logged_in() ) {
    								$current_user = wp_get_current_user();
    							?>
                                <span class="username">Hi, <?php echo $current_user->user_login; ?></span>
                                <a href="<?php echo get_site_url(); ?>/logout/">Logout</a>
                                <?php
                                }else{
    							?>
    
                                <a href="<?php echo get_site_url(); ?>/login/">Login</a>
                                <?php } ?>
    
                            </div>

    By the way, the plugin on the old theme was situated above the header like so:

    <body <?php body_class(); ?>>
    <div class="bt-wrapper">
    	<header role="banner">
            <div class="bt-con">
    			<?php do_shortcode('[matchesscore]'); ?>
                <div class="bt-social">
                    <div class="bts-left"></div>
                    <div class="bts-middle">
                    	<?php
    					$twitter_username = get_option( 'twitter_username' );
    					$facebook_username = get_option( 'facebook_username' );
    					$youtube_url = get_option( 'youtube_url' );
    					$google_plus_url = get_option( 'google_plus_url' );
    					?>
                        <a href="<?php echo $twitter_username; ?>" target="_blank" class="bt-soc twit"></a>
                        <a href="<?php echo $google_plus_url; ?>" target="_blank" class="bt-soc gtak"></a>
                        <a href="<?php echo $facebook_username; ?>" target="_blank" class="bt-soc fbs"></a>
                        <a href="<?php echo $youtube_url; ?>" target="_blank" class="bt-soc ytb"></a>
                    </div>
                    <div class="bts-right">
                    </div>
                </div>

    I’m so frustrated with WordPress right now, it seems so delicate. The wind will blow and the site malfunctions. Thanks for any help.

    Moderator bcworkz

    (@bcworkz)

    I feel your pain. These sort of problems often seem insurmountable when you’re in the middle of it. Once it’s all said and done the actual fix is often simple, it’s finding the fix that’s a massive problem.

    The connection refused error is unlikely a WordPress issue, it’s more of a server/hosting issue. But without a reliable connection to your site, it will be challenging to debug. Not accessing cPanel is certainly unrelated to WP. You should seek resolution for these through your host.

    Setting WP_DEBUG to true usually results in error messages, but on occasion it does not. Failure to do so makes debugging quite a challenge. And your edit looks fine, so the problem lies deeper.

    If you switch back to your old theme, everything still works as it did? If you deactivate the plugin responsible for the shortcode, with the new theme active, do you see site content? (minus the shortcode content of course).

    Please try switching to twentysixteen theme and placing the exact same <?php do_shortcode('[matchesscore]'); ?> at the very bottom of the header.php file. Does content appear? Undo your change after testing.

    Switch back to your new theme. Deactivate all plugins except the one responsible for the shortcode. Still whitescreen?

    These tests will narrow down where the problem lies. We still don’t know how to fix it, but at least know where to start looking. Unfortunately, plugin/theme conflicts is WordPress’ Achilles heel. It’s unrelated to wind direction, though it certainly seems so sometimes 🙂

    Thread Starter chrstna

    (@chrstna)

    Hi,

    Thanks for this reply.

    Unfortunately I still haven’t been able to fix the connection error so I haven’t been able to try any of your suggestions.

    I contacted my hosting provider and they told me it’s a plugin that’s messing it up. I don’t know how they know that? I’m just renaming plugin folders via ftp and refreshing the page for now…. there has to be a better way to do this?

    *sigh

    Moderator bcworkz

    (@bcworkz)

    I don’t think they actually know it’s a plugin, rather it’s a reasonable explanation since they found nothing wrong on their end.

    A plugin (or theme) will cause a connection problem if it gets caught in an infinite loop, for example. It’s possible that some conflict between your new theme and one of your plugins has inadvertently caused an infinite loop. I think it’s reasonable to assume that a connection error and the white screen are sign of the same problem.

    I assume your site works OK with the new theme and no plugins? Restore the plugins folder and reactivate only the plugin responsible for [matchesscore]. If you immediately have white screen or connection issues, then these two are incompatible for some reason.

    If all seems well, reactivate your other plugins one at a time. Reload the problem page after each. When the problem reoccurs you’ve found the problem plugin.

    If the new theme and matchesscore appear incompatible, try the shortcode with the twentysixteen theme. If that seems to work then there’s an issue with your new theme, otherwise it’s the matchesscore plugin itself.

    Thread Starter chrstna

    (@chrstna)

    Hi,

    Again, thank you for your replies.

    I fixed the white page issue by renaming one plugin and refreshing the page. Funnily enough when I renamed it back to the original the site was still functioning. Amazing how I can fix something without really knowing why or how.

    I tried your suggestion and the matchesscore plugin doesn’t work with any other template than the original. This occurs with the plugin on the ‘Your Votes’ page also. This is actually a more pressing issue than the matchesscore plugin. We can do without the matchesscore plugin as it’s just a carousel of information that isn’t necessary to the function of the site.

    Could you have a look at this page with the functioning plugin on the ‘Your Votes’ page
    http://brownlowtracker.com.au/uat/brownlow-tracker/
    (please click the page numbers and actually clicking the teams does something too)

    And then check out http://brownlowtracker.com.au/brownlow-tracker/
    where it doesn’t work.

    Another question: each page can be set to have a different theme. If a page is using the default theme, what php file does that correspond with? I’m thinking that I might try to merge the two themes so that the Your votes page is actually using a file from the original BTracker theme. Does that seem plausible?

    Christina

    Thread Starter chrstna

    (@chrstna)

    Hi,

    Also, when I try to click on a page number or the teams, I get this error on the google console:

    http://brownlowtracker.com.au/screen.png

    btracker_ajax is not defined

    Could this be why the plugin is not working? I have no knowledge of jquery/javascript so I’m grasping at straws here. I know where the btracker-ajax file is though if I need to edit anything.

    *rips hair out*

    Moderator bcworkz

    (@bcworkz)

    When you restored that one plugin’s name, did you also re-activate it, or just rename it? When WP can’t find a plugin it is deactivated. Unless you re-activate it, renaming it doesn’t do much except make it available again.

    Regardless, it sounds like there is more than one problem. To answer your question about template files, there’s not a logical relationship between the label you see on the edit screen and the file name, so I can’t answer your question directly, but here’s how to figure it out:

    Usually the default template file is ‘page.php’, but the others can be any name. The label you see in the template dropdown is in the file’s leading comment after “Template:”. Open files in your theme’s folder that might be a likely candidate. Check for the “Template:” label in the leading comment. When you find the label you’re interested in, you’ve found the file. If there is no “Template:” in the comment, it is not a page template.

    “btracker_ajax is not defined” is a good discovery, well done! Your site is very heavily AJAX driven. It’s pretty cool, but when any script error occurs, the entire thing stops working. This is why WP seems so fragile. While WP does have some issues, this fragility is due to the reliance on client scripts, not WP itself. Just sayin’ 🙂

    btracker_ajax is a critical object because it tells the script where to get more information. Despite the similarity in names, it’s not directly related to the btracker-ajax file. It’s a script object set by a call to wp_localize_script() in PHP.

    For some reason this call is not happening. There wouldn’t be any reason to use wp_localize_script() on a page template, but there could be script elsewhere that selectively makes the call only under certain circumstances, your different template not being one of them. What you could do as a workaround is simply have the page template output the requisite script block. It’s usually inserted in the footer as part of a call to get_footer() but you can put it in the head section as well. Make sure this is outside of any PHP code blocks, it should be handled like other plain HTML:

    <script type='text/javascript'>
    /* <![CDATA[ */
    var btracker_ajax = {"ajaxurl":"http:\/\/brownlowtracker.com.au\/wp-admin\/admin-ajax.php"};
    /* ]]> */
    </script>

    Note that the same code on the functioning page included the /uat/ sub-folder, I removed it here to match the non-functioning page’s path. Where ever you put it, it needs a path to match the WP installation’s admin-ajax.php location. Ideally, I would place it after the PHP call to wp_head() but before the closing </head> tag. Location is not too critical though.

    It’s a rather dirty hack, but it’ll solve the not defined error, but don’t get your hopes too far up, there may still be other issues. OTOH that could be the only thing standing in the way of success. Good luck!

    Thread Starter chrstna

    (@chrstna)

    Hi,

    SO CLOSE.

    I inserted the code in the header.php of the new theme and now the numbers across the top work, but it gives me a blank if I click the flags.

    SO CLOSE.

    There are, at least, no more errors in the google console now. Except I kind of wish there were since it’s still not 100%.

    Thank you so much for explaining everything as well.

    I don’t know why the flags won’t work… don’t even know where to begin. If you have any idea why please let me know. My client has also contacted the dudes who created the plugin in the first place, so hopefully they can have some input.

    Thank you for all your help thus far!

    Christina

    Moderator bcworkz

    (@bcworkz)

    Yes, error messages are kinda nice because they give you a clue to the problem. Nothing worse than a problem with no clues!

    I’m guessing the new theme page is still lacking some javascript resources. Try comparing the the javascript src links between working and non-working pages (as output to your browser, not the template code). They are not only in the header, but in the footer as well. Anything missing on the non-working page is a likely candidate, unless it’s obviously unrelated, such as Google tracker script. (starts with var _gaq = _gaq || [];)

    Besides src links, any actual missing code like the btracker_ajax assignment could be important. While it’s very much the wrong way to do things in WP, as a dirty hack to identify the problem you can simply copy any missing src links and code to the new page template. Try to ensure anything inserted gets processed in the same order as on the working page. And remember to not paste into any PHP code sections.

    Doing this can just as easily create conflicts as resolve them, but for lack of a better idea, maybe worth a go. Stay organized with incremental backups so it’s easy to back up and try something else if things get worse instead of better. Good luck!

    Thread Starter chrstna

    (@chrstna)

    Hi,

    *sobs quietly in the darkest corner of the room*

    Turns out the dev who created the plugin is working on another project so he’s unavailable to help out. Well that’s what my client says but if he exists as a person then I don’t see why he can’t help!

    I’m quite stubborn when it comes to fixing things that don’t work, but I think it’s time to move on. I am going to recommend to my client that he finds a WordPress dev to take over from this point. I’m still disappointed I couldn’t figure it out.

    Thank you for all your suggestions though, I appreciated it!

    Christina

    Moderator bcworkz

    (@bcworkz)

    You’re welcome. You certainly gave a valiant effort! It can be very difficult to work out what a different dev has done, especially when they don’t follow the recommended practice of any particular open source community.

    Unfortunately, guidelines are often disregarded by even the most well intentioned when deadlines loom. Then rifts develop between clients and devs so there’s no going back, and someone ends up with a tangled mess. Most unfortunate.

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

The topic ‘PHP shortcode of custom plugin returning white screen’ is closed to new replies.