Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/elementor/modules/editor-app-bar/module.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + namespace Elementor\Modules\EditorAppBar;
3 +
4 + use Elementor\Core\Base\Module as BaseModule;
5 +
6 + if ( ! defined( 'ABSPATH' ) ) {
7 + exit; // Exit if accessed directly.
8 + }
9 +
10 + class Module extends BaseModule {
11 + const PACKAGES = [
12 + 'editor-app-bar',
13 + ];
14 +
15 + const STYLES = [
16 + 'editor-v2-app-bar-overrides',
17 + ];
18 +
19 + const POPUP_DISMISSED_OPTION = '_elementor_structure_popup_dismissed';
20 + const STRUCTURE_POPUP_TARGET_VERSION = '3.32.0';
21 +
22 + public function get_name() {
23 + return 'editor-app-bar';
24 + }
25 +
26 + public function __construct() {
27 + parent::__construct();
28 +
29 + add_filter( 'elementor/editor/v2/packages', fn( $packages ) => $this->add_packages( $packages ) );
30 + add_filter( 'elementor/editor/v2/styles', fn( $styles ) => $this->add_styles( $styles ) );
31 + add_filter( 'elementor/editor/templates', fn( $templates ) => $this->remove_templates( $templates ) );
32 +
33 + add_action( 'elementor/editor/v2/scripts/enqueue', fn() => $this->dequeue_scripts() );
34 + add_action( 'elementor/editor/v2/styles/enqueue', fn() => $this->dequeue_styles() );
35 +
36 + add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'maybe_enqueue_structure_popup' ] );
37 + add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
38 + }
39 +
40 + public function register_ajax_actions( $ajax ) {
41 + $ajax->register_ajax_action( 'structure_popup_dismiss', [ $this, 'ajax_dismiss_structure_popup' ] );
42 + }
43 +
44 + public function ajax_dismiss_structure_popup( $data ) {
45 + $user_id = get_current_user_id();
46 +
47 + if ( ! $user_id ) {
48 + throw new \Exception( 'User not authenticated' );
49 + }
50 +
51 + update_user_meta( $user_id, self::POPUP_DISMISSED_OPTION, true );
52 +
53 + return [
54 + 'success' => true,
55 + 'message' => 'Structure popup dismissed successfully',
56 + ];
57 + }
58 +
59 + public function maybe_enqueue_structure_popup(): void {
60 +
61 + if ( ! $this->should_show_structure_popup_for_current_user() ) {
62 + return;
63 + }
64 +
65 + wp_localize_script( 'elementor-editor', 'elementorShowInfotip', [ 'shouldShow' => '1' ] );
66 + }
67 +
68 + private function should_show_structure_popup_for_current_user(): bool {
69 + $user_id = get_current_user_id();
70 +
71 + if ( ! $user_id ) {
72 + return false;
73 + }
74 +
75 + if ( ! $this->is_existing_user_upgraded_to_target_version( self::STRUCTURE_POPUP_TARGET_VERSION ) ) {
76 + return false;
77 + }
78 +
79 + if ( get_user_meta( $user_id, self::POPUP_DISMISSED_OPTION, true ) ) {
80 + return false;
81 + }
82 +
83 + return true;
84 + }
85 +
86 + private function is_existing_user_upgraded_to_target_version( string $target_version ): bool {
87 +
88 + if ( version_compare( ELEMENTOR_VERSION, $target_version, '<' ) ) {
89 + return false;
90 + }
91 +
92 + $installs_history = \Elementor\Core\Upgrade\Manager::get_installs_history();
93 +
94 + return ! empty( $installs_history ) &&
95 + version_compare( array_key_first( $installs_history ), $target_version, '<' );
96 + }
97 +
98 + private function add_packages( $packages ) {
99 + return array_merge( $packages, self::PACKAGES );
100 + }
101 +
102 + private function add_styles( $styles ) {
103 + return array_merge( $styles, self::STYLES );
104 + }
105 +
106 + private function remove_templates( $templates ) {
107 + return array_diff( $templates, [ 'responsive-bar' ] );
108 + }
109 +
110 + private function dequeue_scripts() {
111 + wp_dequeue_script( 'elementor-responsive-bar' );
112 + }
113 +
114 + private function dequeue_styles() {
115 + wp_dequeue_style( 'elementor-responsive-bar' );
116 + }
117 + }
118 +