After adding my website to a new server, I keep getting a unexpected end of file error, but the file is identitcal to it's original source
-
17-04-2021 - |
Domanda
I have this script that changes buddypress' cover image template. this file works fine on my server, but as soon as I moved it to my client's server, it broke. I keep getting the error
Parse error: syntax error, unexpected end of file in /var/www/vhosts/womenschapter.com/httpdocs/wp-content/themes/jupiterx-child/buddypress/members/single/cover-image-header.php on line 102
the file is identical across both sites though, and mine works perfectly. I can also add as many php closing tags as I want, but I still get the same error. I almost feel like the new server might be configured differently, but I am completely in the dark here.
This is my code:
<?php
/**
* BuddyPress - Users Cover Image Header
*
* @since 3.0.0
* @version 3.0.0
*/
?>
<div class="DMUserContent">
<!-- New HTML -->
<a class="DMImageColumn" href="<?php bp_displayed_user_link(); ?>">
<?php bp_displayed_user_avatar( 'type=full' ); ?>
</a>
<div class="DMContentColumn">
<h3>MEET</h3>
<?php if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) : ?>
<h1>
<?php
$DMName = bp_profile_field_data( 'field=First Name', bp_displayed_user_id() );
?> <?php
$DMName .= bp_profile_field_data( 'field=Last Name', bp_displayed_user_id() );
echo $DMName;
?>
</h1>
<!-- <h5>@<?php // bp_displayed_user_mentionname(); ?></h5> -->
<?php endif;
?>
<h4><?php bp_profile_field_data( 'field=Job Title', bp_displayed_user_id() ); ?> - <?php bp_profile_field_data( 'field=Company Name', bp_displayed_user_id() ); ?></h4>
<p class="DMSPshortDescription"><?php bp_profile_field_data( 'field=Short description of your services', bp_displayed_user_id() ); ?></p>
<div class="Divider"></div>
<p class="DMSPWebLink"><?php echo bp_profile_field_data( 'field=Website', bp_displayed_user_id()); ?></p>
<div class="DMSPSocialMediaLinks">
<?php
if (bp_get_profile_field_data( 'field=Instagram name', bp_displayed_user_id()) != null && bp_get_profile_field_data( 'field=Instagram name', bp_displayed_user_id()) != "" ){ ?>
<a class="DMSPinstagram" href='https://instagram.com/<?php echo bp_profile_field_data( 'field=Instagram name', bp_displayed_user_id()); ?>'>
<?php echo bp_profile_field_data( 'field=Instagram name', bp_displayed_user_id()); ?></a>
<?php
} ?>
<?php
if (bp_get_profile_field_data( 'field=Facebook name', bp_displayed_user_id()) != null && bp_get_profile_field_data( 'field=Facebook name', bp_displayed_user_id()) != "" ){ ?>
<a class="DMSPfacebook" href='https://facebook.com/<?php echo bp_profile_field_data( 'field=Facebook name', bp_displayed_user_id()); ?>'>
<?php echo bp_profile_field_data( 'field=Facebook name', bp_displayed_user_id()); ?></a>
<?php
} ?>
<?php
if (bp_get_profile_field_data( 'field=Twitter name', bp_displayed_user_id()) != null && bp_get_profile_field_data( 'field=Twitter name', bp_displayed_user_id()) != "" ){
?>
<a class="DMSPtwitter" href='https://Twitter.com/<?php echo bp_profile_field_data( 'field=Twitter name', bp_displayed_user_id()); ?>'>
<?php echo bp_profile_field_data( 'field=Twitter name', bp_displayed_user_id()); ?></a>
<?php
} ?>
<?php
if (bp_get_profile_field_data( 'field=Email', bp_displayed_user_id()) != null && bp_get_profile_field_data( 'field=Email', bp_displayed_user_id()) != "" ){
?>
<a class="DMSPemail" href='mailto:<?php echo bp_profile_field_data( 'field=Email', bp_displayed_user_id()); ?>'>
<?php echo bp_profile_field_data( 'field=Email', bp_displayed_user_id()); ?></a>
<?php
} ?>
</div>
<?php
if ( bp_is_my_profile() ){
?> <a href="<?php bp_displayed_user_link()?>profile" class='WCStyleButton'>Edit Profile</a>
<?php }
?>
<div id="item-header-content">
<?php
bp_nouveau_member_header_buttons(
array(
'container' => 'ul',
'button_element' => 'button',
'container_classes' => array( 'member-header-actions' ),
)
);
?>
<?php bp_nouveau_member_hook( 'before', 'header_meta' ); ?>
</div>
</div>
</div>
Soluzione
So the issue has already been resolved via the comments and the current state of the question already includes the corrected code. But I thought I should post this answer as a reminder for you, me and everyone reading this. :)
So first off, here's a helpful excerpt from an article on WP Engine:
The “unexpected end of file” error is not specific to WordPress, and can happen on any PHP-based website. This specific error means the file mentioned in the error message ends abruptly without the proper closing tags, and the code was unable to be parsed as a result.
And now here's the comment which helped solved the problem:
And also the
{?>
(change that to{ ?>
) and)?>
(change that to) ?>
) - i.e. once again, add a space (or a new line, whichever is better..) before the?>
(and after the<?php
).
And based on this answer on Stack Overflow, I believe the problem was the {?>
which should have been written as { ?>
(i.e. an opening bracket followed by a space then the closing PHP tag).
So in summary, you should not put brackets directly close to the opening/closing PHP tag, but separate it with a space:
// Bad
{?>
<?php}
// Good
{ ?>
<?php }
However, regarding this: "the file is identical across both sites though, and mine works perfectly"; it's probably because some PHP installations/setups are forgiving to brackets that are directly close to the opening/closing PHP tag. Because that seemed to be the case with my first test which was on a PHP 7.3 (Windows) install, except that I had to change the <?php; }
to <?php }
, but that's probably just a typo in the question.. :)