4 if ( ! defined(
'GRAVITYVIEW_DIR' ) ) {
26 if ( ! has_action(
'wp_enqueue_scripts', array( $this,
'maybe_enqueue_scripts' ) ) ) {
27 add_action(
'wp_enqueue_scripts', array( $this,
'maybe_enqueue_scripts' ) );
30 add_action(
'wp_ajax_gf_lock_request_entry', array( $this,
'ajax_lock_request' ), 1 );
31 add_action(
'wp_ajax_gf_reject_lock_request_entry', array( $this,
'ajax_reject_lock_request' ), 1 );
32 add_action(
'wp_ajax_nopriv_gf_lock_request_entry', array( $this,
'ajax_lock_request' ) );
33 add_action(
'wp_ajax_nopriv_gf_reject_lock_request_entry', array( $this,
'ajax_reject_lock_request' ) );
38 $object_id = rgget(
'object_id' );
40 echo json_encode( $response );
46 $object_id = rgget(
'object_id' );
48 echo json_encode( $response );
54 GFCache::delete(
'lock_request_entry_' . $object_id );
61 if ( 0 == ( $user_id = get_current_user_id() ) ) {
65 $lock_holder_user_id = $this->
check_lock( $object_id );
68 if ( ! $lock_holder_user_id ) {
70 $result[
'html'] = __(
'You now have control',
'gk-gravityview' );
71 $result[
'status'] =
'lock_obtained';
75 $user = get_userdata( $lock_holder_user_id );
76 $result[
'html'] = sprintf( __(
'Your request has been sent to %s.',
'gk-gravityview' ),
$user->display_name );
78 $result[
'html'] = __(
'Your request has been sent.',
'gk-gravityview' );
83 $result[
'status'] =
'lock_requested';
90 GFCache::set(
'lock_request_entry_' . $object_id, $lock_request_value,
true, 120 );
114 if ( ! $post || ! is_a( $post,
'WP_Post' ) ) {
120 $entry_array =
$entry->as_entry();
122 $continue_enqueuing =
false;
125 foreach( $views->all() as $view ) {
128 if( ! $view->settings->get(
'edit_locking' ) ) {
133 $joined_forms = $view::get_joined_forms( $view->ID );
135 $entry_form_id = $entry_array[
'form_id'];
137 if( ! isset( $joined_forms[ $entry_form_id ] ) ) {
141 $continue_enqueuing =
true;
146 if( ! $continue_enqueuing ) {
166 $min = defined(
'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || isset( $_GET[
'gform_debug'] ) ?
'' :
'.min';
167 $locking_path = GFCommon::get_base_url() .
'/includes/locking/';
169 wp_enqueue_script(
'gforms_locking', $locking_path .
"js/locking{$min}.js", array(
'jquery',
'heartbeat' ), GFCommon::$version );
170 wp_enqueue_style(
'gforms_locking_css', $locking_path .
"css/locking{$min}.css", array(
'edit' ), GFCommon::$version );
172 $translations = array_map(
'wp_strip_all_tags', $this->
get_strings() );
175 'noResponse' => $translations[
'no_response'],
176 'requestAgain' => $translations[
'request_again'],
177 'requestError' => $translations[
'request_error'],
178 'gainedControl' => $translations[
'gained_control'],
179 'rejected' => $translations[
'request_rejected'],
180 'pending' => $translations[
'request_pending'],
186 'hasLock' => ! $lock_user_id ? 1 : 0,
188 'objectID' =>
$entry[
'id'],
189 'objectType' =>
'entry',
193 wp_localize_script(
'gforms_locking',
'gflockingVars', $vars );
211 $user = get_userdata( $user_id );
213 $locked = $user_id &&
$user;
215 $hidden = $locked ?
'' :
' hidden';
219 $avatar = get_avatar( $user->ID, 64 );
220 $person_editing_text = $user->display_name;
222 $current_user = wp_get_current_user();
223 $avatar = get_avatar( $current_user->ID, 64 );
224 $person_editing_text = _x(
'the person who is editing the entry',
'Referring to the user who is currently editing a locked entry',
'gk-gravityview' );
227 $message =
'<div class="gform-locked-message"> 228 <div class="gform-locked-avatar">' . $avatar .
'</div> 229 <p class="currently-editing" tabindex="0">' . esc_html( sprintf( $this->
get_string(
'currently_locked' ), $person_editing_text ) ) .
'</p> 232 <a id="gform-take-over-button" style="display:none" class="button button-primary wp-tab-first" href="' . esc_url( add_query_arg(
'get-edit-lock',
'1' ) ) .
'">' . esc_html__(
'Take Over',
'gk-gravityview' ) .
'</a> 233 <button id="gform-lock-request-button" class="button button-primary wp-tab-last">' . esc_html__(
'Request Control',
'gk-gravityview' ) .
'</button> 234 <a class="button" onclick="history.back(-1); return false;">' . esc_html( $this->
get_string(
'cancel' ) ) .
'</a> 236 <div id="gform-lock-request-status"> 243 $message =
'<div class="gform-taken-over"> 244 <div class="gform-locked-avatar"></div> 245 <p class="wp-tab-first" tabindex="0"> 246 <span class="currently-editing"></span><br> 249 <a id="gform-release-lock-button" class="button button-primary wp-tab-last" href="' . esc_url( add_query_arg(
'release-edit-lock',
'1' ) ) .
'">' . esc_html( $this->
get_string(
'accept' ) ) .
'</a> 250 <button id="gform-reject-lock-request-button" style="display:none" class="button button-primary wp-tab-last">' . esc_html__(
'Reject Request',
'gk-gravityview' ) .
'</button> 255 $html =
'<div id="gform-lock-dialog" class="notification-dialog-wrap' . $hidden .
'"> 256 <div class="notification-dialog-background"></div> 257 <div class="notification-dialog">';
276 $translations = array(
277 'currently_locked' => __(
'This entry is currently locked. Click on the "Request Control" button to let %s know you\'d like to take over.',
'gk-gravityview' ),
278 'currently_editing' => __(
'%s is currently editing this entry',
'gk-gravityview' ),
279 'taken_over' => __(
'%s has taken over and is currently editing this entry.',
'gk-gravityview' ),
280 'lock_requested' => __(
'%s has requested permission to take over control of this entry.',
'gk-gravityview' ),
281 'accept' => __(
'Accept',
'gk-gravityview' ),
282 'cancel' => __(
'Cancel',
'gk-gravityview' ),
283 'gained_control' => __(
'You now have control',
'gk-gravityview' ),
284 'request_pending' => __(
'Pending',
'gk-gravityview' ),
285 'no_response' => __(
'No response',
'gk-gravityview' ),
286 'request_again' => __(
'Request again',
'gk-gravityview' ),
287 'request_error' => __(
'Error',
'gk-gravityview' ),
288 'request_rejected' => __(
'Your request was rejected',
'gk-gravityview' ),
291 $translations = array_map(
'wp_strip_all_tags', $translations );
293 return $translations;
304 return \GV\Utils::get( $this->
get_strings(), $string,
'' );
323 $current_url = add_query_arg( $wp->query_string,
'', home_url( $wp->request ) );
325 if ( isset( $_GET[
'get-edit-lock'] ) ) {
327 echo
'<script>window.location = ' . json_encode( remove_query_arg(
'get-edit-lock', $current_url ) ) .
';</script>';
329 }
else if ( isset( $_GET[
'release-edit-lock'] ) ) {
331 $current_url = remove_query_arg(
'edit', $current_url );
332 echo
'<script>window.location = ' . json_encode( remove_query_arg(
'release-edit-lock', $current_url ) ) .
';</script>';
335 if ( ! $user_id = $this->
check_lock( $entry_id ) ) {
353 if ( $user_id != get_current_user_id() ) {
370 return GFCache::get(
'lock_entry_' . $entry_id );
382 GFCache::set(
'lock_entry_' . $entry_id, $user_id,
true, 1500 );
393 GFCache::delete(
'lock_entry_' . $entry_id );
407 $entry = GFAPI::get_entry( $entry_id );
413 if ( 0 === ( $user_id = get_current_user_id() ) ) {
get_strings()
Localized string for the UI.
maybe_lock_object( $entry_id)
Lock the entry...
delete_lock_request_meta( $object_id)
static check_user_cap_edit_entry( $entry, $view=0)
checks if user has permissions to edit a specific entry
static from_post(\WP_Post $post)
Get a list of objects inside the supplied .
check_lock( $entry_id)
Is this entry locked to some other user?
If this file is called directly, abort.
ajax_reject_lock_request()
update_lock_request_meta( $object_id, $lock_request_value)
request_lock( $object_id)
set_lock( $entry_id)
Lock the entry to the current user.
enqueue_scripts( $entry)
Enqueue the required scripts and styles from Gravity Forms.
load()
Load extension entry point.
get_lock_ui( $user_id)
Returns a string with the Lock UI HTML markup.
gravityview()
The main GravityView wrapper function.
update_lock_meta( $entry_id, $user_id)
Set the lock for an entry.
get_string( $string)
Get a localized string.
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
maybe_enqueue_scripts()
Checks whether to enqueue scripts based on:
delete_lock_meta( $entry_id)
Release the lock for an entry.
get_lock_meta( $entry_id)
The lock for an entry.