PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.1
Elementor Website Builder – more than just a page builder v3.34.1
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / settings / tools.php

tools.php in Elementor Website Builder – more than just a page builder 3.34.1, at includes/settings/tools.php

502 lines 16.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
5 use Elementor\Core\Admin\Menu\Main as MainMenu;
6 use Elementor\Core\Kits\Manager;
7 use Elementor\Includes\Settings\AdminMenuItems\Tools_Menu_Item;
8 use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
9 use Elementor\Includes\Settings\AdminMenuItems\Editor_One_Tools_Menu;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 /**
16 * Elementor "Tools" page in WordPress Dashboard.
17 *
18 * Elementor settings page handler class responsible for creating and displaying
19 * Elementor "Tools" page in WordPress dashboard.
20 *
21 * @since 1.0.0
22 */
23 class Tools extends Settings_Page {
24
25 const CAPABILITY = 'manage_options';
26
27 /**
28 * Settings page ID for Elementor tools.
29 */
30 const PAGE_ID = 'elementor-tools';
31
32 private function register_admin_menu( MainMenu $menu ) {
33 $menu->add_submenu( [
34 'page_title' => esc_html__( 'Tools', 'elementor' ),
35 'menu_title' => esc_html__( 'Tools', 'elementor' ),
36 'menu_slug' => self::PAGE_ID,
37 'function' => [ $this, 'display_settings_page' ],
38 'index' => 50,
39 ] );
40 }
41
42 /**
43 * Clear cache.
44 *
45 * Delete post meta containing the post CSS file data. And delete the actual
46 * CSS files from the upload directory.
47 *
48 * Fired by `wp_ajax_elementor_clear_cache` action.
49 *
50 * @since 1.0.0
51 * @access public
52 */
53 public function ajax_elementor_clear_cache() {
54 check_ajax_referer( 'elementor_clear_cache', '_nonce' );
55
56 if ( ! current_user_can( static::CAPABILITY ) ) {
57 wp_send_json_error( 'Permission denied' );
58 }
59
60 Plugin::$instance->files_manager->clear_cache();
61
62 wp_send_json_success();
63 }
64
65 public function admin_post_elementor_site_clear_cache() {
66 check_ajax_referer( 'elementor_site_clear_cache' );
67
68 if ( ! current_user_can( static::CAPABILITY ) ) {
69 wp_die( 'Permission denied' );
70 }
71
72 Plugin::$instance->files_manager->clear_cache();
73
74 $http_referer = wp_get_raw_referer();
75 if ( empty( $http_referer ) ) {
76 $http_referer = admin_url( 'admin.php?page=' . static::PAGE_ID );
77 }
78
79 wp_safe_redirect( $http_referer );
80 die;
81 }
82
83 /**
84 * Recreate kit.
85 *
86 * Recreate default kit (only when default kit does not exist).
87 *
88 * Fired by `wp_ajax_elementor_recreate_kit` action.
89 *
90 * @since 1.0.0
91 * @access public
92 */
93 public function ajax_elementor_recreate_kit() {
94 check_ajax_referer( 'elementor_recreate_kit', '_nonce' );
95
96 if ( ! current_user_can( static::CAPABILITY ) ) {
97 wp_send_json_error( 'Permission denied' );
98 }
99
100 $kit = Plugin::$instance->kits_manager->get_active_kit();
101
102 if ( $kit->get_id() ) {
103 wp_send_json_error( [ 'message' => esc_html__( 'There\'s already an active kit.', 'elementor' ) ], 400 );
104 }
105
106 $created_default_kit = Plugin::$instance->kits_manager->create_default();
107
108 if ( ! $created_default_kit ) {
109 wp_send_json_error( [ 'message' => esc_html__( 'An error occurred while trying to create a kit.', 'elementor' ) ], 500 );
110 }
111
112 update_option( Manager::OPTION_ACTIVE, $created_default_kit );
113
114 wp_send_json_success( esc_html__( 'New kit have been created successfully', 'elementor' ) );
115 }
116
117 /**
118 * Replace URLs.
119 *
120 * Sends an ajax request to replace old URLs to new URLs. This method also
121 * updates all the Elementor data.
122 *
123 * Fired by `wp_ajax_elementor_replace_url` action.
124 *
125 * @since 1.1.0
126 * @access public
127 */
128 public function ajax_elementor_replace_url() {
129 check_ajax_referer( 'elementor_replace_url', '_nonce' );
130
131 if ( ! current_user_can( static::CAPABILITY ) ) {
132 wp_send_json_error( 'Permission denied' );
133 }
134
135 $from = Utils::get_super_global_value( $_POST, 'from' ) ?? '';
136 $to = Utils::get_super_global_value( $_POST, 'to' ) ?? '';
137
138 try {
139 $results = Utils::replace_urls( $from, $to );
140 wp_send_json_success( $results );
141 } catch ( \Exception $e ) {
142 wp_send_json_error( $e->getMessage() );
143 }
144 }
145
146 /**
147 * Elementor version rollback.
148 *
149 * Rollback to previous Elementor version.
150 *
151 * Fired by `admin_post_elementor_rollback` action.
152 *
153 * @since 1.5.0
154 * @access public
155 */
156 public function post_elementor_rollback() {
157 check_admin_referer( 'elementor_rollback' );
158
159 if ( ! static::can_user_rollback_versions() ) {
160 wp_die( esc_html__( 'Not allowed to rollback versions', 'elementor' ) );
161 }
162
163 $rollback_versions = $this->get_rollback_versions();
164 $version = Utils::get_super_global_value( $_GET, 'version' );
165
166 if ( empty( $version ) || ! in_array( $version, $rollback_versions, true ) ) {
167 wp_die( esc_html__( 'An error occurred, the selected version is invalid. Try selecting different version.', 'elementor' ) );
168 }
169
170 /**
171 * Filter to allow override the rollback process.
172 * Should return an instance of `Rollback` class.
173 *
174 * @since 3.16.0
175 *
176 * @param Rollback|null $rollback The rollback instance.
177 * @param string $version The version to roll back to.
178 */
179 $rollback = apply_filters( 'elementor/settings/rollback', null, $version );
180
181 if ( ! ( $rollback instanceof Rollback ) ) {
182 $plugin_slug = basename( ELEMENTOR__FILE__, '.php' );
183
184 $rollback = new Rollback( [
185 'version' => $version,
186 'plugin_name' => ELEMENTOR_PLUGIN_BASE,
187 'plugin_slug' => $plugin_slug,
188 'package_url' => sprintf( 'https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, $version ),
189 ] );
190 }
191
192 $rollback->run();
193
194 wp_die(
195 '', esc_html__( 'Rollback to Previous Version', 'elementor' ), [
196 'response' => 200,
197 ]
198 );
199 }
200
201 /**
202 * Tools page constructor.
203 *
204 * Initializing Elementor "Tools" page.
205 *
206 * @since 1.0.0
207 * @access public
208 */
209 public function __construct() {
210 parent::__construct();
211
212 add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) {
213 if ( ! $this->is_editor_one_active() ) {
214 $admin_menu->register( static::PAGE_ID, new Tools_Menu_Item( $this ) );
215 }
216 }, Settings::ADMIN_MENU_PRIORITY + 20 );
217
218 add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
219 $this->register_editor_one_menu( $menu_data_provider );
220 } );
221
222 add_action( 'wp_ajax_elementor_clear_cache', [ $this, 'ajax_elementor_clear_cache' ] );
223 add_action( 'admin_post_elementor_site_clear_cache', [ $this, 'admin_post_elementor_site_clear_cache' ] );
224 add_action( 'wp_ajax_elementor_replace_url', [ $this, 'ajax_elementor_replace_url' ] );
225 add_action( 'wp_ajax_elementor_recreate_kit', [ $this, 'ajax_elementor_recreate_kit' ] );
226
227 add_action( 'admin_post_elementor_rollback', [ $this, 'post_elementor_rollback' ] );
228 }
229
230 private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ) {
231 $menu_data_provider->register_menu( new Editor_One_Tools_Menu() );
232 }
233
234 private function is_editor_one_active(): bool {
235 return (bool) Plugin::instance()->modules_manager->get_modules( 'editor-one' );
236 }
237
238 private function get_rollback_versions() {
239 $rollback_versions = get_transient( 'elementor_rollback_versions_' . ELEMENTOR_VERSION );
240
241 if ( false === $rollback_versions ) {
242 $max_versions = 30;
243
244 $versions = apply_filters( 'elementor/settings/rollback/versions', [] );
245
246 if ( empty( $versions ) ) {
247 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
248
249 $plugin_information = plugins_api(
250 'plugin_information', [
251 'slug' => 'elementor',
252 ]
253 );
254
255 if ( empty( $plugin_information->versions ) || ! is_array( $plugin_information->versions ) ) {
256 return [];
257 }
258
259 uksort( $plugin_information->versions, 'version_compare' );
260 $versions = array_keys( array_reverse( $plugin_information->versions ) );
261 }
262
263 $rollback_versions = [];
264
265 $current_index = 0;
266 foreach ( $versions as $version ) {
267 if ( $max_versions <= $current_index ) {
268 break;
269 }
270
271 $lowercase_version = strtolower( $version );
272 $is_valid_rollback_version = ! preg_match( '/(trunk|beta|rc|dev)/i', $lowercase_version );
273
274 /**
275 * Is rollback version is valid.
276 *
277 * Filters the check whether the rollback version is valid.
278 *
279 * @param bool $is_valid_rollback_version Whether the rollback version is valid.
280 */
281 $is_valid_rollback_version = apply_filters(
282 'elementor/settings/tools/rollback/is_valid_rollback_version',
283 $is_valid_rollback_version,
284 $lowercase_version
285 );
286
287 if ( ! $is_valid_rollback_version ) {
288 continue;
289 }
290
291 if ( version_compare( $version, ELEMENTOR_VERSION, '>=' ) ) {
292 continue;
293 }
294
295 ++$current_index;
296 $rollback_versions[] = $version;
297 }
298
299 set_transient( 'elementor_rollback_versions_' . ELEMENTOR_VERSION, $rollback_versions, WEEK_IN_SECONDS );
300 }
301
302 return $rollback_versions;
303 }
304
305 /**
306 * Create tabs.
307 *
308 * Return the tools page tabs, sections and fields.
309 *
310 * @since 1.5.0
311 * @access protected
312 *
313 * @return array An array with the page tabs, sections and fields.
314 */
315 protected function create_tabs() {
316 $rollback_html = '<select class="elementor-rollback-select">';
317
318 foreach ( $this->get_rollback_versions() as $version ) {
319 $rollback_html .= "<option value='{$version}'>$version</option>";
320 }
321 $rollback_html .= '</select>';
322
323 $tabs = [
324 'general' => [
325 'label' => esc_html__( 'General', 'elementor' ),
326 'sections' => [
327 'tools' => [
328 'fields' => [
329 'clear_cache' => [
330 'label' => esc_html__( 'Elementor Cache', 'elementor' ),
331 'field_args' => [
332 'type' => 'raw_html',
333 'html' => sprintf( '<button data-nonce="%s" data-id="elementor-tools-general-button-clear-files-data" class="button elementor-button-spinner" id="elementor-clear-cache-button">%s</button>', wp_create_nonce( 'elementor_clear_cache' ), esc_html__( 'Clear Files & Data', 'elementor' ) ),
334 'desc' => esc_html__( "Clear outdated CSS files and cached data in the database (rendered HTML, JS/CSS assets, etc.). We'll regenerate those files the next time someone visits any page on your website.", 'elementor' ),
335 ],
336 ],
337 'reset_api_data' => [
338 'label' => esc_html__( 'Sync Library', 'elementor' ),
339 'field_args' => [
340 'type' => 'raw_html',
341 'html' => sprintf( '<button data-nonce="%s" data-id="elementor-tools-general-button-sync-library" class="button elementor-button-spinner" id="elementor-library-sync-button">%s</button>', wp_create_nonce( 'elementor_reset_library' ), esc_html__( 'Sync Library', 'elementor' ) ),
342 'desc' => esc_html__( 'Elementor Library automatically updates on a daily basis. You can also manually update it by clicking on the sync button.', 'elementor' ),
343 ],
344 ],
345 ],
346 ],
347 ],
348 ],
349 'replace_url' => [
350 'label' => esc_html__( 'Replace URL', 'elementor' ),
351 'sections' => [
352 'replace_url' => [
353 'callback' => function() {
354 echo '<h2>' . esc_html__( 'Replace URL', 'elementor' ) . '</h2>';
355 printf(
356 '<p><strong>%1$s</strong> %2$s</p>',
357 esc_html__( 'Important:', 'elementor' ),
358 sprintf(
359 /* translators: 1: Link open tag, 2: Link close tag. */
360 esc_html__( 'It is strongly recommended to %1$sbackup the database%2$s before using replacing URLs.', 'elementor' ),
361 '<a href="https://go.elementor.com/wordpress-backups/" target="_blank">',
362 '</a>'
363 )
364 );
365 },
366 'fields' => [
367 'replace_url' => [
368 'label' => esc_html__( 'Update Site Address (URL)', 'elementor' ),
369 'field_args' => [
370 'type' => 'raw_html',
371 'html' => sprintf( '<input type="text" name="from" placeholder="https://old.example.com" class="large-text"><input type="text" name="to" placeholder="https://new.example.com" class="large-text"><button data-nonce="%s" data-id="elementor-tools-replace_url-button-replace-url" class="button elementor-button-spinner" id="elementor-replace-url-button">%s</button>', wp_create_nonce( 'elementor_replace_url' ), esc_html__( 'Replace URL', 'elementor' ) ),
372 'desc' => esc_html__( 'Enter your old and new URLs for your WordPress installation, to update all Elementor data (Relevant for domain transfers or move to \'HTTPS\').', 'elementor' ),
373 ],
374 ],
375 ],
376 ],
377 ],
378 ],
379 'versions' => [
380 'show_if' => static::can_user_rollback_versions(),
381 'label' => esc_html__( 'Version Control', 'elementor' ),
382 'sections' => [
383 'rollback' => [
384 'label' => esc_html__( 'Rollback to Previous Version', 'elementor' ),
385 'callback' => function() {
386 $intro_text = sprintf(
387 /* translators: %s: Elementor version. */
388 esc_html__( 'Experiencing an issue with Elementor version %s? Rollback to a previous version before the issue appeared.', 'elementor' ),
389 ELEMENTOR_VERSION
390 );
391 $intro_text = '<p>' . $intro_text . '</p>';
392
393 Utils::print_unescaped_internal_string( $intro_text );
394 },
395 'fields' => [
396 'rollback' => [
397 'label' => esc_html__( 'Rollback Version', 'elementor' ),
398 'field_args' => [
399 'type' => 'raw_html',
400 'html' => sprintf(
401 $rollback_html . '<a data-placeholder-text="%1$s v{VERSION}" href="#" data-placeholder-url="%2$s" class="button elementor-button-spinner elementor-rollback-button">%1$s</a>',
402 esc_html__( 'Reinstall', 'elementor' ),
403 wp_nonce_url( admin_url( 'admin-post.php?action=elementor_rollback&version=VERSION' ), 'elementor_rollback' )
404 ),
405 'desc' => '<span style="color: red;">' . esc_html__( 'Warning: Please backup your database before making the rollback.', 'elementor' ) . '</span>',
406 ],
407 ],
408 ],
409 ],
410 'beta' => [
411 'show_if' => $this->display_beta_tester(),
412 'label' => esc_html__( 'Become a Beta Tester', 'elementor' ),
413 'callback' => function() {
414 echo '<p>' .
415 esc_html__( 'Turn-on Beta Tester, to get notified when a new beta version of Elementor or Elementor Pro is available. The Beta version will not install automatically. You always have the option to ignore it.', 'elementor' ) .
416 '</p>';
417 echo '<p>' . sprintf(
418 /* translators: 1: Link open tag, 2: Link close tag. */
419 esc_html__( '%1$sClick here%2$s %3$sto join our first-to-know email updates.%4$s', 'elementor' ),
420 '<a id="beta-tester-first-to-know" class="elementor-become-a-beta-tester" href="#">',
421 '</a>',
422 '<span class="elementor-become-a-beta-tester">',
423 '</span>',
424 ) . '</p>';
425 },
426 'fields' => [
427 'beta' => [
428 'label' => esc_html__( 'Beta Tester', 'elementor' ),
429 'field_args' => [
430 'type' => 'select',
431 'std' => 'no',
432 'options' => [
433 'no' => esc_html__( 'Disable', 'elementor' ),
434 'yes' => esc_html__( 'Enable', 'elementor' ),
435 ],
436 'desc' => '<span style="color: red;">' . esc_html__( 'Please Note: We do not recommend updating to a beta version on production sites.', 'elementor' ) . '</span>',
437 ],
438 ],
439 ],
440 ],
441 ],
442 ],
443 ];
444
445 if ( ! Plugin::$instance->kits_manager->get_active_kit()->get_id() ) {
446 $tabs['general']['sections']['tools']['fields']['recreate_kit'] = [
447 'label' => esc_html__( 'Recreate Kit', 'elementor' ),
448 'field_args' => [
449 'type' => 'raw_html',
450 'html' => sprintf( '<button data-nonce="%s" class="button elementor-button-spinner" id="elementor-recreate-kit-button">%s</button>', wp_create_nonce( 'elementor_recreate_kit' ), esc_html__( 'Recreate Kit', 'elementor' ) ),
451 'desc' => esc_html__( 'It seems like your site doesn\'t have any active Kit. The active Kit includes all of your Site Settings. By recreating your Kit you will able to start edit your Site Settings again.', 'elementor' ),
452 ],
453 ];
454 }
455 return $tabs;
456 }
457
458 /**
459 * Get tools page title.
460 *
461 * Retrieve the title for the tools page.
462 *
463 * @since 1.5.0
464 * @access protected
465 *
466 * @return string Tools page title.
467 */
468 protected function get_page_title() {
469 return esc_html__( 'Tools', 'elementor' );
470 }
471
472 /**
473 * Check if the current user can access the version control tab and rollback versions.
474 *
475 * @return bool
476 */
477 public static function can_user_rollback_versions() {
478 return current_user_can( 'activate_plugins' ) && current_user_can( 'update_plugins' );
479 }
480
481 /**
482 * Check if the beta tester should be displayed.
483 *
484 * @since 3.19.0
485 *
486 * @return bool
487 */
488 public function display_beta_tester(): bool {
489 $display_beta_tester = true;
490 /**
491 * Filter to allow override the display of the beta tester.
492 *
493 * @param bool $display_beta_tester Whether to display the beta tester.
494 *
495 * @since 3.19.0
496 *
497 * return bool
498 */
499 return apply_filters( 'elementor/admin/show_beta_tester', $display_beta_tester );
500 }
501 }
502