| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Easy Search Replace |
| 4 |
* Description: Find & replace text, HTML, or URLs across your WordPress site in real time — no database changes. |
| 5 |
* Version: 1.2.1 |
| 6 |
* Author: FluxPress |
| 7 |
* Author URI: https://fluxpress.io |
| 8 |
* Text Domain: easy-search-replace |
| 9 |
* Domain Path: /languages |
| 10 |
* License: GNU General Public License v2 or later |
| 11 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 12 |
* Requires at least: 5.0 |
| 13 |
* Requires PHP: 7.2 |
| 14 |
* |
| 15 |
* @package EasySearchReplace |
| 16 |
*/ |
| 17 |
|
| 18 |
// Exit if accessed directly. |
| 19 |
if ( ! defined( 'ABSPATH' ) ) { |
| 20 |
exit; |
| 21 |
} |
| 22 |
|
| 23 |
/* --------------------------------------------------------------------------- |
| 24 |
* Plugin constants |
| 25 |
* ------------------------------------------------------------------------- */ |
| 26 |
|
| 27 |
if ( ! defined( 'ESRN_VERSION' ) ) { |
| 28 |
define( 'ESRN_VERSION', '1.2.1' ); |
| 29 |
} |
| 30 |
if ( ! defined( 'ESRN_PLUGIN_FILE' ) ) { |
| 31 |
define( 'ESRN_PLUGIN_FILE', __FILE__ ); |
| 32 |
} |
| 33 |
if ( ! defined( 'ESRN_PLUGIN_DIR' ) ) { |
| 34 |
define( 'ESRN_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 35 |
} |
| 36 |
if ( ! defined( 'ESRN_PLUGIN_URL' ) ) { |
| 37 |
define( 'ESRN_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 38 |
} |
| 39 |
if ( ! defined( 'ESRN_PLUGIN_BASENAME' ) ) { |
| 40 |
define( 'ESRN_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 41 |
} |
| 42 |
if ( ! defined( 'ESRN_OPTION_KEY' ) ) { |
| 43 |
define( 'ESRN_OPTION_KEY', 'esrn_search_replace_options' ); |
| 44 |
} |
| 45 |
|
| 46 |
/* --------------------------------------------------------------------------- |
| 47 |
* Composer autoload |
| 48 |
* ------------------------------------------------------------------------- */ |
| 49 |
|
| 50 |
require_once __DIR__ . '/vendor/autoload.php'; |
| 51 |
|
| 52 |
/* --------------------------------------------------------------------------- |
| 53 |
* Load plugin classes and modules |
| 54 |
* ------------------------------------------------------------------------- */ |
| 55 |
|
| 56 |
require_once ESRN_PLUGIN_DIR . 'inc/class-rule-schema.php'; |
| 57 |
require_once ESRN_PLUGIN_DIR . 'inc/class-freemius-gate.php'; |
| 58 |
require_once ESRN_PLUGIN_DIR . 'inc/class-tracker.php'; |
| 59 |
require_once ESRN_PLUGIN_DIR . 'inc/class-rule-engine.php'; |
| 60 |
|
| 61 |
require_once ESRN_PLUGIN_DIR . 'inc/options.php'; |
| 62 |
require_once ESRN_PLUGIN_DIR . 'lib/dom.php'; |
| 63 |
|
| 64 |
/* --------------------------------------------------------------------------- |
| 65 |
* Lightweight install tracking |
| 66 |
* ------------------------------------------------------------------------- */ |
| 67 |
|
| 68 |
ESRN_Tracker::register(); |
| 69 |
|
| 70 |
function esrn_add_weekly_cron_schedule( $schedules ) { |
| 71 |
if ( ! isset( $schedules['weekly'] ) ) { |
| 72 |
$schedules['weekly'] = array( 'interval' => WEEK_IN_SECONDS, 'display' => __( 'Once Weekly', 'easy-search-replace' ) ); |
| 73 |
} |
| 74 |
return $schedules; |
| 75 |
} |
| 76 |
add_filter( 'cron_schedules', 'esrn_add_weekly_cron_schedule' ); |
| 77 |
|
| 78 |
/* --------------------------------------------------------------------------- |
| 79 |
* Bootstrap |
| 80 |
* ------------------------------------------------------------------------- */ |
| 81 |
|
| 82 |
/** |
| 83 |
* Run one-time data migration on load. Cheap - no-op after first successful run. |
| 84 |
*/ |
| 85 |
add_action( 'plugins_loaded', array( 'ESRN_Rule_Schema', 'maybe_migrate' ), 5 ); |
| 86 |
|
| 87 |
/** |
| 88 |
* Boot the rule engine. |
| 89 |
*/ |
| 90 |
function esrn_boot_engine() { |
| 91 |
static $engine = null; |
| 92 |
if ( null === $engine ) { |
| 93 |
$engine = new ESRN_Rule_Engine(); |
| 94 |
$engine->register(); |
| 95 |
} |
| 96 |
return $engine; |
| 97 |
} |
| 98 |
add_action( 'plugins_loaded', 'esrn_boot_engine', 10 ); |
| 99 |
|
| 100 |
/* --------------------------------------------------------------------------- |
| 101 |
* Internationalization |
| 102 |
* ------------------------------------------------------------------------- */ |
| 103 |
|
| 104 |
/** |
| 105 |
* Load the plugin translation files. |
| 106 |
*/ |
| 107 |
function esrn_load_textdomain() { |
| 108 |
load_plugin_textdomain( |
| 109 |
'easy-search-replace', |
| 110 |
false, |
| 111 |
dirname( ESRN_PLUGIN_BASENAME ) . '/languages' |
| 112 |
); |
| 113 |
} |
| 114 |
add_action( 'plugins_loaded', 'esrn_load_textdomain' ); |
| 115 |
|
| 116 |
/* --------------------------------------------------------------------------- |
| 117 |
* Admin assets & settings link |
| 118 |
* ------------------------------------------------------------------------- */ |
| 119 |
|
| 120 |
/** |
| 121 |
* Enqueue admin assets only on the plugin's settings screen. |
| 122 |
* |
| 123 |
* @param string $hook_suffix Current admin page hook suffix. |
| 124 |
*/ |
| 125 |
function esrn_enqueue_admin_scripts( $hook_suffix ) { |
| 126 |
// get_current_screen() is the safest way to identify our settings page. |
| 127 |
if ( 'settings_page_easy_search_replace' !== $hook_suffix ) { |
| 128 |
return; |
| 129 |
} |
| 130 |
|
| 131 |
wp_enqueue_script( |
| 132 |
'esrn-search-replace', |
| 133 |
ESRN_PLUGIN_URL . 'assets/admin.js', |
| 134 |
array( 'jquery' ), |
| 135 |
ESRN_VERSION, |
| 136 |
true |
| 137 |
); |
| 138 |
wp_localize_script( |
| 139 |
'esrn-search-replace', |
| 140 |
'esrnAdminL10n', |
| 141 |
array( |
| 142 |
/* translators: %d: rule number starting from 1 */ |
| 143 |
'ruleLabel' => __( 'Rule %d', 'easy-search-replace' ), |
| 144 |
'select2Placeholder' => __( 'Select post types', 'easy-search-replace' ), |
| 145 |
) |
| 146 |
); |
| 147 |
wp_enqueue_style( |
| 148 |
'esrn-search-replace', |
| 149 |
ESRN_PLUGIN_URL . 'assets/admin.css', |
| 150 |
array(), |
| 151 |
ESRN_VERSION |
| 152 |
); |
| 153 |
|
| 154 |
// Prefer core's registered Select2 if available; otherwise fall back to bundled copy. |
| 155 |
if ( wp_script_is( 'select2', 'registered' ) ) { |
| 156 |
wp_enqueue_style( 'select2' ); |
| 157 |
wp_enqueue_script( 'select2' ); |
| 158 |
} else { |
| 159 |
wp_enqueue_style( |
| 160 |
'esrn-select2', |
| 161 |
ESRN_PLUGIN_URL . 'assets/select2.css', |
| 162 |
array(), |
| 163 |
'4.0.13' |
| 164 |
); |
| 165 |
wp_enqueue_script( |
| 166 |
'esrn-select2', |
| 167 |
ESRN_PLUGIN_URL . 'assets/select2.js', |
| 168 |
array( 'jquery' ), |
| 169 |
'4.0.13', |
| 170 |
true |
| 171 |
); |
| 172 |
} |
| 173 |
} |
| 174 |
add_action( 'admin_enqueue_scripts', 'esrn_enqueue_admin_scripts' ); |
| 175 |
|
| 176 |
/** |
| 177 |
* Suppress third-party admin notices on our settings page. |
| 178 |
*/ |
| 179 |
function esrn_suppress_admin_notices() { |
| 180 |
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; |
| 181 |
if ( ! $screen || 'settings_page_easy_search_replace' !== $screen->id ) { |
| 182 |
return; |
| 183 |
} |
| 184 |
|
| 185 |
remove_all_actions( 'admin_notices' ); |
| 186 |
remove_all_actions( 'all_admin_notices' ); |
| 187 |
remove_all_actions( 'user_admin_notices' ); |
| 188 |
remove_all_actions( 'network_admin_notices' ); |
| 189 |
} |
| 190 |
add_action( 'in_admin_header', 'esrn_suppress_admin_notices', 1000 ); |
| 191 |
|
| 192 |
/** |
| 193 |
* Add a "Settings" link to the plugins list row. |
| 194 |
* |
| 195 |
* @param array $links Existing action links. |
| 196 |
* @return array |
| 197 |
*/ |
| 198 |
function esrn_add_settings_link( $links ) { |
| 199 |
$settings_link = sprintf( '<a href="%s">%s</a>', |
| 200 |
esc_url( admin_url( 'options-general.php?page=easy_search_replace' ) ), |
| 201 |
esc_html__( 'Settings', 'easy-search-replace' ) ); |
| 202 |
$upgrade_link = sprintf( '<a href="%s" target="_blank" rel="noopener" style="color:#4f46e5;font-weight:600;">%s</a>', |
| 203 |
esc_url( 'https://fluxpress.io/plugins/easy-search-replace/#pricing' ), |
| 204 |
esc_html__( 'Upgrade to Pro', 'easy-search-replace' ) ); |
| 205 |
array_unshift( $links, $upgrade_link ); |
| 206 |
array_unshift( $links, $settings_link ); |
| 207 |
return $links; |
| 208 |
} |
| 209 |
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'esrn_add_settings_link' ); |
| 210 |
|