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

103 lines 2.6 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 * Conditionally disable Content Control for Elementor builder.
30 *
31 * @param boolean $is_disabled Whether protection is disabled.
32 * @return boolean
33 */
34 public function protection_is_disabled( $is_disabled ) {
35 // If already disabled, no reason to continue.
36 if ( $is_disabled || ! did_action( 'elementor/loaded' ) ) {
37 return $is_disabled;
38 }
39
40 return $this->elementor_builder_is_active();
41 }
42
43 /**
44 * Add Elementor font post type to ignored post types.
45 *
46 * @param string[] $post_types Post types to ignore.
47 * @return string[]
48 */
49 public function post_types_to_ignore( $post_types ) {
50 $post_types[] = 'elementor_font';
51 $post_types[] = 'elementor_icons';
52 $post_types[] = 'elementor_library';
53 $post_types[] = 'elementor_snippet';
54
55 return $post_types;
56 }
57
58 /**
59 * Check if Elementor builder is active.
60 *
61 * @return boolean
62 */
63 public function elementor_builder_is_active() {
64 // Check if this is the admin theme builder app.
65 // phpcs:ignore WordPress.Security.NonceVerification.Recommended Simple & direct string comparison.
66 if (
67 is_admin() &&
68 // Disable notices as this is a generic string comparison to prevent doing a lot of work.
69 // phpcs:disable WordPress.Security.NonceVerification.Recommended
70 ! empty( $_GET['page'] ) &&
71 'elementor-app' === $_GET['page']
72 // phpcs:enable WordPress.Security.NonceVerification.Recommended
73 ) {
74 return true;
75 }
76
77 if ( ! class_exists( '\Elementor\Plugin' ) || ! isset( \Elementor\Plugin::$instance ) ) {
78 return false;
79 }
80
81 /**
82 * Elementor instance.
83 *
84 * @var \Elementor\Plugin $elementor
85 */
86 $elementor = \Elementor\Plugin::$instance;
87
88 /**
89 * Elementor preview instance.
90 *
91 * @var \Elementor\Preview|(object{is_preview_mod:\Closure}&\stdClass)|false $preview
92 */
93 $preview = isset( $elementor->preview ) ? $elementor->preview : false;
94
95 if ( false === $preview || ! method_exists( $preview, 'is_preview_mode' ) ) {
96 return false;
97 }
98
99 // Check if the page builder is active.
100 return $preview->is_preview_mode();
101 }
102 }
103