PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / trunk
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 47 releases
content-control / classes / Controllers / Compatibility / Elementor.php

Elementor.php in Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More trunk, at classes/Controllers/Compatibility/Elementor.php

111 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor compatibility controller.
4 *
5 * @package ContentControl\Admin
6 * @copyright (c) 2023 Code Atlantic LLC
7 */
8
9 namespace ContentControl\Controllers\Compatibility;
10
11 use ContentControl\Base\Controller;
12
13 /**
14 * Elementor controller class.
15 */
16 class Elementor extends Controller {
17
18 /**
19 * Initialize widget editor UX.
20 *
21 * @return void
22 */
23 public function init() {
24 add_filter( 'content_control/post_types_to_ignore', [ $this, 'post_types_to_ignore' ] );
25 add_filter( 'content_control/protection_is_disabled', [ $this, 'protection_is_disabled' ] );
26 }
27
28 /**
29 * Check if controller is enabled.
30 *
31 * @return bool
32 */
33 public function controller_enabled() {
34 return class_exists( '\Elementor\Plugin' ) || did_action( 'elementor/loaded' );
35 }
36
37 /**
38 * Conditionally disable Content Control for Elementor builder.
39 *
40 * @param boolean $is_disabled Whether protection is disabled.
41 * @return boolean
42 */
43 public function protection_is_disabled( $is_disabled ) {
44 // If already disabled, no reason to continue.
45 if ( $is_disabled || ! did_action( 'elementor/loaded' ) ) {
46 return $is_disabled;
47 }
48
49 return $this->elementor_builder_is_active();
50 }
51
52 /**
53 * Add Elementor font post type to ignored post types.
54 *
55 * @param string[] $post_types Post types to ignore.
56 * @return string[]
57 */
58 public function post_types_to_ignore( $post_types ) {
59 $post_types[] = 'elementor_font';
60 $post_types[] = 'elementor_icons';
61 $post_types[] = 'elementor_library';
62 $post_types[] = 'elementor_snippet';
63
64 return $post_types;
65 }
66
67 /**
68 * Check if Elementor builder is active.
69 *
70 * @return boolean
71 */
72 public function elementor_builder_is_active() {
73 // Check if this is the admin theme builder app.
74 // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only routing check.
75 if (
76 is_admin() &&
77 ! empty( $_GET['page'] ) &&
78 is_string( $_GET['page'] ) &&
79 'elementor-app' === sanitize_key( wp_unslash( $_GET['page'] ) )
80 ) {
81 return true;
82 }
83 // phpcs:enable WordPress.Security.NonceVerification.Recommended
84
85 if ( ! class_exists( '\Elementor\Plugin' ) || ! isset( \Elementor\Plugin::$instance ) ) {
86 return false;
87 }
88
89 /**
90 * Elementor instance.
91 *
92 * @var \Elementor\Plugin $elementor
93 */
94 $elementor = \Elementor\Plugin::$instance;
95
96 /**
97 * Elementor preview instance.
98 *
99 * @var \Elementor\Preview|(object{is_preview_mod:\Closure}&\stdClass)|false $preview
100 */
101 $preview = isset( $elementor->preview ) ? $elementor->preview : false;
102
103 if ( false === $preview || ! method_exists( $preview, 'is_preview_mode' ) ) {
104 return false;
105 }
106
107 // Check if the page builder is active.
108 return $preview->is_preview_mode();
109 }
110 }
111