PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.0-dev2
Elementor Website Builder – more than just a page builder v4.0.0-dev2
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 / classes / action / action-handler.php

action-handler.php in Elementor Website Builder – more than just a page builder 4.0.0-dev2, at modules/floating-buttons/classes/action/action-handler.php

85 lines 2.5 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\Classes\Action;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 use Elementor\Modules\FloatingButtons\Classes\Conditions\Conditions_Cache;
10 use Elementor\Modules\FloatingButtons\Documents\Floating_Buttons;
11 use Elementor\Modules\FloatingButtons\Module;
12
13 class Action_Handler {
14
15 protected string $action;
16 protected array $menu_args;
17 protected Conditions_Cache $conditions_cache;
18
19 public function __construct( string $action, array $menu_args ) {
20 $this->action = $action;
21 $this->menu_args = $menu_args;
22 $this->conditions_cache = new Conditions_Cache();
23 }
24
25 public function process_action() {
26 if ( ! current_user_can( 'edit_posts' ) ) {
27 return;
28 }
29
30 switch ( $this->action ) {
31 case 'remove_from_entire_site':
32 $this->handle_remove_from_entire_site();
33 break;
34 case 'set_as_entire_site':
35 $this->handle_set_as_entire_site();
36 break;
37 default:
38 break;
39 }
40 }
41
42 private function handle_remove_from_entire_site(): void {
43 $post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT );
44 check_admin_referer( 'remove_from_entire_site_' . $post_id );
45 delete_post_meta( $post_id, '_elementor_conditions' );
46 $this->conditions_cache->remove_from_cache( $post_id );
47
48 wp_redirect( $this->menu_args['menu_slug'] );
49 exit;
50 }
51
52 private function handle_set_as_entire_site(): void {
53 $post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT );
54 check_admin_referer( 'set_as_entire_site_' . $post_id );
55
56 $posts = $this->get_published_floating_elements( $post_id );
57
58 foreach ( $posts as $post_id_to_delete ) {
59 delete_post_meta( $post_id_to_delete, '_elementor_conditions' );
60 $this->conditions_cache->remove_from_cache( $post_id_to_delete );
61 }
62
63 update_post_meta( $post_id, '_elementor_conditions', [ 'include/general' ] );
64 $this->conditions_cache->add_to_cache( $post_id );
65
66 wp_redirect( $this->menu_args['menu_slug'] );
67 exit;
68 }
69
70 private function get_published_floating_elements( int $post_id ): array {
71 return get_posts( [
72 'post_type' => Module::CPT_FLOATING_BUTTONS,
73 'posts_per_page' => -1,
74 'post_status' => 'publish',
75 'fields' => 'ids',
76 'no_found_rows' => true,
77 'update_post_term_cache' => false,
78 'update_post_meta_cache' => false,
79 'meta_query' => Floating_Buttons::get_meta_query_for_floating_buttons(
80 Floating_Buttons::get_floating_element_type( $post_id )
81 ),
82 ] );
83 }
84 }
85