| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Audits; |
| 4 |
|
| 5 |
use Elementor\Core\Base\Module as BaseModule; |
| 6 |
use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 7 |
use Elementor\Modules\Audits\Data\Controller; |
| 8 |
use Elementor\Plugin; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
class Module extends BaseModule { |
| 15 |
|
| 16 |
const EXPERIMENT_NAME = 'e_page_audit'; |
| 17 |
|
| 18 |
const REST_NAMESPACE = 'elementor/v1'; |
| 19 |
|
| 20 |
const PACKAGES = [ |
| 21 |
'editor-props', |
| 22 |
'editor-styles', |
| 23 |
'editor-elements', |
| 24 |
'editor-floating-panels', |
| 25 |
'editor-audits', |
| 26 |
]; |
| 27 |
|
| 28 |
public function __construct() { |
| 29 |
parent::__construct(); |
| 30 |
|
| 31 |
if ( ! self::is_active() ) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
$this->register_data_controller(); |
| 36 |
|
| 37 |
add_filter( 'elementor/editor/v2/packages', fn( $packages ) => $this->add_packages( $packages ) ); |
| 38 |
add_action( 'elementor/editor/v2/scripts/enqueue', fn() => $this->print_inline_config() ); |
| 39 |
} |
| 40 |
|
| 41 |
public function get_name(): string { |
| 42 |
return 'audits'; |
| 43 |
} |
| 44 |
|
| 45 |
public static function get_experimental_data() { |
| 46 |
return [ |
| 47 |
'name' => self::EXPERIMENT_NAME, |
| 48 |
'title' => esc_html__( 'Page Audit', 'elementor' ), |
| 49 |
'description' => esc_html__( 'Scan the current page for SEO, accessibility, performance, and best-practice issues directly from the editor.', 'elementor' ), |
| 50 |
'release_status' => Experiments_Manager::RELEASE_STATUS_BETA, |
| 51 |
'default' => Experiments_Manager::STATE_INACTIVE, |
| 52 |
'hidden' => true, |
| 53 |
]; |
| 54 |
} |
| 55 |
|
| 56 |
public static function is_active(): bool { |
| 57 |
return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME ); |
| 58 |
} |
| 59 |
|
| 60 |
public function register_data_controller(): void { |
| 61 |
Plugin::$instance->data_manager_v2->register_controller( new Controller() ); |
| 62 |
} |
| 63 |
|
| 64 |
private function add_packages( array $packages ): array { |
| 65 |
return array_merge( $packages, self::PACKAGES ); |
| 66 |
} |
| 67 |
|
| 68 |
private function print_inline_config(): void { |
| 69 |
wp_add_inline_script( |
| 70 |
'elementor-v2-editor-audits', |
| 71 |
'window.elementorAudits = ' . wp_json_encode( [ |
| 72 |
'restNamespace' => self::REST_NAMESPACE, |
| 73 |
'nonce' => wp_create_nonce( 'wp_rest' ), |
| 74 |
] ) . ';', |
| 75 |
'before' |
| 76 |
); |
| 77 |
} |
| 78 |
} |
| 79 |
|