PluginProbe
Elementor Website Builder – more than just a page builder / 3.31.2
Elementor Website Builder – more than just a page builder v3.31.2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / floating-buttons / documents / floating-buttons.php

floating-buttons.php in Elementor Website Builder – more than just a page builder 3.31.2, at modules/floating-buttons/documents/floating-buttons.php

255 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\FloatingButtons\Documents;
4
5 use Elementor\Core\Base\Document;
6 use Elementor\Core\DocumentTypes\PageBase;
7 use Elementor\Modules\FloatingButtons\Module;
8 use Elementor\Modules\Library\Traits\Library as Library_Trait;
9 use Elementor\Modules\FloatingButtons\Module as Floating_Buttons_Module;
10 use Elementor\Modules\PageTemplates\Module as Page_Templates_Module;
11 use Elementor\Plugin;
12 use Elementor\TemplateLibrary\Source_Local;
13 use Elementor\Utils as ElementorUtils;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 class Floating_Buttons extends PageBase {
20 use Library_Trait;
21
22 public static function get_properties() {
23 $properties = parent::get_properties();
24
25 $properties['support_kit'] = true;
26 $properties['support_site_editor'] = false;
27 $properties['cpt'] = [ Floating_Buttons_Module::CPT_FLOATING_BUTTONS ];
28 $properties['show_navigator'] = false;
29 $properties['allow_adding_widgets'] = false;
30 $properties['support_page_layout'] = false;
31 $properties['library_close_title'] = esc_html__( 'Go To Dashboard', 'elementor' );
32 $properties['publish_button_title'] = esc_html__( 'After publishing this widget, you will be able to set it as visible on the entire site in the Admin Table.', 'elementor' );
33 $properties['allow_closing_remote_library'] = false;
34
35 return $properties;
36 }
37
38 public static function get_floating_element_type( $post_id ) {
39 $meta = get_post_meta( $post_id, Floating_Buttons_Module::FLOATING_ELEMENTS_TYPE_META_KEY, true );
40 return $meta ? $meta : 'floating-buttons';
41 }
42
43 public static function is_editing_existing_floating_buttons_page() {
44 $action = ElementorUtils::get_super_global_value( $_GET, 'action' );
45 $post_id = ElementorUtils::get_super_global_value( $_GET, 'post' );
46
47 return 'elementor' === $action && static::is_floating_buttons_type_meta_key( $post_id );
48 }
49
50 public static function is_creating_floating_buttons_page() {
51 $action = ElementorUtils::get_super_global_value( $_POST, 'action' ); //phpcs:ignore WordPress.Security.NonceVerification.Missing
52 $post_id = ElementorUtils::get_super_global_value( $_POST, 'editor_post_id' ); //phpcs:ignore WordPress.Security.NonceVerification.Missing
53
54 return 'elementor_ajax' === $action && static::is_floating_buttons_type_meta_key( $post_id );
55 }
56
57 public static function is_floating_buttons_type_meta_key( $post_id ) {
58 return Module::FLOATING_BUTTONS_DOCUMENT_TYPE === get_post_meta( $post_id, Document::TYPE_META_KEY, true );
59 }
60
61 public function print_content() {
62 $plugin = \Elementor\Plugin::$instance;
63
64 if ( $plugin->preview->is_preview_mode( $this->get_main_id() ) ) {
65 // PHPCS - the method builder_wrapper is safe.
66 echo $plugin->preview->builder_wrapper( '' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
67 } else {
68 // PHPCS - the method get_content is safe.
69 echo $this->get_content(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
70 }
71 }
72
73 public function get_location() {
74 return self::get_property( 'location' );
75 }
76
77 public static function get_type() {
78 return Floating_Buttons_Module::FLOATING_BUTTONS_DOCUMENT_TYPE;
79 }
80
81 public static function register_post_fields_control( $document ) {}
82
83 public static function register_hide_title_control( $document ) {}
84
85 public function get_name() {
86 return Floating_Buttons_Module::FLOATING_BUTTONS_DOCUMENT_TYPE;
87 }
88
89 public function filter_admin_row_actions( $actions ) {
90 unset( $actions['edit'] );
91 unset( $actions['inline hide-if-no-js'] );
92 $built_with_elementor = parent::filter_admin_row_actions( [] );
93
94 if ( isset( $actions['trash'] ) ) {
95 $delete = $actions['trash'];
96 unset( $actions['trash'] );
97 $actions['trash'] = $delete;
98 }
99
100 if ( 'publish' === $this->get_post()->post_status ) {
101 $actions = $this->set_as_entire_site( $actions );
102 }
103
104 return $built_with_elementor + $actions;
105 }
106
107 public static function get_meta_query_for_floating_buttons( string $floating_element_type ): array {
108 $meta_query = [
109 'relation' => 'AND',
110 [
111 'key' => '_elementor_conditions',
112 'compare' => 'EXISTS',
113 ],
114 ];
115
116 if ( 'floating-buttons' === $floating_element_type ) {
117 $meta_query[] = [
118 'relation' => 'OR',
119 [
120 'key' => Module::FLOATING_ELEMENTS_TYPE_META_KEY,
121 'compare' => 'NOT EXISTS',
122 ],
123 [
124 'key' => Module::FLOATING_ELEMENTS_TYPE_META_KEY,
125 'value' => 'floating-buttons',
126 ],
127 ];
128 } else {
129 $meta_query[] = [
130 'key' => Module::FLOATING_ELEMENTS_TYPE_META_KEY,
131 'value' => $floating_element_type,
132 ];
133 }
134
135 return $meta_query;
136 }
137
138 /**
139 * Tries to find the post id of the floating element that is set as entire site.
140 * If found, returns the post id, otherwise returns 0.
141 *
142 * @param string $floating_element_type
143 *
144 * @return int
145 */
146 public static function get_set_as_entire_site_post_id( string $floating_element_type ): int {
147 static $types = [];
148
149 if ( isset( $types[ $floating_element_type ] ) ) {
150 return $types[ $floating_element_type ];
151 }
152
153 $query = new \WP_Query( [
154 'post_type' => Floating_Buttons_Module::CPT_FLOATING_BUTTONS,
155 'posts_per_page' => -1,
156 'post_status' => 'publish',
157 'fields' => 'ids',
158 'no_found_rows' => true,
159 'update_post_term_cache' => false,
160 'meta_query' => static::get_meta_query_for_floating_buttons( $floating_element_type ),
161 ] );
162
163 foreach ( $query->get_posts() as $post_id ) {
164 $conditions = get_post_meta( $post_id, '_elementor_conditions', true );
165
166 if ( ! $conditions ) {
167 continue;
168 }
169
170 if ( in_array( 'include/general', $conditions ) ) {
171 $types[ $floating_element_type ] = $post_id;
172 return $post_id;
173 }
174 }
175
176 return 0;
177 }
178
179 public function set_as_entire_site( $actions ) {
180 $floating_element_type = static::get_floating_element_type( $this->get_main_id() );
181 $current_set_as_entire_site_post_id = static::get_set_as_entire_site_post_id( $floating_element_type );
182
183 if ( $current_set_as_entire_site_post_id === $this->get_main_id() ) {
184 $actions['set_as_entire_site'] = sprintf(
185 '<a style="color:red;" href="?post=%s&action=remove_from_entire_site&_wpnonce=%s">%s</a>',
186 $this->get_post()->ID,
187 wp_create_nonce( 'remove_from_entire_site_' . $this->get_post()->ID ),
188 esc_html__( 'Remove From Entire Site', 'elementor' )
189 );
190 } else {
191 $actions['set_as_entire_site'] = sprintf(
192 '<a href="?post=%s&action=set_as_entire_site&_wpnonce=%s">%s</a>',
193 $this->get_post()->ID,
194 wp_create_nonce( 'set_as_entire_site_' . $this->get_post()->ID ),
195 esc_html__( 'Set as Entire Site', 'elementor' )
196 );
197 }
198
199 return $actions;
200 }
201
202 public static function get_title() {
203 return esc_html__( 'Floating Element', 'elementor' );
204 }
205
206 public static function get_plural_title() {
207 return esc_html__( 'Floating Elements', 'elementor' );
208 }
209
210 public static function get_create_url() {
211 return parent::get_create_url() . '#library';
212 }
213
214 public function save( $data ) {
215 if ( empty( $data['settings']['template'] ) ) {
216 $data['settings']['template'] = Page_Templates_Module::TEMPLATE_CANVAS;
217 }
218
219 return parent::save( $data );
220 }
221
222 public function admin_columns_content( $column_name ) {
223 if ( 'elementor_library_type' === $column_name ) {
224 $admin_filter_url = admin_url( Source_Local::ADMIN_MENU_SLUG . '&elementor_library_type=' . $this->get_name() );
225 $meta = static::get_floating_element_type( $this->get_main_id() );
226 printf( '<a href="%s">%s</a>', $admin_filter_url, Module::get_floating_elements_types()[ $meta ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
227 }
228 }
229
230 public function get_edit_url() {
231 return add_query_arg(
232 [
233 'post' => $this->get_main_id(),
234 'action' => 'elementor',
235 'floating_element' => get_post_meta(
236 $this->get_main_id(),
237 Module::FLOATING_ELEMENTS_TYPE_META_KEY,
238 true
239 ),
240 ],
241 admin_url( 'post.php' )
242 );
243 }
244
245 protected function get_remote_library_config() {
246 $config = [
247 'type' => 'floating_button',
248 'default_route' => 'templates/floating-buttons',
249 'autoImportSettings' => true,
250 ];
251
252 return array_replace_recursive( parent::get_remote_library_config(), $config );
253 }
254 }
255