",$args);
$args = str_ireplace("[php useadvancedfilter]","",$args);
ob_start();
eval("?>".$args);
$returned = ob_get_clean();
return $returned;
}
}
$args = str_ireplace("[php useadvancedfilter]","",$args);
ob_start();
eval("?>".$args);
$returned = ob_get_clean();
return $returned;
}
function php_handler($args, $content=""){
global $is_comment;
global $wpdb;
$options = get_option("allowPHP_options");
if(isset($options['preparse'])){$preparse = $options['preparse'];}else{$preparse = 0;}
if($is_comment){return "";}
$res = "";
extract( shortcode_atts(array('debug' => 0,'silentdebug' => 0, 'function' => -1, 'mode'=>''), $args));
if(!isset($args['mode'])){$mode="";}else{$mode = $args['mode'];}
if(!isset($args['debug'])){$debug="0";}else{$debug = $args['debug'];}
if(!isset($args['silentdebug'])){$silentdebug="0";}else{$silentdebug = $args['silentdebug'];}
if($debug == 1){error_reporting(E_ALL);ini_set("display_errors","1");}
if($function == ""){$function == "-1";}
if($function == -1){
if(($preparse!= 1 && $mode != "old") || $mode == "new"){
#goodregextouse: /([\[])([\/]*[\d\w][\s\d\w\=\"\']*)([\]])/
#stage1 ([\[])([\/]*[\d\w][\s\d\w="'.$;*([\/]*)([\]])*
#stage2 ([){1}([/]*[\d\w]+[\w\d\s ]*?[ ]*?)([/]*\]){1}
#stage3 (\[){1}([/]{0,1}[\d\w]+[\w\d\s =\'\"\.\$]*?[ ]*?)([/]*\]){0,1}
#stage4 (\[{1})([\/]{0,1})([a-zA-z]{1}[a-zA-Z0-9]*[^\'\"])([a-zA-Z0-9 \!\"\£\$\%\^\&\*\*\(\)\_\-\+\=\|\\\,\.\/\?\:\;\@\'\#\~\{\[\}\]\¬\¦\`\<\>]*)([\/]{0,1})(]{1})
$content = strip_tags($content);
$count = "";
$content = preg_replace("/(\[{1})([\/]*)([a-zA-z\/]{1}[a-zA-Z0-9]*[^\'\"])([a-zA-Z0-9 \!\"\£\$\%\^\&\*\*\(\)\_\-\+\=\|\\\,\.\/\?\:\;\@\'\#\~\{\}\¬\¦\`\<\>]*)([\/]*)([\]]{1})/ix","<$3$4>",$content,"-1", $count);
$content = htmlspecialchars($content, ENT_NOQUOTES);
$content = str_replace("’","'",$content);
$content = str_replace("‘","'",$content);
$content = str_replace("′","'",$content);
$content = str_replace("“","\"",$content);
$content = str_replace("”","\"",$content);
$content = str_replace("″","\"",$content);
$content = str_replace("'","'",$content);
$content = str_replace("'","'",$content);
$content = str_replace("&","&",$content);
$content = str_replace(">",'>',$content);
$content = str_replace("<",'<',$content);
$content = htmlspecialchars_decode($content);
}
else{
$content =(htmlspecialchars($content,ENT_QUOTES));$content = str_replace("’","'",$content);$content = str_replace("‘","'",$content);$content = str_replace("′","'",$content);$content = str_replace("“","\"",$content);$content = str_replace("”","\"",$content);$content = str_replace("″","\"",$content);$content = str_replace("'","'",$content);$content = str_replace("'","'",$content);$content = str_replace("&","&",$content);$content = str_replace("<br />"," ", $content);$content = htmlspecialchars_decode($content);$content = str_replace("
"," ",$content);$content = str_replace("
"," ",$content);$content = str_replace("
"," ",$content);$content = str_replace("[br/]","End Allow PHP Debug
"; echo "Allow PHP in posts and pages adds the functionality to include PHP in your WordPress posts and pages by adding a simple shortcode [php] your code [/php]
This plugin strips away the automatically generated wordpress <p> and <br/> tags but still allows the addition of your own <p> and <br/> tags using a form of BBcode items such [p][/p] [br /]
Also, you can now save your most used PHP codes as "snippets" which you can insert into multiple pages at once.
With Version 2.2.0, the tag replacement system has been revamped which should reduce the need to escape [ and ] that shouldnt be changed < and >
To add the PHP code to your post or page simply place any PHP code inside the shortcode tags.
For example: If you wanted to add content that is visible to a particular user id:
[php] global $user_ID; if($user_ID == 1){ echo "Hello World"; } [/php]
This code will output Hello World to only user id #1, and no one else
In addition, should this code not be working (for example a missing ";") simply just change the [php] to be [php debug=1]
[php debug=1] global $user_ID; if($user_ID == 1){ echo "Hello World" } [/php]
Will result in the output:
Parse error: syntax error, unexpected '}', expecting ',' or ';' in XXX : eval()'d code on line 5 global $user_ID; if($user_ID == 1){ echo "Hello World" }
As well as the normal debug tag, you can also enable a silent debug by setting silentdebug in the [php] tag to be 1 ([php debug=1 silentdebug=1]), this will output all debug information as comments in the source code
If you are upgrading Allow PHP In Posts and Pages from a version before 2.2.0 you may experience issues with the code being disrupted as the replacement method has been changed, however you can set the tag replacement method to be the older version in the plugin options or by adding mode=old to the [php] tag, similarly, if you wish to use the new method when you have the old method turn on in the plugin options, just add mode=new to the [php] tag
To call a pre-defined function from the Code Snippets page, add function=x to the [php] tag, where x is the function id
This plugin strips away all instances of <p> and <br /> therefore code has been added so that if you wish to use tags in your output (e.g.):
[php] echo "hello <br /> world"; [/php]
The < and > tags will need to be swapped for [ and ] respectively so <p> becomes [p] and </p> becomes [/p] which is converted back to <p> at runtime. these [ ] work for all tags (p, strong, em etc.).
[php] echo "hello [br /] world"; [/php]
With code written pre-version 2.2.0 you may need to turn on support for the older replacement method as you may experience issues with the code being disrupted as the replacement method has been changed, however you can set the tag replacement method to be the older version in the plugin options or by adding mode=old to the [php] tag, similarly, if you wish to use the new method when you have the old method turn on in the plugin options, just add mode=new to the [php] tag. In the current release, only known html tags are altered by the code, other tags and square bracket items (such as PHP arrays) are no longer affected.
All snippets begin with a <?php and end with a ?> So if you wish to use html only you will need to close the php tag, then re-open it at the end.
| ID | Snippet | ||
|---|---|---|---|
| id; ?> | |||
| No Snippets Found | |||
Add A New Snippet |
|||
If this plugin has helped you, your clients or customers then please take a moment to 'say thanks'.
By spreading the word you help increase awareness of us and our plugins which makes it easier to justify the time we spend on this project.
Please help us keep this plugin free to use and allow us to provide on-going updates and support.
Here are some quick, easy and free things you can do which all help and we would really appreciate.