PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / trunk
Forumax – AI Powered Advanced Community Forum Plugin vtrunk
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / lib / bbpress / includes / common / locks.php

locks.php in Forumax – AI Powered Advanced Community Forum Plugin trunk, at lib/bbpress/includes/common/locks.php

83 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Locking
5 *
6 * @package bbPress
7 * @subpackage Common
8 */
9
10 // Exit if accessed directly
11 defined( 'ABSPATH' ) || exit;
12
13 /**
14 * Check to see if the post is currently being edited by another user.
15 *
16 * @see wp_check_post_lock()
17 *
18 * @since 2.6.0 bbPress (r6340)
19 *
20 * @param int $post_id ID of the post to check for editing
21 * @return integer False: not locked or locked by current user. Int: user ID of user with lock.
22 */
23 function bbp_check_post_lock( $post_id = 0 ) {
24
25 // Bail if no post
26 if ( !$post = get_post( $post_id ) ) {
27 return false;
28 }
29
30 // Bail if no lock
31 if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) ) {
32 return false;
33 }
34
35 // Get lock
36 $lock = explode( ':', $lock );
37 $time = $lock[0];
38 $user = (int) isset( $lock[1] )
39 ? $lock[1]
40 : get_post_meta( $post->ID, '_edit_last', true );
41
42 // Filter editing window duration
43 $time_window = apply_filters( 'bbp_check_post_lock_window', 3 * MINUTE_IN_SECONDS );
44
45 // Return user who is or last edited
46 if ( ! empty( $time ) && ( $time > ( time() - $time_window ) ) && ( $user !== bbp_get_current_user_id() ) ) {
47 return (int) $user;
48 }
49
50 return false;
51 }
52
53 /**
54 * Mark the post as currently being edited by the current user
55 *
56 * @since 2.6.0 bbPress (r6340)
57 *
58 * @param int $post_id ID of the post to being edited
59 * @return bool|array Returns false if the post doesn't exist of there is no current user, or
60 * an array of the lock time and the user ID.
61 */
62 function bbp_set_post_lock( $post_id = 0 ) {
63
64 // Bail if no post
65 if ( !$post = get_post( $post_id ) ) {
66 return false;
67 }
68
69 // Bail if no user
70 if ( 0 == ( $user_id = get_current_user_id() ) ) {
71 return false;
72 }
73
74 // Get time & lock value
75 $now = time();
76 $lock = "{$now}:{$user_id}";
77
78 // Set lock value
79 update_post_meta( $post->ID, '_edit_lock', $lock );
80
81 return array( $now, $user_id );
82 }
83