-
Notifications
You must be signed in to change notification settings - Fork 31
/
inpsyde-search-replace.php
executable file
·129 lines (101 loc) · 3.49 KB
/
inpsyde-search-replace.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: Search & Replace
* Plugin URI: https://wordpress.org/plugins/search-and-replace/
* Description: Search & Replace data in your whole WordPress setup, backup and import your database, change table prefix or migrate your domain to another domain.
* Author: WP MEDIA SAS
* Author URI: https://wp-media.me/
* Contributors: s-hinse, derpixler, ChriCo, Bueltge, inpsyde
* Version: 3.2.3
* Text Domain: search-and-replace
* Domain Path: /languages
* License: GPLv2+
* License URI: LICENSE
*/
use Inpsyde\SearchReplace\Database;
use Inpsyde\SearchReplace\Page;
defined( 'ABSPATH' ) || die( 'No direct access!' );
add_action( 'plugins_loaded', 'search_replace_load' );
register_activation_hook( __FILE__, 'search_replace_activate' );
/**
* Validate requirements on activation
*
* Runs on plugin activation.
* Check if php min 5.6.0 if not deactivate the plugin.
*
* @since 3.1.1
*
* @return void
*/
function search_replace_activate() {
$required_php_version = '5.6.0';
$correct_php_version = version_compare( PHP_VERSION, $required_php_version, '>=' );
search_replace_textdomain();
if ( ! $correct_php_version ) {
deactivate_plugins( basename( __FILE__ ) );
wp_die(
'<p>' .
sprintf(
// translators: %1$s will replace with the PHP version of the client.
esc_attr__(
'This plugin can not be activated because it requires at least PHP version %1$s. ',
'search-and-replace'
),
$required_php_version
)
. '</p> <a href="' . admin_url( 'plugins.php' ) . '">'
. esc_attr__( 'back', 'search-and-replace' ) . '</a>'
);
}
}
/**
* Load the plugin
*
* @since 3.1.1
*
* @return bool
*/
function search_replace_load() {
global $wpdb;
// all hooks are just available on backend.
if ( ! is_admin() ) {
return false;
}
define( 'SEARCH_REPLACE_BASEDIR', plugin_dir_url( __FILE__ ) );
search_replace_textdomain();
$user_cap = apply_filters( 'search_replace_access_capability', 'manage_options' );
$file = __DIR__ . '/vendor/autoload.php';
if ( ! current_user_can( $user_cap ) || ! file_exists( $file ) ) {
return false;
}
/** @noinspection PhpIncludeInspection */
include_once $file;
$max_execution = new Inpsyde\SearchReplace\Service\MaxExecutionTime();
$dbm = new Database\Manager( $wpdb );
$replace = new Database\Replace( $dbm, $max_execution );
$dbe = new Database\Exporter( $replace, $dbm, new \WP_Error() );
$dbi = new Database\Importer( $max_execution );
$downloader = new Inpsyde\SearchReplace\FileDownloader( $dbe, $max_execution );
add_action( 'init', [ $downloader, 'deliver_backup_file' ] );
$page_manager = new Page\Manager();
$page_manager->add_page( new Page\BackupDatabase( $dbe, $downloader ) );
$page_manager->add_page( new Page\SearchReplace( $dbm, $replace, $dbe, $downloader ) );
$page_manager->add_page( new Page\ReplaceDomain( $dbm, $dbe, $downloader ) );
$page_manager->add_page( new Page\SqlImport( $dbi ) );
$page_manager->add_page( new Page\Credits() );
add_action( 'admin_menu', [ $page_manager, 'register_pages' ] );
add_action( 'admin_head', [ $page_manager, 'remove_submenu_pages' ] );
add_action( 'admin_enqueue_scripts', [ $page_manager, 'register_css' ] );
add_action( 'admin_enqueue_scripts', [ $page_manager, 'register_js' ] );
return true;
}
/**
* Loading the plugin translations.
*/
function search_replace_textdomain() {
return load_plugin_textdomain(
'search-and-replace',
false,
plugin_basename( __DIR__ ) . '/languages/'
);
}