Make WordPress Core

Ticket #38067: auth.php

File auth.php, 1.4 KB (added by sebastian.pisula, 8 years ago)

if filter will be exists this is solution for my problem. I need only filter :)

Line 
1<?php
2
3add_filter( 'wp_post_lock_status', function ( $lock_status, $post_id, $time, $time_window, $user ) {
4
5        if ( $lock_status === false ) {
6
7                if ( get_post_meta( $post_id, '_edit_lock_hash', 1 ) !== wp360_get_unique_hash() ) {
8                        return $user;
9                }
10        }
11
12        return $lock_status;
13}, 10, 5 );
14
15
16function wp360_get_unique_hash() {
17
18        if ( isset( $_COOKIE[ 'wordpress_logged_in_unique_' . COOKIEHASH ] ) ) {
19                return $_COOKIE[ 'wordpress_logged_in_unique_' . COOKIEHASH ];
20        }
21
22        return false;
23}
24
25add_action( 'set_logged_in_cookie', function ( $logged_in_cookie, $expire, $expiration, $user_id, $scheme ) {
26
27        $secure = is_ssl();
28        $secure = apply_filters( 'secure_auth_cookie', $secure, $user_id );
29
30        $secure_logged_in_cookie = $secure && 'https' === parse_url( get_option( 'home' ), PHP_URL_SCHEME );
31        $secure_logged_in_cookie = apply_filters( 'secure_logged_in_cookie', $secure_logged_in_cookie, $user_id, $secure );
32
33        $hash = md5( isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '' . wp_generate_password() );
34
35        setcookie( 'wordpress_logged_in_unique_' . COOKIEHASH, $hash, $expire, COOKIEPATH, COOKIE_DOMAIN,
36                $secure_logged_in_cookie, true );
37}, 10, 5 );
38
39add_action( 'updated_postmeta', function ( $meta_id, $object_id, $meta_key, $meta_value ) {
40
41        if ( $meta_key === '_edit_lock' && $hash = wp360_get_unique_hash() ) {
42                update_post_meta( $object_id, '_edit_lock_hash', $hash );
43        }
44}, 10, 4 );