| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Insert PHP Code Snippet |
| 4 |
Plugin URI: http://xyzscripts.com/wordpress-plugins/insert-php-code-snippet/ |
| 5 |
Description: Insert and run PHP code in your pages and posts easily using shortcodes. This plugin lets you create a shortcode for any PHP code and use it in your posts, pages, or widgets. It also includes flexible snippet placement options: Automatic, Execute on Demand, and Manual Shortcode. |
| 6 |
Version: 1.4.5 |
| 7 |
Author: xyzscripts.com |
| 8 |
Author URI: http://xyzscripts.com/ |
| 9 |
Text Domain: insert-php-code-snippet |
| 10 |
License: GPLv2 or later |
| 11 |
*/ |
| 12 |
|
| 13 |
/* |
| 14 |
This program is free software; you can redistribute it and/or |
| 15 |
modify it under the terms of the GNU General Public License |
| 16 |
as published by the Free Software Foundation; either version 2 |
| 17 |
of the License, or (at your option) any later version. |
| 18 |
|
| 19 |
This program is distributed in the hope that it will be useful, |
| 20 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
GNU General Public License for more details. |
| 23 |
|
| 24 |
You should have received a copy of the GNU General Public License |
| 25 |
along with this program; if not, write to the Free Software |
| 26 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 27 |
*/ |
| 28 |
|
| 29 |
// if ( !function_exists( 'add_action' ) ) { |
| 30 |
// echo "Hi there! I'm just a plugin, not much I can do when called directly."; |
| 31 |
// exit; |
| 32 |
// } |
| 33 |
if ( ! defined( 'ABSPATH' ) ) |
| 34 |
exit; |
| 35 |
|
| 36 |
//error_reporting(E_ALL); |
| 37 |
|
| 38 |
define('XYZ_INSERT_PHP_PLUGIN_FILE',__FILE__); |
| 39 |
|
| 40 |
require( dirname( __FILE__ ) . '/xyz-functions.php' ); |
| 41 |
|
| 42 |
require( dirname( __FILE__ ) . '/add_shortcode_tynimce.php' ); |
| 43 |
|
| 44 |
require( dirname( __FILE__ ) . '/admin/install.php' ); |
| 45 |
|
| 46 |
require( dirname( __FILE__ ) . '/admin/menu.php' ); |
| 47 |
|
| 48 |
require( dirname( __FILE__ ) . '/shortcode-handler.php' ); |
| 49 |
|
| 50 |
require( dirname( __FILE__ ) . '/ajax-handler.php' ); |
| 51 |
|
| 52 |
require( dirname( __FILE__ ) . '/admin/uninstall.php' ); |
| 53 |
|
| 54 |
require( dirname( __FILE__ ) . '/widget.php' ); |
| 55 |
|
| 56 |
require( dirname( __FILE__ ) . '/direct_call.php' ); |
| 57 |
|
| 58 |
require_once( dirname( __FILE__ ) . '/admin/admin-notices.php' ); |
| 59 |
|
| 60 |
if(get_option('xyz_credit_link')=="ips"){ |
| 61 |
|
| 62 |
add_action('wp_footer', 'xyz_ips_credit'); |
| 63 |
|
| 64 |
} |
| 65 |
function xyz_ips_credit() { |
| 66 |
$content = '<div style="width:100%;text-align:center; font-size:11px; clear:both"><a target="_blank" title="Insert PHP Snippet Wordpress Plugin" href="http://xyzscripts.com/wordpress-plugins/insert-php-code-snippet/">PHP Code Snippets</a> Powered By : <a target="_blank" title="PHP Scripts & Wordpress Plugins" href="http://www.xyzscripts.com" >XYZScripts.com</a></div>'; |
| 67 |
echo $content; |
| 68 |
} |
| 69 |
add_action('admin_init', 'xyz_ips_check_and_upgrade_plugin_version'); |
| 70 |
|
| 71 |
function xyz_ips_check_and_upgrade_plugin_version() { |
| 72 |
|
| 73 |
$current_version = xyz_ips_plugin_get_version(); |
| 74 |
$saved_version = get_option('xyz_ips_free_version'); |
| 75 |
if ($saved_version === false) { |
| 76 |
xyz_ips_run_upgrade_routines(); |
| 77 |
add_option('xyz_ips_free_version', $current_version); |
| 78 |
} elseif (version_compare($current_version, $saved_version, '>')) { |
| 79 |
xyz_ips_run_upgrade_routines(); |
| 80 |
update_option('xyz_ips_free_version', $current_version); |
| 81 |
} |
| 82 |
} |
| 83 |
add_filter('plugin_action_links_' . plugin_basename(XYZ_INSERT_PHP_PLUGIN_FILE), 'xyz_ips_plugin_action_links'); |
| 84 |
function xyz_ips_plugin_action_links($links) { |
| 85 |
if (isset($links['deactivate'])) { |
| 86 |
if (preg_match('/href=[\'"]([^\'"]+)[\'"]/', $links['deactivate'], $matches)) { |
| 87 |
$deactivation_url_ips = esc_url($matches[1]); |
| 88 |
$links['deactivate'] = '<a href="' . $deactivation_url_ips . '" class="xyz-ips-deactivate-link">Deactivate</a>'; |
| 89 |
} |
| 90 |
} |
| 91 |
return $links; |
| 92 |
} |
| 93 |
add_action('admin_enqueue_scripts', 'xyz_ips_enqueue_modal_assets'); |
| 94 |
function xyz_ips_enqueue_modal_assets($hook) { |
| 95 |
if ($hook !== 'plugins.php') return; |
| 96 |
// Output modal HTML |
| 97 |
add_action('admin_footer', 'xyz_ips_modal_html'); |
| 98 |
} |
| 99 |
function xyz_ips_modal_html() { |
| 100 |
?> |
| 101 |
<div id="xyz-ips-modal" class="xyz-ips-modal-overlay" style="display:none;"> |
| 102 |
<div class="xyz-ips-modal-box"> |
| 103 |
<h2>Are you sure you want to deactivate?</h2> |
| 104 |
<p> |
| 105 |
<span class="dashicons dashicons-warning" style="color: #d63638; font-size: 20px; vertical-align: middle;"></span> |
| 106 |
<strong> <u>Deleting</u> Insert PHP Code Snippet <u>afterward</u> will permanently remove all saved snippets, and any shortcodes using them will stop working.</strong> |
| 107 |
</p> |
| 108 |
<div class="xyz-ips-modal-buttons"> |
| 109 |
<button id="xyz-ips-proceed-deactivate" class="button button-primary">Proceed to Deactivate</button> |
| 110 |
<button id="xyz-ips-cancel-deactivate" class="button">Cancel</button> |
| 111 |
</div> |
| 112 |
</div> |
| 113 |
</div> |
| 114 |
<?php |
| 115 |
} |
| 116 |
// --- update manual shortcode counts --- |
| 117 |
add_action('save_post', function($post_id, $post) { |
| 118 |
if (wp_is_post_autosave($post_id)) return; |
| 119 |
if (wp_is_post_revision($post_id)) return; |
| 120 |
if (!$post) return; |
| 121 |
if ($post->post_status !== 'publish') { |
| 122 |
global $wpdb; |
| 123 |
$wpdb->delete($wpdb->prefix . 'xyz_ips_usage', ['post_id' => $post_id]); |
| 124 |
return; |
| 125 |
} |
| 126 |
xyz_ips_update_usage_for_post( |
| 127 |
$post_id, |
| 128 |
$post->post_content, |
| 129 |
$post->post_type |
| 130 |
); |
| 131 |
}, 10, 2); |
| 132 |
add_action('before_delete_post', function($post_id) { |
| 133 |
global $wpdb; |
| 134 |
$wpdb->delete($wpdb->prefix . 'xyz_ips_usage', ['post_id' => $post_id]); |
| 135 |
}); |
| 136 |
?> |
| 137 |
|