|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Jetpack_Sync_Post_Meta { |
|
4
|
|
|
|
|
5
|
|
|
static $sync = array(); |
|
|
|
|
|
|
6
|
|
|
static $delete = array(); |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
static $max_to_sync = 10; |
|
|
|
|
|
|
9
|
|
|
static $que_option_name = 'jetpack_sync_post_ids_que'; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
static function init() { |
|
12
|
|
|
// Mark the post as needs updating when post meta data changes. |
|
13
|
|
|
add_action( 'added_post_meta', array( __CLASS__, 'update_post_meta' ), 10, 4 ); |
|
14
|
|
|
add_action( 'updated_postmeta', array( __CLASS__, 'update_post_meta' ), 10, 4 ); |
|
15
|
|
|
add_action( 'deleted_post_meta', array( __CLASS__, 'delete_post_meta' ), 10, 4 ); |
|
16
|
|
|
|
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* added_post_meta, update_post_meta, delete_post_meta |
|
21
|
|
|
*/ |
|
22
|
|
|
static function update_post_meta( $meta_ids, $post_id, $meta_key, $meta_value ) { |
|
23
|
|
|
$ignore_meta_keys = array( '_edit_lock', '_pingme', '_encloseme' ); |
|
24
|
|
|
if ( in_array( $meta_key, $ignore_meta_keys ) ) { |
|
25
|
|
|
return; |
|
26
|
|
|
} |
|
27
|
|
|
$data = array( 'id' => $meta_ids, 'key' => $meta_key, 'post_id' => $post_id, 'value' => $meta_value ); |
|
28
|
|
|
$key = ( ! is_array( $meta_ids ) ? $meta_ids : json_encode( $data ) ); |
|
29
|
|
|
|
|
30
|
|
|
self::$sync[ $key ] = $data; |
|
31
|
|
|
Jetpack_Sync::schedule_sync(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
static function delete_post_meta( $meta_ids, $post_id, $meta_key, $meta_value ) { |
|
35
|
|
|
$data = array( |
|
36
|
|
|
'id' => $meta_ids, |
|
37
|
|
|
'key' => $meta_key, |
|
38
|
|
|
'post_id' => $post_id, |
|
39
|
|
|
'value' => $meta_value |
|
40
|
|
|
); |
|
41
|
|
|
$key = ( ! is_array( $meta_ids ) ? $meta_ids : json_encode( $data ) ); |
|
42
|
|
|
self::$delete[ $key ] = $data; |
|
43
|
|
|
Jetpack_Sync::schedule_sync(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
static function post_meta_to_sync() { |
|
47
|
|
|
return array_values( self::$sync ); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
static function post_meta_to_delete() { |
|
51
|
|
|
return array_values( self::$delete ); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
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.