|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Jetpack_Sync_Meta { |
|
4
|
|
|
|
|
5
|
|
|
static $sync = array(); |
|
|
|
|
|
|
6
|
|
|
static $delete = array(); |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
static $max_to_sync = 10; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
static private $meta_types = array( 'post', 'comment' ); |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
static function init() { |
|
14
|
|
|
foreach ( self::$meta_types as $type ) { |
|
15
|
|
|
add_action( 'added_' . $type . '_meta', array( __CLASS__, 'update_meta' ), 10, 4 ); |
|
16
|
|
|
add_action( 'updated_' . $type . '_meta', array( __CLASS__, 'update_meta' ), 10, 4 ); |
|
17
|
|
|
add_action( 'deleted_' . $type . '_meta', array( __CLASS__, 'delete_meta' ), 10, 4 ); |
|
18
|
|
|
} |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
static function update_meta( $meta_ids, $object_id, $meta_key, $meta_value ) { |
|
22
|
|
|
$action_array = explode( '_', current_action() ); |
|
23
|
|
|
$type = $action_array[1]; |
|
24
|
|
|
|
|
25
|
|
|
$ignore_meta_keys = array( '_edit_lock', '_pingme', '_encloseme' ); |
|
26
|
|
|
if ( in_array( $meta_key, $ignore_meta_keys ) ) { |
|
27
|
|
|
return; |
|
28
|
|
|
} |
|
29
|
|
|
$data = array( 'id' => $meta_ids, 'key' => $meta_key, $type.'_id' => $object_id, 'value' => $meta_value ); |
|
30
|
|
|
$key = ( ! is_array( $meta_ids ) ? $meta_ids : json_encode( $data ) ); |
|
31
|
|
|
|
|
32
|
|
|
self::$sync[ $type ][ $key ] = $data; |
|
33
|
|
|
Jetpack_Sync::schedule_sync(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
static function delete_meta( $meta_ids, $object_id, $meta_key, $meta_value ) { |
|
37
|
|
|
$action_array = explode( '_', current_action() ); |
|
38
|
|
|
$type = $action_array[1]; |
|
39
|
|
|
$data = array( |
|
40
|
|
|
'id' => $meta_ids, |
|
41
|
|
|
'key' => $meta_key, |
|
42
|
|
|
$type.'_id' => $object_id, |
|
43
|
|
|
'value' => $meta_value, |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
$key = ( ! is_array( $meta_ids ) ? $meta_ids : json_encode( $data ) ); |
|
47
|
|
|
|
|
48
|
|
|
self::$delete[ $type ][ $key ] = $data; |
|
49
|
|
|
Jetpack_Sync::schedule_sync(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
static function meta_to_sync( $type ) { |
|
53
|
|
|
if ( isset( self::$sync[ $type ] ) ) { |
|
54
|
|
|
return array_values( self::$sync[ $type ] ); |
|
55
|
|
|
} |
|
56
|
|
|
return array(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
static function meta_to_delete( $type ) { |
|
60
|
|
|
if ( isset( self::$delete[ $type ] ) ) { |
|
61
|
|
|
return array_values( self::$delete[ $type ] ); |
|
62
|
|
|
} |
|
63
|
|
|
return array(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
|
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.