PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / 2.6.4
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More v2.6.4
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 2.6.4, at classes/Controllers/Compatibility/Elementor.php

112 lines 2.8 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:ignore WordPress.Security.NonceVerification.Recommended Simple & direct string comparison.
75 if (
76 is_admin() &&
77 // Disable notices as this is a generic string comparison to prevent doing a lot of work.
78 // phpcs:disable WordPress.Security.NonceVerification.Recommended
79 ! empty( $_GET['page'] ) &&
80 'elementor-app' === $_GET['page']
81 // phpcs:enable WordPress.Security.NonceVerification.Recommended
82 ) {
83 return true;
84 }
85
86 if ( ! class_exists( '\Elementor\Plugin' ) || ! isset( \Elementor\Plugin::$instance ) ) {
87 return false;
88 }
89
90 /**
91 * Elementor instance.
92 *
93 * @var \Elementor\Plugin $elementor
94 */
95 $elementor = \Elementor\Plugin::$instance;
96
97 /**
98 * Elementor preview instance.
99 *
100 * @var \Elementor\Preview|(object{is_preview_mod:\Closure}&\stdClass)|false $preview
101 */
102 $preview = isset( $elementor->preview ) ? $elementor->preview : false;
103
104 if ( false === $preview || ! method_exists( $preview, 'is_preview_mode' ) ) {
105 return false;
106 }
107
108 // Check if the page builder is active.
109 return $preview->is_preview_mode();
110 }
111 }
112