| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: Search & Replace Everything |
| 4 |
* Plugin URI: https://wpcode.com/ |
| 5 |
* Description: Search & Replace text and images across your entire WordPress database with a simple, powerful interface. |
| 6 |
* Version: 1.0.7 |
| 7 |
* Author: WPCode |
| 8 |
* Author URI: https://wpcode.com |
| 9 |
* License: GPL2 |
| 10 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 11 |
* Text Domain: search-replace-wpcode |
| 12 |
* Domain Path: /languages |
| 13 |
*/ |
| 14 |
|
| 15 |
// Exit if accessed directly. |
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
// Don't allow multiple versions to be active. |
| 21 |
if ( function_exists( 'wsrw_main' ) ) { |
| 22 |
|
| 23 |
if ( ! function_exists( 'wsrw_pro_just_activated' ) ) { |
| 24 |
/** |
| 25 |
* When we activate a Pro version, we need to do additional operations: |
| 26 |
* 1) deactivate a Lite version; |
| 27 |
* 2) register option which help to run all activation process for Pro version (custom tables creation, etc.). |
| 28 |
*/ |
| 29 |
function wsrw_pro_just_activated() { |
| 30 |
wsrw_deactivate(); |
| 31 |
add_option( 'wsrw_install', 1 ); |
| 32 |
} |
| 33 |
} |
| 34 |
add_action( 'activate_search-replace-wpcode-pro/wsrw-premium.php', 'wsrw_pro_just_activated' ); |
| 35 |
|
| 36 |
if ( ! function_exists( 'wsrw_lite_just_activated' ) ) { |
| 37 |
/** |
| 38 |
* Store temporarily that the Lite version of the plugin was activated. |
| 39 |
* This is needed because WP does a redirect after activation and |
| 40 |
* we need to preserve this state to know whether user activated Lite or not. |
| 41 |
*/ |
| 42 |
function wsrw_lite_just_activated() { |
| 43 |
|
| 44 |
set_transient( 'wsrw_lite_just_activated', true ); |
| 45 |
} |
| 46 |
} |
| 47 |
add_action( 'activate_search-replace-wpcode/wsrw.php', 'wsrw_lite_just_activated' ); |
| 48 |
|
| 49 |
if ( ! function_exists( 'wsrw_lite_just_deactivated' ) ) { |
| 50 |
/** |
| 51 |
* Store temporarily that Lite plugin was deactivated. |
| 52 |
* Convert temporary "activated" value to a global variable, |
| 53 |
* so it is available through the request. Remove from the storage. |
| 54 |
*/ |
| 55 |
function wsrw_lite_just_deactivated() { |
| 56 |
|
| 57 |
global $wsrw_lite_just_activated, $wsrw_lite_just_deactivated; |
| 58 |
|
| 59 |
$wsrw_lite_just_activated = (bool) get_transient( 'wsrw_lite_just_activated' ); |
| 60 |
$wsrw_lite_just_deactivated = true; |
| 61 |
|
| 62 |
delete_transient( 'wsrw_lite_just_activated' ); |
| 63 |
} |
| 64 |
} |
| 65 |
add_action( 'deactivate_search-replace-wpcode/wsrw.php', 'wsrw_lite_just_deactivated' ); |
| 66 |
|
| 67 |
if ( ! function_exists( 'wsrw_deactivate' ) ) { |
| 68 |
/** |
| 69 |
* Deactivate Lite if Search & Replace Everything is already activated. |
| 70 |
*/ |
| 71 |
function wsrw_deactivate() { |
| 72 |
|
| 73 |
$plugin = 'search-replace-wpcode/wsrw.php'; |
| 74 |
|
| 75 |
deactivate_plugins( $plugin ); |
| 76 |
|
| 77 |
do_action( 'wsrw_plugin_deactivated', $plugin ); |
| 78 |
} |
| 79 |
} |
| 80 |
add_action( 'admin_init', 'wsrw_deactivate' ); |
| 81 |
|
| 82 |
if ( ! function_exists( 'wsrw_lite_notice' ) ) { |
| 83 |
/** |
| 84 |
* Display the notice after deactivation when Pro is still active |
| 85 |
* and user wanted to activate the Lite version of the plugin. |
| 86 |
*/ |
| 87 |
function wsrw_lite_notice() { |
| 88 |
|
| 89 |
global $wsrw_lite_just_activated, $wsrw_lite_just_deactivated; |
| 90 |
|
| 91 |
if ( |
| 92 |
empty( $wsrw_lite_just_activated ) || |
| 93 |
empty( $wsrw_lite_just_deactivated ) |
| 94 |
) { |
| 95 |
return; |
| 96 |
} |
| 97 |
|
| 98 |
// Currently tried to activate Lite with Pro still active, so display the message. |
| 99 |
printf( |
| 100 |
'<div class="notice notice-warning"> |
| 101 |
<p>%1$s</p> |
| 102 |
<p>%2$s</p> |
| 103 |
</div>', |
| 104 |
esc_html__( 'Heads up!', 'search-replace-wpcode' ), |
| 105 |
esc_html__( 'Your site already has Search & Replace Everything Pro activated. If you want to switch to Search & Replace Everything Lite, please first go to Plugins → Installed Plugins and deactivate Search & Replace Everything Pro. Then, you can activate Search And Replace Everything Lite.', 'search-replace-wpcode' ) |
| 106 |
); |
| 107 |
|
| 108 |
if ( isset( $_GET['activate'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 109 |
unset( $_GET['activate'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 110 |
} |
| 111 |
|
| 112 |
unset( $wsrw_lite_just_activated, $wsrw_lite_just_deactivated ); |
| 113 |
} |
| 114 |
} |
| 115 |
add_action( 'admin_notices', 'wsrw_lite_notice' ); |
| 116 |
|
| 117 |
// Do not process the plugin code further. |
| 118 |
return; |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Main plugin class. |
| 123 |
*/ |
| 124 |
class WSRW_Main { |
| 125 |
|
| 126 |
/** |
| 127 |
* Holds the instance of the plugin. |
| 128 |
* |
| 129 |
* @since 1.0.0 |
| 130 |
* |
| 131 |
* @var WSRW_Main The one true WSRW_Main |
| 132 |
*/ |
| 133 |
private static $instance; |
| 134 |
|
| 135 |
/** |
| 136 |
* Plugin version. |
| 137 |
* |
| 138 |
* @since 2.0.0 |
| 139 |
* |
| 140 |
* @var string |
| 141 |
*/ |
| 142 |
public $version = ''; |
| 143 |
|
| 144 |
/** |
| 145 |
* The admin page loader. |
| 146 |
* |
| 147 |
* @var WSRW_Admin_Page_Loader |
| 148 |
*/ |
| 149 |
public $admin_page_loader; |
| 150 |
|
| 151 |
/** |
| 152 |
* The admin notices instance. |
| 153 |
* |
| 154 |
* @var WSRW_Notice |
| 155 |
*/ |
| 156 |
public $notice; |
| 157 |
|
| 158 |
/** |
| 159 |
* The settings instance. |
| 160 |
* |
| 161 |
* @var WSRW_Settings |
| 162 |
*/ |
| 163 |
public $settings; |
| 164 |
|
| 165 |
/** |
| 166 |
* Main instance of WSRW_Main. |
| 167 |
* |
| 168 |
* @return WSRW_Main |
| 169 |
* @since 2.0.0 |
| 170 |
*/ |
| 171 |
public static function instance() { |
| 172 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WSRW_Main ) ) { |
| 173 |
self::$instance = new WSRW_Main(); |
| 174 |
} |
| 175 |
|
| 176 |
return self::$instance; |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Constructor. |
| 181 |
*/ |
| 182 |
private function __construct() { |
| 183 |
$this->setup_constants(); |
| 184 |
$this->includes(); |
| 185 |
add_action( 'plugins_loaded', array( $this, 'load_components' ) ); |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Set up global constants. |
| 190 |
* |
| 191 |
* @return void |
| 192 |
*/ |
| 193 |
private function setup_constants() { |
| 194 |
|
| 195 |
define( 'WSRW_FILE', __FILE__ ); |
| 196 |
|
| 197 |
$plugin_headers = get_file_data( WSRW_FILE, array( 'version' => 'Version' ) ); |
| 198 |
|
| 199 |
define( 'WSRW_VERSION', $plugin_headers['version'] ); |
| 200 |
define( 'WSRW_PLUGIN_BASENAME', plugin_basename( WSRW_FILE ) ); |
| 201 |
define( 'WSRW_PLUGIN_URL', plugin_dir_url( WSRW_FILE ) ); |
| 202 |
define( 'WSRW_PLUGIN_PATH', plugin_dir_path( WSRW_FILE ) ); |
| 203 |
|
| 204 |
$this->version = WSRW_VERSION; |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* Require the files needed for the plugin. |
| 209 |
* |
| 210 |
* @return void |
| 211 |
*/ |
| 212 |
private function includes() { |
| 213 |
if ( is_admin() || wp_doing_ajax() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { |
| 214 |
require_once WSRW_PLUGIN_PATH . 'includes/class-wsrw-settings.php'; |
| 215 |
require_once WSRW_PLUGIN_PATH . 'includes/helpers.php'; |
| 216 |
require_once WSRW_PLUGIN_PATH . 'includes/icons.php'; |
| 217 |
require_once WSRW_PLUGIN_PATH . 'includes/admin/class-wsrw-admin-page-loader.php'; |
| 218 |
require_once WSRW_PLUGIN_PATH . 'includes/admin/admin-scripts.php'; |
| 219 |
require_once WSRW_PLUGIN_PATH . 'includes/class-wsrw-search-replace.php'; |
| 220 |
require_once WSRW_PLUGIN_PATH . 'includes/class-wsrw-install.php'; |
| 221 |
require_once WSRW_PLUGIN_PATH . 'includes/admin/class-wsrw-notice.php'; |
| 222 |
require_once WSRW_PLUGIN_PATH . 'includes/admin/class-wsrw-review.php'; |
| 223 |
} |
| 224 |
|
| 225 |
require_once WSRW_PLUGIN_PATH . 'includes/class-wsrw-image-replace.php'; |
| 226 |
|
| 227 |
require_once WSRW_PLUGIN_PATH . 'includes/lite/loader.php'; |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Load components in the main plugin instance. |
| 232 |
* |
| 233 |
* @return void |
| 234 |
*/ |
| 235 |
public function load_components() { |
| 236 |
if ( is_admin() || wp_doing_ajax() || defined( 'DOING_CRON' ) && DOING_CRON ) { |
| 237 |
$this->settings = new WSRW_Settings(); |
| 238 |
$this->admin_page_loader = new WSRW_Admin_Page_Loader(); |
| 239 |
$this->notice = new WSRW_Notice(); |
| 240 |
|
| 241 |
new WSRW_Search_Replace(); |
| 242 |
} |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
require_once dirname( __FILE__ ) . '/includes/wsrw.php'; |
| 247 |
|
| 248 |
// Kick it off. |
| 249 |
wsrw_main(); |
| 250 |
|