",$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("&#8217;","'",$content); $content = str_replace("&#8216;","'",$content); $content = str_replace("&#8242;","'",$content); $content = str_replace("&#8220;","\"",$content); $content = str_replace("&#8221;","\"",$content); $content = str_replace("&#8243;","\"",$content); $content = str_replace("&#039;","'",$content); $content = str_replace("'","'",$content); $content = str_replace("&#038;","&",$content); $content = str_replace("&gt;",'>',$content); $content = str_replace("&lt;",'<',$content); $content = htmlspecialchars_decode($content); } else{ $content =(htmlspecialchars($content,ENT_QUOTES));$content = str_replace("&#8217;","'",$content);$content = str_replace("&#8216;","'",$content);$content = str_replace("&#8242;","'",$content);$content = str_replace("&#8220;","\"",$content);$content = str_replace("&#8221;","\"",$content);$content = str_replace("&#8243;","\"",$content);$content = str_replace("&#039;","'",$content);$content = str_replace("'","'",$content);$content = str_replace("&#038;","&",$content);$content = str_replace("&lt;br /&gt;"," ", $content);$content = htmlspecialchars_decode($content);$content = str_replace("
"," ",$content);$content = str_replace("

"," ",$content);$content = str_replace("

"," ",$content);$content = str_replace("[br/]","
",$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); } } else{ $show404 = $options['show404']; $fourohfourmsg = $options['fourohfourmsg']; if($fourohfourmsg != 0){ $fourohfourmsg = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."allowPHP_functions WHERE id = '".$fourohfourmsg."';"); $fourohfourmsg = htmlspecialchars_decode($fourohfourmsg[0]->function); } else{ $fourohfourmsg = '?>
Error 404: Function Not Found
'; } $id = $args['function']; $sql = "SELECT function FROM ".$wpdb->prefix."allowPHP_functions WHERE id='".$id."'"; $res = $wpdb->get_results($wpdb->prepare($sql)); if(sizeof($res) == 0){ if($show404 == 1){$content = $fourohfourmsg;} } else{ $content = htmlspecialchars_decode($res[0]->function); } } ob_start(); eval ($content); if($debug == 1||$silentdebug == 1){ if($silentdebug == 1){ echo "\n\n\n\n"; } else{ echo "

End Allow PHP Debug

"; echo "
"; } } $returned = ob_get_clean(); return $returned; } function allow_php_menu(){ add_menu_page( "Allow PHP in posts and pages", "Allow PHP in posts", "manage_options", "allow-php-menu", "allowPHP_functions"); add_submenu_page('allow-php-menu','Information', 'Information', 'manage_options', 'allow-php-information', 'allow_php_information'); } function allow_php_information(){ ?>

Allow PHP in Posts and Pages

General Information

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 >

Usage

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

Some Important Notes

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.

Tag list

For Write as
<p> ... </p> [p] ... [/p]
<em>...</em> [em]...[/em]
<p style=''> ... </p> [p style=''] ... [/p]
<u> ... </u> [u] ... [/u]
<br /> [br /]
get_results($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."allowPHP_functions WHERE id = '".$fourohfourmsg."';")); $fourohfourmsg = $fourohfourmsg[0]->function; } else{$fourohfourmsg = 'Error 404: Function Not Found';} $sql = "SELECT * FROM ".$wpdb->prefix."allowPHP_functions"; $results = $wpdb->get_results($wpdb->prepare($sql)); ?>

Allow PHP in Posts and Pages

Plugin Options

alter.php' method="post">

Current 404 message:

/>
/>
/>

Caution:: enabling the advanced filter method renders the code replacement version un-useable, so please be sure to convert all tags be be usable with this method first

The advanced filter method can be enabled manually using the php tag [php useadvancedfilter] php code [/php useadvancedfilter]

Code Snippets are not currently supported with the new method, check back soon though!

Do you like this new filter? Let us know on the blog!

Code Snippets

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; ?>
alter.php' method="post" onsubmit="return confirmMod(id; ?>)"> Name:
<?php ?>
alter.php' method="post" onsubmit="return confirmDel(id; ?>)">  | 
No Snippets Found
 

Add A New Snippet

 
alter.php' method="post"> Name:
<?php ?>
APIP_changeTab('APIP_usage','APIP_usageTab');";}?> prefix."allowPHP_functions( id int NOT NULL AUTO_INCREMENT, name varchar(100) NOT NULL, function text NOT NULL, PRIMARY KEY(id) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } $options = array("show404" => $show404,"fourohfourmsg" => $fourohfourmsg, "dbVersion" => $dbVersion); update_option("allowPHP_options", $options); } function add_APIP_button() { if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ){ return; } if ( get_user_option('rich_editing') == 'true') { add_filter('mce_external_plugins', 'add_APIP_tinymce_plugin'); add_filter('mce_buttons', 'register_APIP_button'); } } define( "APIP_PLUGIN_DIR", "allow-php-in-posts-and-pages" ); define( "APIP_PLUGIN_URL", get_bloginfo('wpurl')."/wp-content/plugins/" . APIP_PLUGIN_DIR ); function register_APIP_button($buttons) { array_push($buttons, "|", "allowPHP"); return $buttons; } function add_APIP_tinymce_plugin($plugin_array) { $plugin_array['allowPHP'] = APIP_PLUGIN_URL . '/AP.js'; return $plugin_array; } function APIP_my_refresh_mce($ver) { $ver += 5; return $ver; } add_action('init', 'add_APIP_button'); add_filter( 'tiny_mce_version', 'APIP_my_refresh_mce'); function APIP_Appeal(){ ?>
Developed by Hit Reach Check out our other Wordpress Plugins Version: Support, Comments & Questions

Please help! We need your support...

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.

  1. Promote this plugin on Twitter


  2. Link to us
    By linking to www.hitreach.co.uk from your site or blog it means you can help others find the plugin on our site and also let Google know we are trust and link worthy which helps our profile.

  3. Like us on Facebook
    Just visit www.facebook.com/webdesigndundee and hit the 'Like!' button!

  4. Share this plugin on Facebook
    Share a link to the plugin page with your friends on Facebook

  5. Make A Donation
    Ok this one isn't really free but hopefully it's still a lot cheaper than if you'd had to buy the plugin or pay for it to be made for your project. Any amount is appreciated