_properties['format'] ) {
if ( empty( $_GET[ self::RECALC_ACTION ] ) ) { // phpcs:ignore -- nonce validation is not required here.
$nonce = wp_create_nonce( self::RECALC_ACTION );
$url = add_query_arg( [
self::RECALC_ACTION => 1,
'_wpnonce' => $nonce,
] );
$title .= 'Recalculate';
} else {
$title .= $this->get_remove_recalc_query_string_script();
}
}
return $title;
}
public function get_fields() {
return [
'usage' => '',
];
}
public function get_usage() {
/** @var Module $module */
$module = Module::instance();
if ( ! empty( $_GET[ self::RECALC_ACTION ] ) ) {
if ( empty( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], self::RECALC_ACTION ) ) {
wp_die( 'Invalid Nonce', 'Invalid Nonce', [
'back_link' => true,
] );
}
$module->recalc_usage();
}
$usage = '';
foreach ( $module->get_formatted_usage() as $doc_type => $data ) {
$usage .= '
' . $data['title'] . ' ( ' . $data['count'] . ' ) | ';
foreach ( $data['elements'] as $element => $count ) {
$usage .= $element . ': ' . $count . PHP_EOL;
}
$usage .= ' |
';
}
return [
'value' => $usage,
];
}
public function get_raw_usage() {
/** @var Module $module */
$module = Module::instance();
$usage = PHP_EOL;
foreach ( $module->get_formatted_usage( 'raw' ) as $doc_type => $data ) {
$usage .= "\t{$data['title']} : " . $data['count'] . PHP_EOL;
foreach ( $data['elements'] as $element => $count ) {
$usage .= "\t\t{$element} : {$count}" . PHP_EOL;
}
}
return [
'value' => $usage,
];
}
/**
* Removes the "elementor_usage_recalc" param from the query string to avoid recalc every refresh.
* When using a redirect header in place of this approach it throws an error because some components have already output some content.
*
* @return string
*/
private function get_remove_recalc_query_string_script() {
ob_start();
?>