| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Insert PHP |
| 4 |
Plugin URI: http://www.willmaster.com/software/WPplugins/ |
| 5 |
Description: Run PHP code inserted into WordPress posts and pages. |
| 6 |
Version: 1.3 |
| 7 |
Date: 29 September 2015 |
| 8 |
Author: Will Bontrager Software, LLC <will@willmaster.com> |
| 9 |
Author URI: http://www.willmaster.com/contact.php |
| 10 |
*/ |
| 11 |
|
| 12 |
/* |
| 13 |
Copyright 2012,2013,2015 Will Bontrager Software LLC (email: will@willmaster.com) |
| 14 |
|
| 15 |
This program is free software; you can redistribute it and/or modify |
| 16 |
it under the terms of the GNU General Public License, version 2, as |
| 17 |
published by the Free Software Foundation. A copy of the license is at |
| 18 |
http://www.gnu.org/licenses/gpl-2.0.html |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
*/ |
| 25 |
|
| 26 |
/* |
| 27 |
Note: This plugin requires WordPress version 3.3.1 or higher. |
| 28 |
|
| 29 |
Information about the Insert PHP plugin can be found here: |
| 30 |
http://www.willmaster.com/software/WPplugins/go/iphphome_iphplugin |
| 31 |
|
| 32 |
Instructions and examples can be found here: |
| 33 |
http://www.willmaster.com/software/WPplugins/go/iphpinstructions_iphplugin |
| 34 |
*/ |
| 35 |
|
| 36 |
|
| 37 |
if( ! function_exists('will_bontrager_insert_php') ) |
| 38 |
{ |
| 39 |
|
| 40 |
function will_bontrager_insert_php($content) |
| 41 |
{ |
| 42 |
$will_bontrager_content = $content; |
| 43 |
preg_match_all('!\[insert_php[^\]]*\](.*?)\[/insert_php[^\]]*\]!is',$will_bontrager_content,$will_bontrager_matches); |
| 44 |
$will_bontrager_nummatches = count($will_bontrager_matches[0]); |
| 45 |
for( $will_bontrager_i=0; $will_bontrager_i<$will_bontrager_nummatches; $will_bontrager_i++ ) |
| 46 |
{ |
| 47 |
ob_start(); |
| 48 |
eval($will_bontrager_matches[1][$will_bontrager_i]); |
| 49 |
$will_bontrager_replacement = ob_get_contents(); |
| 50 |
ob_clean(); |
| 51 |
ob_end_flush(); |
| 52 |
$will_bontrager_content = preg_replace('/'.preg_quote($will_bontrager_matches[0][$will_bontrager_i],'/').'/',$will_bontrager_replacement,$will_bontrager_content,1); |
| 53 |
} |
| 54 |
return $will_bontrager_content; |
| 55 |
} # function will_bontrager_insert_php() |
| 56 |
|
| 57 |
add_filter( 'the_content', 'will_bontrager_insert_php', 9 ); |
| 58 |
|
| 59 |
} # if( ! function_exists('will_bontrager_insert_php') ) |
| 60 |
?> |
| 61 |
|