PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.13
Elementor Website Builder – more than just a page builder v3.0.13
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
← All changes | modules/usage/usage-reporter.php +15 -47 4.2.33.0.13 View file →
@@ -1,9 +1,8 @@
1 1 <?php
2 2 namespace Elementor\Modules\Usage;
3 3
4 4 use Elementor\Modules\System_Info\Reporters\Base;
5 -use Elementor\Utils;
6 5
7 6 if ( ! defined( 'ABSPATH' ) ) {
8 7 exit; // Exit if accessed directly.
9 8 }
@@ -18,21 +17,11 @@
18 17
19 18 const RECALC_ACTION = 'elementor_usage_recalc';
20 19
21 20 public function get_title() {
22 - return esc_html__( 'Elements Usage', 'elementor' );
23 - }
21 + $title = 'Elements Usage';
24 22
25 - public function get_fields() {
26 - return [
27 - 'usage' => '',
28 - ];
29 - }
30 -
31 - public function print_html_label( $label ) {
32 - $title = $this->get_title();
33 -
34 - if ( empty( $_GET[ self::RECALC_ACTION ] ) ) { // phpcs:ignore -- nonce validation is not required here.
23 + if ( 'html' === $this->_properties['format'] && empty( $_GET[ self::RECALC_ACTION ] ) ) { // phpcs:ignore -- nonce validation is not require here.
35 24 $nonce = wp_create_nonce( self::RECALC_ACTION );
36 25 $url = add_query_arg( [
37 26 self::RECALC_ACTION => 1,
38 27 '_wpnonce' => $nonce,
@@ -37,25 +26,26 @@
37 26 self::RECALC_ACTION => 1,
38 27 '_wpnonce' => $nonce,
39 28 ] );
40 29
41 - $title .= '<a id="elementor-usage-recalc" href="' . esc_url( $url ) . '#elementor-usage-recalc" class="box-title-tool">' . esc_html__( 'Recalculate', 'elementor' ) . '</a>';
42 - } else {
43 - $title .= $this->get_remove_recalc_query_string_script();
30 + $title .= '<a id="elementor-usage-recalc" href="' . esc_url( $url ) . '#elementor-usage-recalc" class="box-title-tool">Recalculate</a>';
44 31 }
45 32
46 - parent::print_html_label( $title );
33 + return $title;
47 34 }
48 35
36 + public function get_fields() {
37 + return [
38 + 'usage' => '',
39 + ];
40 + }
41 +
49 42 public function get_usage() {
50 43 /** @var Module $module */
51 44 $module = Module::instance();
52 45
53 46 if ( ! empty( $_GET[ self::RECALC_ACTION ] ) ) {
54 - // phpcs:ignore
55 - $nonce = Utils::get_super_global_value( $_GET, '_wpnonce' );
56 -
57 - if ( ! wp_verify_nonce( $nonce, self::RECALC_ACTION ) ) {
47 + if ( empty( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], self::RECALC_ACTION ) ) {
58 48 wp_die( 'Invalid Nonce', 'Invalid Nonce', [
59 49 'back_link' => true,
60 50 ] );
61 51 }
@@ -60,8 +50,12 @@
60 50 ] );
61 51 }
62 52
63 53 $module->recalc_usage();
54 +
55 + wp_safe_redirect( remove_query_arg( self::RECALC_ACTION ) );
56 +
57 + die;
64 58 }
65 59
66 60 $usage = '';
67 61
@@ -95,32 +89,6 @@
95 89
96 90 return [
97 91 'value' => $usage,
98 92 ];
99 - }
100 -
101 - /**
102 - * Removes the "elementor_usage_recalc" param from the query string to avoid recalc every refresh.
103 - * When using a redirect header in place of this approach it throws an error because some components have already output some content.
104 - *
105 - * @return string
106 - */
107 - private function get_remove_recalc_query_string_script() {
108 - ob_start();
109 - ?>
110 - <script>
111 - // Origin file: modules/usage/usage-reporter.php - get_remove_recalc_query_string_script()
112 - {
113 - const url = new URL( window.location );
114 -
115 - url.hash = '';
116 - url.searchParams.delete( 'elementor_usage_recalc' );
117 - url.searchParams.delete( '_wpnonce' );
118 -
119 - history.replaceState( '', window.title, url.toString() );
120 - }
121 - </script>
122 - <?php
123 -
124 - return ob_get_clean();
125 93 }
126 94 }