Title: [Plugin: WP-Syntax] [PATCH] Add &quot;include&quot; parameter
Last modified: August 20, 2016

---

# [Plugin: WP-Syntax] [PATCH] Add "include" parameter

 *  [Constantin Bosneaga](https://wordpress.org/support/users/ameoba32/)
 * (@ameoba32)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-wp-syntax-patch-add-include-parameter/)
 * I use this plugin on my blog and I like it. Recently I improved it by adding 
   new parameter “include” to the
 * `<pre>` tag. It allows you to include code from filesystem and highlight it as
   well. It is very handy when you have working example on the site and want to 
   show the source code on the blog.
 * patch is below
 *     ```
       $ diff wp-syntax.php.orig wp-syntax.php
       62c62
       <     $ext = 'pre[id|name|class|style|lang|line|escaped|hightlight|src]';
       ---
       >     $ext = 'pre[id|name|class|style|lang|line|escaped|hightlight|src|include]';
       169c169,178
       <     $code = wp_syntax_code_trim($match[6]);
       ---
       >     $include_file = wp_syntax_code_trim($match[6]);
       >     $code = wp_syntax_code_trim($match[7]);
       >
       >     if (!empty($include_file)) {
       >       if (substr($include_file,0,4) == 'http')
       >               $code = file_get_contents($include_file);
       >       elseif (file_exists(ABSPATH.$include_file))
       >               $code = file_get_contents(ABSPATH.$include_file);
       >     }
       >
       217c226
       <         "/\s*<pre(?:lang=[\"']([\w-]+)[\"']|line=[\"'](\d*)[\"']|escaped=[\"'](true|false)?[\"']|highlight=[\"']((?:\d+[,-])*\d+)[\"']|src=[\"']([^\"']+)[\"']|\s)+>(.*)<\/pre>\s*/siU",
       ---
       >         "/\s*<pre(?:lang=[\"']([\w-]+)[\"']|line=[\"'](\d*)[\"']|escaped=[\"'](true|false)?[\"']|highlight=[\"']((?:\d+[,-])*\d+)[\"']|src=[\"']([^\"']+)[\"']|include=[\"']([^\"']+)[\"']|\s)+>(.*)<\/pre>\s*/siU",
       ```
   
 * [http://wordpress.org/extend/plugins/wp-syntax/](http://wordpress.org/extend/plugins/wp-syntax/)

Viewing 1 replies (of 1 total)

 *  [parism5](https://wordpress.org/support/users/parism5/)
 * (@parism5)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-wp-syntax-patch-add-include-parameter/#post-3053807)
 * Constantin Bosneaga!!
 * Your patch work just great!! Thanks a lot. I add a warning message if file not
   found:
 * [wp-syntax.patch](http://rmf.fciencias.unam.mx/~paris/uploads/wp-syntax.patch)
 *     ```
       --- wp-syntax.php.orig	2013-01-17 13:16:59.739527313 -0600
       +++ wp-syntax.php	2013-01-18 11:00:33.664527445 -0600
       @@ -59,7 +59,7 @@
        if (!defined("WP_PLUGIN_URL"))  define("WP_PLUGIN_URL",  WP_CONTENT_URL        . "/plugins");
   
        function wp_syntax_change_mce_options($init) {
       -    $ext = 'pre[id|name|class|style|lang|line|escaped|hightlight|src]';
       +    $ext = 'pre[id|name|class|style|lang|line|escaped|hightlight|src|include]';
   
            if ( isset($init["extended_valid_elements"]) )
        	{
       @@ -166,7 +166,17 @@
            $line = trim($match[2]);
            $escaped = trim($match[3]);
            $caption = wp_syntax_caption($match[5]);
       -    $code = wp_syntax_code_trim($match[6]);
       +    $include_file = wp_syntax_code_trim($match[6]);
       +    $code = wp_syntax_code_trim($match[7]);
       +
       +    if (!empty($include_file)) {
       +       if (substr($include_file,0,4) == 'http')
       +               $code = file_get_contents($include_file);
       +       elseif (file_exists(ABSPATH.$include_file))
       +               $code = file_get_contents(ABSPATH.$include_file);
       +       if(!$code)
       +	  $code="WARNING! file :".$include_file."\nNot found.";
       +    }
   
            if ($escaped == 'true') $code = htmlspecialchars_decode($code);
   
       @@ -214,7 +224,7 @@
        function wp_syntax_before_filter($content)
        {
            return preg_replace_callback(
       -        "/\s*<pre(?:lang=[\"']([\w-]+)[\"']|line=[\"'](\d*)[\"']|escaped=[\"'](true|false)?[\"']|highlight=[\"']((?:\d+[,-])*\d+)[\"']|src=[\"']([^\"']+)[\"']|\s)+>(.*)<\/pre>\s*/siU",
       +        "/\s*<pre(?:lang=[\"']([\w-]+)[\"']|line=[\"'](\d*)[\"']|escaped=[\"'](true|false)?[\"']|highlight=[\"']((?:\d+[,-])*\d+)[\"']|src=[\"']([^\"']+)[\"']|include=[\"']([^\"']+)[\"']|\s)+>(.*)<\/pre>\s*/siU",
                "wp_syntax_substitute",
                $content
            );
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: WP-Syntax] [PATCH] Add "include" parameter’ is closed to new
replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-syntax_f8f6f6.svg)
 * [WP-Syntax](https://wordpress.org/plugins/wp-syntax/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-syntax/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-syntax/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-syntax/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-syntax/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-syntax/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [parism5](https://wordpress.org/support/users/parism5/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-wp-syntax-patch-add-include-parameter/#post-3053807)
 * Status: not resolved