Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/elemento.../modules/componen...
File: component-lock-manager.php
<?php
[0] Fix | Delete
namespace Elementor\Modules\Components;
[1] Fix | Delete
[2] Fix | Delete
use Elementor\Modules\Components\Documents\Component as Component_Document;
[3] Fix | Delete
use Elementor\Modules\Components\Document_Lock_Manager;
[4] Fix | Delete
[5] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[6] Fix | Delete
exit; // Exit if accessed directly.
[7] Fix | Delete
}
[8] Fix | Delete
[9] Fix | Delete
class Component_Lock_Manager extends Document_Lock_Manager {
[10] Fix | Delete
const ONE_HOUR = 60 * 60;
[11] Fix | Delete
private static $instance = null;
[12] Fix | Delete
public function __construct() {
[13] Fix | Delete
parent::__construct( self::ONE_HOUR );
[14] Fix | Delete
}
[15] Fix | Delete
[16] Fix | Delete
public static function get_instance() {
[17] Fix | Delete
if ( null === self::$instance ) {
[18] Fix | Delete
self::$instance = new self();
[19] Fix | Delete
}
[20] Fix | Delete
return self::$instance;
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
public function register_hooks() {
[24] Fix | Delete
add_filter( 'heartbeat_received', [ $this, 'heartbeat_received' ], 10, 2 );
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
public function heartbeat_received( $response, $data ) {
[28] Fix | Delete
if ( ! isset( $data['elementor_post_lock']['post_ID'] ) ) {
[29] Fix | Delete
return $response;
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
$post_id = $data['elementor_post_lock']['post_ID'];
[33] Fix | Delete
[34] Fix | Delete
if ( ! $this->is_component_post( $post_id ) ) {
[35] Fix | Delete
return $response;
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
$lock_data = $this->get_lock_data( $post_id );
[39] Fix | Delete
$user_id = get_current_user_id();
[40] Fix | Delete
if ( $user_id === (int) $lock_data['locked_by'] ) {
[41] Fix | Delete
$this->extend_lock( $post_id );
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
return $response;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Unlock a component.
[50] Fix | Delete
*
[51] Fix | Delete
* @param int $post_id The component ID to unlock
[52] Fix | Delete
* @return bool True if unlock was successful, false otherwise
[53] Fix | Delete
* @throws \Exception If post is not a component type.
[54] Fix | Delete
*/
[55] Fix | Delete
public function unlock( $post_id ) {
[56] Fix | Delete
if ( ! $this->is_component_post( $post_id ) ) {
[57] Fix | Delete
throw new \Exception( 'Post is not a component type' );
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
$lock_data = $this->get_lock_data( $post_id );
[61] Fix | Delete
$current_user_id = get_current_user_id();
[62] Fix | Delete
if ( $lock_data['locked_by'] && (int) $lock_data['locked_by'] !== (int) $current_user_id ) {
[63] Fix | Delete
return false;
[64] Fix | Delete
}
[65] Fix | Delete
return parent::unlock( $post_id );
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Lock a component.
[70] Fix | Delete
*
[71] Fix | Delete
* @param int $post_id The component ID to lock
[72] Fix | Delete
* @return bool|null True if lock was successful, null if locked by another user, false otherwise
[73] Fix | Delete
* @throws \Exception If post is not a component type.
[74] Fix | Delete
*/
[75] Fix | Delete
public function lock( $post_id ) {
[76] Fix | Delete
if ( ! $this->is_component_post( $post_id ) ) {
[77] Fix | Delete
throw new \Exception( 'Post is not a component type' );
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
$lock_data = $this->get_lock_data( $post_id );
[81] Fix | Delete
$is_expired = $this->is_lock_expired( $post_id );
[82] Fix | Delete
[83] Fix | Delete
if ( $is_expired ) {
[84] Fix | Delete
parent::unlock( $post_id );
[85] Fix | Delete
} elseif ( $lock_data['locked_by'] ) {
[86] Fix | Delete
return null;
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
return parent::lock( $post_id );
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
/**
[93] Fix | Delete
* Get lock data for a component.
[94] Fix | Delete
*
[95] Fix | Delete
* @param int $post_id The component ID
[96] Fix | Delete
* @return array Lock data with 'locked_by' (int|null), 'locked_at' (int|null)
[97] Fix | Delete
* @throws \Exception If post is not a component type.
[98] Fix | Delete
*/
[99] Fix | Delete
public function get_lock_data( $post_id ) {
[100] Fix | Delete
if ( ! $this->is_component_post( $post_id ) ) {
[101] Fix | Delete
throw new \Exception( 'Post is not a component type' );
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
return parent::get_lock_data( $post_id );
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* Extend the lock for a component.
[109] Fix | Delete
*
[110] Fix | Delete
* @param int $post_id The component ID
[111] Fix | Delete
* @return bool|null True if extended successfully, null if not locked or locked by another user
[112] Fix | Delete
* @throws \Exception If post is not a component type.
[113] Fix | Delete
*/
[114] Fix | Delete
public function extend_lock( $post_id ) {
[115] Fix | Delete
if ( ! $this->is_component_post( $post_id ) ) {
[116] Fix | Delete
throw new \Exception( 'Post is not a component type' );
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
$lock_data = $this->get_lock_data( $post_id );
[120] Fix | Delete
if ( ! $lock_data['locked_by'] ) {
[121] Fix | Delete
return null;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
$current_user_id = get_current_user_id();
[125] Fix | Delete
if ( (int) $lock_data['locked_by'] !== (int) $current_user_id ) {
[126] Fix | Delete
return null;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
return parent::extend_lock( $post_id );
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
private function is_component_post( $post_id ) {
[133] Fix | Delete
return get_post_type( $post_id ) === Component_Document::TYPE;
[134] Fix | Delete
}
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function