| @@ -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,9 +17,25 @@ | ||
| 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' ); | |
| 21 | + $title = 'Elements Usage'; | |
| 22 | + | |
| 23 | + if ( 'html' === $this->_properties['format'] ) { | |
| 24 | + if ( empty( $_GET[ self::RECALC_ACTION ] ) ) { // phpcs:ignore -- nonce validation is not required here. | |
| 25 | + $nonce = wp_create_nonce( self::RECALC_ACTION ); | |
| 26 | + $url = add_query_arg( [ | |
| 27 | + self::RECALC_ACTION => 1, | |
| 28 | + '_wpnonce' => $nonce, | |
| 29 | + ] ); | |
| 30 | + | |
| 31 | + $title .= '<a id="elementor-usage-recalc" href="' . esc_url( $url ) . '#elementor-usage-recalc" class="box-title-tool">Recalculate</a>'; | |
| 32 | + } else { | |
| 33 | + $title .= $this->get_remove_recalc_query_string_script(); | |
| 34 | + } | |
| 35 | + } | |
| 36 | + | |
| 37 | + return $title; | |
| 23 | 38 | } |
| 24 | 39 | |
| 25 | 40 | public function get_fields() { |
| 26 | 41 | return [ |
| @@ -27,35 +42,14 @@ | ||
| 27 | 42 | 'usage' => '', |
| 28 | 43 | ]; |
| 29 | 44 | } |
| 30 | 45 | |
| 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. | |
| 35 | - $nonce = wp_create_nonce( self::RECALC_ACTION ); | |
| 36 | - $url = add_query_arg( [ | |
| 37 | - self::RECALC_ACTION => 1, | |
| 38 | - '_wpnonce' => $nonce, | |
| 39 | - ] ); | |
| 40 | - | |
| 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(); | |
| 44 | - } | |
| 45 | - | |
| 46 | - parent::print_html_label( $title ); | |
| 47 | - } | |
| 48 | - | |
| 49 | 46 | public function get_usage() { |
| 50 | 47 | /** @var Module $module */ |
| 51 | 48 | $module = Module::instance(); |
| 52 | 49 | |
| 53 | 50 | 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 ) ) { | |
| 51 | + if ( empty( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], self::RECALC_ACTION ) ) { | |
| 58 | 52 | wp_die( 'Invalid Nonce', 'Invalid Nonce', [ |
| 59 | 53 | 'back_link' => true, |
| 60 | 54 | ] ); |
| 61 | 55 | } |