| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: PHP code snippets (Insert PHP) |
| 4 |
* Plugin URI: https://wordpress.org/plugins/insert-php/ |
| 5 |
* Description: Run PHP code inserted into WordPress posts and pages. An easy, clean and easy way to add code snippets to your site. You do not need to edit the functions.php file of your theme again! |
| 6 |
* Author: Will Bontrager Software, LLC <will@willmaster.com>, Webcraftic <wordpress.webraftic@gmail.com> |
| 7 |
* Version: 2.0.4 |
| 8 |
* Text Domain: insert-php |
| 9 |
* Domain Path: /languages/ |
| 10 |
* Author URI: http://www.willmaster.com/contact.php |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly |
| 14 |
if( !defined('ABSPATH') ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
if( defined('WINP_PLUGIN_ACTIVE') ) { |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
// Set the constant that the plugin is activated |
| 23 |
define('WINP_PLUGIN_ACTIVE', true); |
| 24 |
|
| 25 |
// Root directory of the plugin |
| 26 |
define('WINP_PLUGIN_DIR', dirname(__FILE__)); |
| 27 |
|
| 28 |
// Absolute url of the root directory of the plugin |
| 29 |
define('WINP_PLUGIN_URL', plugins_url(null, __FILE__)); |
| 30 |
|
| 31 |
// Relative url of the plugin |
| 32 |
define('WINP_PLUGIN_BASE', plugin_basename(__FILE__)); |
| 33 |
|
| 34 |
// The type of posts used for snippets types |
| 35 |
define('WINP_SNIPPETS_POST_TYPE', 'wbcr-snippets'); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
global $wp_version; |
| 40 |
|
| 41 |
// Troubleshoot old versions of WordPress |
| 42 |
if( version_compare($wp_version, '4.2.0', '>') ) { |
| 43 |
|
| 44 |
require_once(WINP_PLUGIN_DIR . '/libs/factory/core/boot.php'); |
| 45 |
|
| 46 |
require_once(WINP_PLUGIN_DIR . '/includes/class.helpers.php'); |
| 47 |
require_once(WINP_PLUGIN_DIR . '/includes/class.plugin.php'); |
| 48 |
|
| 49 |
new WINP_Plugin(__FILE__, array( |
| 50 |
'prefix' => 'wbcr_inp_', |
| 51 |
'plugin_name' => 'wbcr_insert_php', |
| 52 |
'plugin_title' => __('PHP code snippets (Insert PHP)', 'insert-php'), |
| 53 |
'plugin_version' => '2.0.4', |
| 54 |
'required_php_version' => '5.2', |
| 55 |
'required_wp_version' => '4.2', |
| 56 |
'plugin_build' => 'free', |
| 57 |
//'updates' => WINP_PLUGIN_DIR . '/updates/' |
| 58 |
)); |
| 59 |
} else { |
| 60 |
// Notification about the old version of Wordpress |
| 61 |
add_action('admin_notices', function () { |
| 62 |
echo '<div class="notice notice-error"><p>' . __('You are using the old version of Wordpress, for the <b>PHP code snippets (Insert PHP)</b> plugin you need Wordpress 4.2 and higher versions!', 'insert-php') . '</p></div>'; |
| 63 |
}); |
| 64 |
} |
| 65 |
|
| 66 |
/* |
| 67 |
Note: This plugin requires WordPress version 3.3.1 or higher. |
| 68 |
|
| 69 |
Information about the Insert PHP plugin can be found here: |
| 70 |
http://www.willmaster.com/software/WPplugins/go/iphphome_iphplugin |
| 71 |
|
| 72 |
Instructions and examples can be found here: |
| 73 |
http://www.willmaster.com/software/WPplugins/go/iphpinstructions_iphplugin |
| 74 |
*/ |
| 75 |
|
| 76 |
// todo: This is the code of the old version of the plugin, left unchanged for compatibility. Delete in the new major version of the plugin |
| 77 |
if( !function_exists('will_bontrager_insert_php') ) { |
| 78 |
|
| 79 |
function will_bontrager_insert_php($content) |
| 80 |
{ |
| 81 |
$will_bontrager_content = $content; |
| 82 |
preg_match_all('!\[insert_php[^\]]*\](.*?)\[/insert_php[^\]]*\]!is', $will_bontrager_content, $will_bontrager_matches); |
| 83 |
$will_bontrager_nummatches = count($will_bontrager_matches[0]); |
| 84 |
for($will_bontrager_i = 0; $will_bontrager_i < $will_bontrager_nummatches; $will_bontrager_i++) { |
| 85 |
ob_start(); |
| 86 |
eval($will_bontrager_matches[1][$will_bontrager_i]); |
| 87 |
$will_bontrager_replacement = ob_get_contents(); |
| 88 |
ob_clean(); |
| 89 |
ob_end_flush(); |
| 90 |
$will_bontrager_content = preg_replace('/' . preg_quote($will_bontrager_matches[0][$will_bontrager_i], '/') . '/', $will_bontrager_replacement, $will_bontrager_content, 1); |
| 91 |
} |
| 92 |
|
| 93 |
return $will_bontrager_content; |
| 94 |
} # function will_bontrager_insert_php() |
| 95 |
|
| 96 |
add_filter('the_content', 'will_bontrager_insert_php', 9); |
| 97 |
} # if( ! function_exists('will_bontrager_insert_php') ) |
| 98 |
|