PluginProbe
Search & Replace Everything by WPCode – Find and Replace Media, Text, Links, and More / 1.0.8
Search & Replace Everything by WPCode – Find and Replace Media, Text, Links, and More v1.0.8
trunk 1.0.0 1.0.1 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
search-replace-wpcode / wsrw.php

wsrw.php in Search & Replace Everything by WPCode – Find and Replace Media, Text, Links, and More 1.0.8, at wsrw.php

260 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.8
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 * The image replace instance.
167 *
168 * @var WSRW_Image_Replace
169 */
170 public $replace_images;
171
172 /**
173 * Main instance of WSRW_Main.
174 *
175 * @return WSRW_Main
176 * @since 2.0.0
177 */
178 public static function instance() {
179 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WSRW_Main ) ) {
180 self::$instance = new WSRW_Main();
181 }
182
183 return self::$instance;
184 }
185
186 /**
187 * Constructor.
188 */
189 private function __construct() {
190 $this->setup_constants();
191 $this->includes();
192 add_action( 'plugins_loaded', array( $this, 'load_components' ) );
193 }
194
195 /**
196 * Set up global constants.
197 *
198 * @return void
199 */
200 private function setup_constants() {
201
202 define( 'WSRW_FILE', __FILE__ );
203
204 $plugin_headers = get_file_data( WSRW_FILE, array( 'version' => 'Version' ) );
205
206 define( 'WSRW_VERSION', $plugin_headers['version'] );
207 define( 'WSRW_PLUGIN_BASENAME', plugin_basename( WSRW_FILE ) );
208 define( 'WSRW_PLUGIN_URL', plugin_dir_url( WSRW_FILE ) );
209 define( 'WSRW_PLUGIN_PATH', plugin_dir_path( WSRW_FILE ) );
210
211 $this->version = WSRW_VERSION;
212 }
213
214 /**
215 * Require the files needed for the plugin.
216 *
217 * @return void
218 */
219 private function includes() {
220 if ( is_admin() || wp_doing_ajax() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
221 require_once WSRW_PLUGIN_PATH . 'includes/class-wsrw-settings.php';
222 require_once WSRW_PLUGIN_PATH . 'includes/helpers.php';
223 require_once WSRW_PLUGIN_PATH . 'includes/icons.php';
224 require_once WSRW_PLUGIN_PATH . 'includes/admin/class-wsrw-admin-page-loader.php';
225 require_once WSRW_PLUGIN_PATH . 'includes/admin/admin-scripts.php';
226 require_once WSRW_PLUGIN_PATH . 'includes/class-wsrw-search-replace.php';
227 require_once WSRW_PLUGIN_PATH . 'includes/class-wsrw-install.php';
228 require_once WSRW_PLUGIN_PATH . 'includes/admin/class-wsrw-notice.php';
229 require_once WSRW_PLUGIN_PATH . 'includes/admin/class-wsrw-review.php';
230 }
231
232 require_once WSRW_PLUGIN_PATH . 'includes/class-wsrw-image-replace.php';
233
234 require_once WSRW_PLUGIN_PATH . 'includes/lite/loader.php';
235 }
236
237 /**
238 * Load components in the main plugin instance.
239 *
240 * @return void
241 */
242 public function load_components() {
243
244 $this->replace_images = new WSRW_Image_Replace();
245
246 if ( is_admin() || wp_doing_ajax() || defined( 'DOING_CRON' ) && DOING_CRON ) {
247 $this->settings = new WSRW_Settings();
248 $this->admin_page_loader = new WSRW_Admin_Page_Loader();
249 $this->notice = new WSRW_Notice();
250
251 new WSRW_Search_Replace();
252 }
253 }
254 }
255
256 require_once dirname( __FILE__ ) . '/includes/wsrw.php';
257
258 // Kick it off.
259 wsrw_main();
260