0, 'function' => -1), $args));
if($args['debug'] == 1){error_reporting(E_ALL);ini_set("display_errors","1");}
if($args['function'] == -1){
$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/]","
",$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{
$options = get_option("allowPHP_options");
$show404 = $options['show404'];
$fourohfourmsg = $options['fourohfourmsg'];
if($fourohfourmsg != 0){
$fourohfourmsg = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."allowPHP_functions WHERE id = '".$fourohfourmsg."';");
$fourohfourmsg = $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 = $res[0]->function;}
}
ob_start();
eval ($content);
if($args['debug'] == 1){
$content =(htmlspecialchars($content,ENT_QUOTES));
echo ("".$content."
");
}
$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');
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
Developed by Hit Reach
Check out our other Wordpress Plugins
Version: 2.0.0 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.
-
Promote this plugin on Twitter
-
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.
-
Like us on Facebook
Just visit www.facebook.com/webdesigndundee and hit the 'Like!' button!
-
Share this plugin on Facebook
Share a link to the plugin page with your friends on Facebook
-
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
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 tag replacement system.
Also, you can now save your most used PHP codes as "snippets" which you can insert into multiple pages at once.
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"
}
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]
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
Developed by Hit Reach
Check out our other Wordpress Plugins
Version: 2.0.0 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.
-
Promote this plugin on Twitter
-
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.
-
Like us on Facebook
Just visit www.facebook.com/webdesigndundee and hit the 'Like!' button!
-
Share this plugin on Facebook
Share a link to the plugin page with your friends on Facebook
-
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
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.
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('url')."/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 += 2;
return $ver;
}
add_action('init', 'add_APIP_button');
add_filter( 'tiny_mce_version', 'APIP_my_refresh_mce');
?>