0

We got a Wordpress site, designed by an external contractor a couple years ago. https://playbacktheatre.com.au

We recently (Dec 2019) changed hosting providers in search of a better service. After the migration the site was working smoothly and it was much faster, as we hoped it would be.

Recently though we got a problem with the home page throwing an HTTP 500 error. I believe this was triggered by the update of one of the pages (https://playbacktheatre.com.au/performances/) using the Wordpress admin panel. Only the home page throws this error, all other pages seem to be working ok.

I asked for a restoration of a previous state from our provider and they did it. (I later found that they restored only a single folder [httpdocs] that contains just the static files and the code. They did not restore the database, nor the plugins, nor Wordpress itself.) The problem was gone! I then I did the update on the page I wanted again (performances/). The problem with the home page reappeared.

I started digging in, using the tools our hosting provider has (Plesk). I found the 500 error in the logs. Here's the error:

.953468 [NOTICE] [960332] [103.27.34.22:38726-1#APVH_playbacktheatre.com.au:lsapi] [STDERR] PHP Parse error: syntax error, unexpected 'endif' (T_ENDIF) in /var/www/vhosts/playbacktheatre.com.au/httpdocs/site/wp-content/themes/playback/front-page.php on line 186

I browsed the front-page.php file trying to find something obviously wrong with line 186 (I am not familiar with php, but I am comfortable with programming and other languages). I could not see anything wrong. Then I restored again the website to a prior working state (I found how to do it on my own, I restored only the httpdocs folder) and checked that the home page was working. I browsed again the front-page.php in the hope of finding something different. The file was exactly the same as before (compared with diff). I am puzzled with this. How come the error appears in one case and not the other? Is it a matter of different portions of the php script running? I would expect a syntax error like this to throw an error regardless.

I am happy to post the full php file here (191 lines) but just to give you a taste, the offending endif statement is the second to last.

    <?php if( have_rows('page_previews') ): while ( have_rows('page_previews') ) : the_row(); ?>

        <?
        $post_object = get_sub_field('page');

        $useCustom = get_sub_field('custom_content');
        $cTitle = get_sub_field('custom_title');
        $cSubtitle = get_sub_field('custom_subtitle');
        $cText = get_sub_field('custom_excerpt');
        $linkType = get_sub_field('link');
        $align = get_sub_field('text_align');

        if($post_object) :

           $post = $post_object;
           setup_postdata( $post );
            ?>

            <section id="<?php echo $post->post_name; ?>" class="preview">

 (... more code ...)

        <?php endif;?>    (<- This is line 186)
        <?php endwhile; endif; ?>

Other things that I tried to fix the problem:

  • Updates Wordpress from 4.8.x to 5.3.x, and updated plugins using Plesk
  • Deactivated plugins using the Wordpress admin panel

I can try doing a more full restoration (database and everything) but I am a bit uncertain on how to do this right. My folder structure is the following:

Name    Modified    Size
.cagefs         Dec 20, 2019 03:23 AM
.cl.selector    Feb 5, 2020 03:23 AM    
.pki            Dec 19, 2019 06:43 PM   
.revisium_antivirus_cache   Dec 20, 2019 07:37 PM
.ssh            Dec 21, 2019 01:00 AM   
.wp-cli         Dec 20, 2019 03:24 AM   
error_docs      Dec 19, 2019 06:42 PM   
httpdocs        Dec 20, 2019 06:00 PM   
httpdocs.bak    Dec 20, 2019 05:36 PM
logs            Feb 19, 2020 03:28 AM   
lscache         Dec 20, 2019 02:48 PM   
migration       Dec 20, 2019 12:42 PM   
site.bak        Dec 20, 2019 05:36 PM   
snapshots       Feb 17, 2020 04:19 PM   
wp_h8yyl_2019-12-20_17-33-19.sql.zip Dec 20, 2019 05:33 PM  1.4 MB

Any advice is very welcome.

0

Your if statment is using an alternative syntax so it needs to be in the following structure which changes the standard opening brace { to a colon : and the closing brace } to endif;

if ($post_object): 
    // Code if true
    else: 
    // Code if false
endif

I'm not sure this will fully fix your problem as there could be different PHP versions on the new server with deprecated functions in the theme, but it should help.

| improve this answer | |
  • I'll try it, but this does not explain why the error does not appear when the file is restored (but nothing changes) – Thanassis Feb 19 at 7:41
  • yes, I know. It seems strange. – TomC Feb 19 at 7:49
  • I updated the code in my description. – Thanassis Feb 19 at 7:49
  • There are no curly braces in the syntax, and all statements are tagged with <?php> tags (I suppose this code was autogenerated). Not sure if my updated description helps. – Thanassis Feb 19 at 7:59
  • 1
    Just to explain more of what is going on, your home page is using front_page.php file as a template. That template is calling the get_sub_field('page') function so I suspect whatever is in your performances page is supposed to appear on the front page and that is possibly what is causing the problem. – TomC Feb 19 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.