0

Ok, maybe I'm missing something, but I am modifying a wordpress theme functions.php file.

I am adding comments in the form of

 add_shortcode( 'member', 'member_check_shortcode' );

 function member_check_shortcode( $atts, $content = null ) {

 if ( is_user_logged_in() && !is_null( $content ) && !is_feed() ) { 

# THIS IS A COMMENT

    $content = "logged in as " . $username1;

    return $content;
 }
return '';
}

This breaks the site and I get the error:

Parse error: syntax error, unexpected end of file in /home/politehr/public_html/wp-content/themes/politehr/functions.php on line 558

Same code with the comment removed:

 add_shortcode( 'member', 'member_check_shortcode' );

 function member_check_shortcode( $atts, $content = null ) {

 if ( is_user_logged_in() && !is_null( $content ) && !is_feed() ) { 

    $content = "logged in as " . $username1;

    return $content;
 }
return '';
}

This does not break the site.

Same problem using double slashes: //

Same problem if I add ?> to the bottom of the file (it's not there on the 2013 theme). (edit: what I meant to say is that the problem is not solved by adding ?> to the bottom of the file)

What causes this problem?

EDIT: responding to comment:

@Ben comments in the format of /* comment */ work ok.

This site is brand new and I have no plugins activated.

It is the Twenty Thirteen theme that is standard with WP.

UPDATE:

Everyone who says that the code is somehow being minified or line breaks removed are probably correct...anyone know how to fix that and make my notepad++ editor insert line breaks? Or is WP doing this? I'm using notepad++ and then uploading via filezilla.

SOLUTION:

EOL conversion in notepad ++

Community
  • 1
  • 1
ssaltman
  • 3,623
  • 1
  • 18
  • 21
  • Very interesting. Just out of curiosity, does it work if you have comments in the /* format? eg: `/* This is my comment */` – Ben Apr 27 '16 at 23:03
  • do you have a plugin on the site that has a documentor? I would susect it is reading that line as a broken annotation command. – blamb Apr 27 '16 at 23:03
  • 2
    my guess minification?, the ?> closing php tags are not required, and in fact personally I don't ever use them. Are you adding this code through an wordpress editor, or in the file itself? – ArtisticPhoenix Apr 27 '16 at 23:09
  • Can you post the link of wp theme? – fusion3k Apr 27 '16 at 23:13
  • 1
    OK. I agree with @ArtisiticPhoenix - the fact that `/* comment */` works and anything that 'comments out' the rest of the line (# and //) doesn't implies that somehow the file is being either minified, or your interpreter might be expecting different line endings (UNIX vs Windows). – Ben Apr 27 '16 at 23:24

1 Answers1

0

Time ago, something like that happens to me. The reason was the differents EOL characters between platforms (Windows and Linux, in my case). The code I edited locally was transformed into one single line of code when uploaded, and the // comments breaks the code after them.

CJ Nimes
  • 648
  • 7
  • 10
  • I believe this may the answer as the errors always appear to be "line 30" even though my Notepad++ shows a different line number. Now, how do I fix this? – ssaltman Apr 28 '16 at 00:08
  • My problem was the files were created on Linux and then edited on Windows, I resolved it creating a new fresh file on Windows and pasting the code on it. Weird, but worked for me. – CJ Nimes Apr 28 '16 at 00:17
  • Also, if you can edit the file directly on the server (via cPanel, or FTP), you can try adding the missings EOLs. – CJ Nimes Apr 28 '16 at 00:19
  • It's the theme functions file so it's large. I will attempt to fix and post how I do it. Pasting into notepad and then back to notepad++ did not work. – ssaltman Apr 28 '16 at 00:24
  • It was notepad++ - see http://stackoverflow.com/questions/16239551/eol-conversion-in-notepad. I marked this as the answer. – ssaltman Apr 28 '16 at 00:29
  • Great! I use Notepad++ occasionally (I always work with Netbeans), now I will pay attention to this, just in case... – CJ Nimes Apr 28 '16 at 00:38