Purpose
Locks in Wonderful Relations prevent multiple users from editing the same entry simultaneously, avoiding accidental data overwrites. Instead of traditional SQL-based row or table locks—unsuitable for web applications where all users share the same database connection—Wonderful Relations implements a session-based locking mechanism.
When a user opens an entry, it becomes locked for other users. Additionally, session-based locks prevent users from opening the same entry in multiple modals and accidentally overwriting their own changes. The system also displays who locked an entry, providing transparency and reducing conflicts.
Lock duration can be configured in global settings, and administrators have the ability to release locks via the Wonderful Relations Dashboard.
Visual Example
User Initiated Entry Unlocking
Overview: This feature allowing users to unlock entries on their own. This is particularly relevant in environments where user roles require distinct levels of access and control over entries.
Implementation:
- User Group Assignment:
- To enable user-initiated unlocking, the user must be assigned to a specific group.
- This group should have a particular option enabled:
allowed_to_force_unlock_entries
. - This option should be set to
true
to activate the unlocking ability for members of the group.
- This group should have a particular option enabled:
- WordPress Admin Consideration:
- For WordPress administrators to utilize this feature, they must also be assigned to a group with the
allowed_to_force_unlock_entries
option enabled. - This ensures uniform functionality across different user roles, including administrative ones.
- For WordPress administrators to utilize this feature, they must also be assigned to a group with the
Handling Wrapped Actions in EditAction
Context: In certain cases, the EditAction
is nested within another action. For example, an action may first verify the existence of an invoice, create it if not present, and then proceed to EditAction
.
Challenge:
- The nonce generated in the button payload is associated with the outer wrapped action, not the
EditAction
. - However, the button is intended to trigger an
EditAction
, leading to a mismatch in nonce validation.
Solution: To ensure correct validation:
- Modify
$_POST
before processing the request. - Replace the existing nonce with one generated for
Edit Action
. - Implement the following update in your code:
$_POST['data']['nonce'] = wp_create_nonce("form_edit_entry")
This adjustment ensures the nonce corresponds to EditAction, allowing secure and seamless processing.
Conclusion
The locking system in Wonderful Relations is built-in and works out-of-the-box with forms and entries. No additional implementation is needed—once a form is used, locking is automatically applied. Users see who is editing an entry, preventing accidental overwrites. Locking behavior can be fine-tuned via options, and administrators can manually release locks when necessary. This ensures a hassle-free and secure editing experience across the platform.