Title: php opening &amp; closing tags break code blocks
Last modified: August 31, 2016

---

# php opening & closing tags break code blocks

 *  Resolved [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/)
 * With a recent update, some of my code blocks broke: it closed the php shortcode
   automatically when there were multiple php opening and closing tags in the snippet.
 * Example:
 *     ```
       [php]
       add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_due_date', 10, 2 );
       function wpo_wcpdf_due_date ($template_type, $order) {
       	if ($template_type == 'invoice') { // put due date only on invoice
       		$invoice_date = get_post_meta( $order->id, '_wcpdf_invoice_date', true );
       		$due_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date . ' + 14 days') );
       		?>
       		<tr class="due-date">
       			<th>Due Date:</th>
       			<td><?php echo $due_date; ?></td>
       		</tr>
       		<?php
       	}
       }
       [/php]
       ```
   
 * would save as (note the small but significant change in the first line):
 *     ```
       [php][/php]
       add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_due_date', 10, 2 );
       function wpo_wcpdf_due_date ($template_type, $order) {
       	if ($template_type == 'invoice') { // put due date only on invoice
       		$invoice_date = get_post_meta( $order->id, '_wcpdf_invoice_date', true );
       		$due_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date . ' + 14 days') );
       		?>
       		<tr class="due-date">
       			<th>Due Date:</th>
       			<td><?php echo $due_date; ?></td>
       		</tr>
       		<?php
       	}
       }
       [/php]
       ```
   
 * This could be fixed by doing:
 *     ```
       [php]
       <?php
       add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_due_date', 10, 2 );
       function wpo_wcpdf_due_date ($template_type, $order) {
       	if ($template_type == 'invoice') { // put due date only on invoice
       		$invoice_date = get_post_meta( $order->id, '_wcpdf_invoice_date', true );
       		$due_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date . ' + 14 days') );
       		?>
       		<tr class="due-date">
       			<th>Due Date:</th>
       			<td><?php echo $due_date; ?></td>
       		</tr>
       		<?php
       	}
       }
       ?>
       [/php]
       ```
   
 * but that’s not what I want because I don’t want my customers to put the php tags
   in there theme functions (when blindly copy pasting).
 * Is there any other way to prevent this? Is this a bug or a feature?
 * [https://wordpress.org/plugins/syntaxhighlighter/](https://wordpress.org/plugins/syntaxhighlighter/)

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

 *  [kronoswp](https://wordpress.org/support/users/kronoswp/)
 * (@kronoswp)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/#post-7073013)
 * +1 I have the same issue with csharp highlighting. The only fix I have found 
   for the moment is to have some form of tags at the start and end of the code 
   eg:
 * [csharp]
    <some tag> // all my code here `</some tag> [/csharp]
 * The issue is that obviously these tags show up in the highlighted code which 
   looks stupid. This only happened after the update. Is there a way to avoid having
   to use arbitrary tags?
 *  Plugin Contributor [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * (@viper007bond)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/#post-7073033)
 * I can reproduce this bug and am investigating.
 *  Plugin Contributor [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * (@viper007bond)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/#post-7073040)
 * Well that was interesting to debug. Basically it comes down to security improvements
   in core.
 * The recent update to my plugin was intended to prevent my plugin’s shortcodes
   from being used inside of HTML tags which was causing a security vulnerability.
   For example, this shouldn’t be allowed:
 *     ```
       <strong [code]hello[/code]></strong>
       ```
   
 * My release fixed that but now the `<?php` is being interpreted as an opening 
   HTML tag and so the closing shortcode is sort of being ignored.
 * So when my plugin comes along, core is parsing the `[php]` as a self-closing 
   shortcode, similar to `[gallery]` works.
 * However my plugin parses it’s shortcodes when on the way into the database in
   order to HTML entity escape the contents of the shortcodes, for example `[code]
   <foo>[/code]` into `[code]& lt;foo& gt;[/code]` (without the spaces). This is
   so that even if my plugin is disabled, you’ll never get bad HTML run on your 
   site.
 * To do this, it takes the content and then re-wraps it in the shortcode tags. 
   It gets passed `<foo>` and returns `[code]& lt;foo& gt;[/code]` so that the shortcode
   tags stick around (normally you want shortode tags removed when they’re processed).
 * So that explains where the extra `[/php]` is coming from.
 * Anyway, I’ve opened a core bug ticket to see if this is working as intended or
   not: [https://core.trac.wordpress.org/ticket/35856](https://core.trac.wordpress.org/ticket/35856)
 * If it is, I’ll come up with some type of work around.
 *  Thread Starter [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/#post-7073041)
 * Thank you Alex, I really appreciate the effort!
 * Keep up the good work 🙂
 *  Plugin Contributor [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * (@viper007bond)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/#post-7073043)
 * This should be fixed in version 3.2.1 which was just released. I figured out 
   a way to work around the issue.
 *  [firebirder](https://wordpress.org/support/users/firebirder/)
 * (@firebirder)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/#post-7073075)
 * Hi
 * Seems, the problem still exists (v3.2.1).
 * Test code:
 *     ```
       [sourcecode language="csharp"]
          while(sb.Length<c_min_text_size)
           sb.Append(c_template_str);
       [/sourcecode]
       ```
   
 *  Thread Starter [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/#post-7073082)
 * I can confirm the fix works for the issue I had with the PHP opening/closing 
   tags specifically. Thanks for the great work alex! 5 stars from me 🙂
 * Ewout
 *  Plugin Contributor [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * (@viper007bond)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/#post-7073090)
 * > Seems, the problem still exists (v3.2.1).
 * Hmm, working fine for me, at least via the text editor (the visual editor is 
   kind of a mess). What’s the exact issue that’s occurring for you? I’ll need more
   details if I’m going to be able to help. 🙂
 *  [firebirder](https://wordpress.org/support/users/firebirder/)
 * (@firebirder)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/#post-7073093)
 * Hi
 * The problem with **existing** posts with source code.
 * After installation of v3.2.1, source code displayed incorrectly.
 * Need open the code in editor and save it – “sb.Length < c_min_text_size” will
   be saved in database as “sb.Length **[html entity for <]** c_min_text_size”.
 * ———–
    Step for reproduction:
 * 1. Create new post in WP (with your v3.2.1):
 * [sourcecode language="csharp"]
    while(sb.Length<c_min_text_size) sb.Append(c_template_str);[/
   sourcecode]
 * 2. Open the WP database in Workbench
 * 3. Select the post record:
    select * from wp_posts p where p.post_name like ‘%
   NEW_TEST_POST_NAME%’
 * 4. Replace the ‘Post_content’ field to:
 * [sourcecode language="csharp"]
    while(sb.Length<c_min_text_size) sb.Append(c_template_str);[/
   sourcecode]
 * 5. Open the post in web browser.
 *  Plugin Contributor [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * (@viper007bond)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/#post-7073106)
 * I think the support forums are messing up your code. Can you throw it on [http://pastebin.com/](http://pastebin.com/)
   or some other code posting site?
 * Also when was your broken post written? Was it recently, when you have version
   3.2.0 installed? Or is this a very old post and version 3.2.1 has broken it?
 * Posts written with plugin version 3.2.0 installed may very well have been broken
   and you’ll need to manually fix it.
 * Posts written before a few weeks ago should still work fine. Here’s an example
   from my site:
 * [http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/](http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/)
 * If you’re looking at the post contents in the database, then HTML entities within
   the shortcodes should be escaped. That is, the `<` in your code should be a `
   <` in the editor but it should be `&``lt;` in the database. If you see this, 
   then it is working correctly!
 *  [firebirder](https://wordpress.org/support/users/firebirder/)
 * (@firebirder)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/#post-7073125)
 * Hi Alex.
 * Forgive me for pause with answer.
 * My posts with source code were created manually. I directly created the database
   records, when I migrated my site (~15 years old) onto WP. My WP-site uses custom
   theme with disabled ‘wpautop’.
 * I do not mask the ‘<‘,’>’ and other symbols. Because all worked without this 
   transfomation. May be it is my mistake.
 * Before 3.2.0 all worked fine. After – no.
 * I will think about correction of my database in future.
 * —–
    The URL of problem source code – [http://www.ibprovider.com/eng/examples/lcpi_oledb_net__c001__example_0008.html](http://www.ibprovider.com/eng/examples/lcpi_oledb_net__c001__example_0008.html)
 * —–
    Regards, Dmitry Kovalenko.

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

The topic ‘php opening & closing tags break code blocks’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/syntaxhighlighter_ffffff.svg)
 * [SyntaxHighlighter Evolved](https://wordpress.org/plugins/syntaxhighlighter/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/syntaxhighlighter/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/syntaxhighlighter/)
 * [Active Topics](https://wordpress.org/support/plugin/syntaxhighlighter/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/syntaxhighlighter/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/syntaxhighlighter/reviews/)

 * 11 replies
 * 4 participants
 * Last reply from: [firebirder](https://wordpress.org/support/users/firebirder/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks/#post-7073125)
 * Status: resolved