PluginProbe
Elementor Website Builder – more than just a page builder / 3.4.4
Elementor Website Builder – more than just a page builder v3.4.4
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 / includes / heartbeat.php

heartbeat.php in Elementor Website Builder – more than just a page builder 3.4.4, at includes/heartbeat.php

98 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 /**
9 * Elementor heartbeat.
10 *
11 * Elementor heartbeat handler class is responsible for initializing Elementor
12 * heartbeat. The class communicates with WordPress Heartbeat API while working
13 * with Elementor.
14 *
15 * @since 1.0.0
16 */
17 class Heartbeat {
18
19 /**
20 * Heartbeat received.
21 *
22 * Locks the Heartbeat response received when editing with Elementor.
23 *
24 * Fired by `heartbeat_received` filter.
25 *
26 * @since 1.0.0
27 * @access public
28 *
29 * @param array $response The Heartbeat response.
30 * @param array $data The `$_POST` data sent.
31 *
32 * @return array Heartbeat response received.
33 */
34 public function heartbeat_received( $response, $data ) {
35 if ( isset( $data['elementor_post_lock']['post_ID'] ) ) {
36 $post_id = $data['elementor_post_lock']['post_ID'];
37 $locked_user = Plugin::$instance->editor->get_locked_user( $post_id );
38
39 if ( ! $locked_user || ! empty( $data['elementor_force_post_lock'] ) ) {
40 Plugin::$instance->editor->lock_post( $post_id );
41 } else {
42 $response['locked_user'] = $locked_user->display_name;
43 }
44
45 /** @var Core\Common\Modules\Ajax\Module $ajax */
46 $ajax = Plugin::$instance->common->get_component( 'ajax' );
47
48 $response['elementorNonce'] = $ajax->create_nonce();
49 }
50 return $response;
51 }
52
53 /**
54 * Refresh nonces.
55 *
56 * Filter the nonces to send to the editor when editing with Elementor. Used
57 * to refresh the nonce when the nonce expires while editing. This way the
58 * user doesn't need to log-in again as Elementor fetches the new nonce from
59 * the server using ajax.
60 *
61 * Fired by `wp_refresh_nonces` filter.
62 *
63 * @since 1.8.0
64 * @access public
65 *
66 * @param array $response The no-priv Heartbeat response object or array.
67 * @param array $data The `$_POST` data sent.
68 *
69 * @return array Refreshed nonces.
70 */
71 public function refresh_nonces( $response, $data ) {
72 if ( isset( $data['elementor_post_lock']['post_ID'] ) ) {
73 /** @var Core\Common\Modules\Ajax\Module $ajax */
74 $ajax = Plugin::$instance->common->get_component( 'ajax' );
75
76 $response['elementor-refresh-nonces'] = [
77 'elementorNonce' => $ajax->create_nonce(),
78 'heartbeatNonce' => wp_create_nonce( 'heartbeat-nonce' ),
79 ];
80 }
81
82 return $response;
83 }
84
85 /**
86 * Heartbeat constructor.
87 *
88 * Initializing Elementor heartbeat.
89 *
90 * @since 1.0.0
91 * @access public
92 */
93 public function __construct() {
94 add_filter( 'heartbeat_received', [ $this, 'heartbeat_received' ], 10, 2 );
95 add_filter( 'wp_refresh_nonces', [ $this, 'refresh_nonces' ], 30, 2 );
96 }
97 }
98