Completed
Push — add/sync-rest-2 ( 0f1049...2638b5 )
by
unknown
09:02
created

Jetpack_Sync_Post_Meta::update_post_meta()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 3
eloc 8
nc 3
nop 4
1
<?php
2
3
class Jetpack_Sync_Post_Meta {
4
5
	static $sync = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $sync.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6
	static $delete = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $delete.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7
8
	static $max_to_sync = 10;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $max_to_sync.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
9
	static $que_option_name = 'jetpack_sync_post_ids_que';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $que_option_name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
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