|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { |
|
4
|
|
|
|
|
5
|
|
|
public function name() { |
|
6
|
|
|
return "posts"; |
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
public function set_defaults() {} |
|
10
|
|
|
|
|
11
|
|
|
public function init_listeners( $callable ) { |
|
12
|
|
|
add_action( 'wp_insert_post', $callable, 10, 3 ); |
|
13
|
|
|
add_action( 'deleted_post', $callable, 10 ); |
|
14
|
|
|
add_action( 'jetpack_publicize_post', $callable ); |
|
15
|
|
|
|
|
16
|
|
|
// full sync |
|
17
|
|
|
add_action( 'jetpack_full_sync_posts', $callable ); // also sends post meta |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function init_before_send() { |
|
21
|
|
|
add_filter( 'jetpack_sync_before_send_wp_insert_post', array( $this, 'expand_wp_insert_post' ) ); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Process content before send |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
function expand_wp_insert_post( $args ) { |
|
29
|
|
|
return array( $args[0], $this->filter_post_content_and_add_links( $args[1] ), $args[2] ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
// Expands wp_insert_post to include filtered content |
|
33
|
|
|
function filter_post_content_and_add_links( $post ) { |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Filters whether to prevent sending post data to .com |
|
37
|
|
|
* |
|
38
|
|
|
* Passing true to the filter will prevent the post data from being sent |
|
39
|
|
|
* to the WordPress.com. |
|
40
|
|
|
* Instead we pass data that will still enable us to do a checksum against the |
|
41
|
|
|
* Jetpacks data but will prevent us from displaying the data on in the API as well as |
|
42
|
|
|
* other services. |
|
43
|
|
|
* @since 4.2.0 |
|
44
|
|
|
* |
|
45
|
|
|
* @param boolean false prevent post data from bing sycned to WordPress.com |
|
46
|
|
|
* @param mixed $post WP_POST object |
|
47
|
|
|
*/ |
|
48
|
|
|
if ( apply_filters( 'jetpack_sync_prevent_sending_post_data', false, $post ) ) { |
|
49
|
|
|
// We only send the bare necessery object to be able to create a checksum. |
|
50
|
|
|
$blocked_post = new stdClass(); |
|
51
|
|
|
$blocked_post->ID = $post->ID; |
|
52
|
|
|
$blocked_post->post_modified = $post->post_modified; |
|
53
|
|
|
$blocked_post->post_modified_gmt = $post->post_modified_gmt; |
|
54
|
|
|
$blocked_post->post_status = 'jetpack_sync_blocked'; |
|
55
|
|
|
return $blocked_post; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if ( 0 < strlen( $post->post_password ) ) { |
|
59
|
|
|
$post->post_password = 'auto-' . wp_generate_password( 10, false ); |
|
60
|
|
|
} |
|
61
|
|
|
/** This filter is already documented in core. wp-includes/post-template.php */ |
|
62
|
|
|
$post->post_content_filtered = apply_filters( 'the_content', $post->post_content ); |
|
63
|
|
|
$post->post_excerpt_filtered = apply_filters( 'the_content', $post->post_excerpt ); |
|
64
|
|
|
$post->permalink = get_permalink( $post->ID ); |
|
65
|
|
|
$post->shortlink = wp_get_shortlink( $post->ID ); |
|
66
|
|
|
$post->dont_email_post_to_subs = get_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', true ); |
|
67
|
|
|
|
|
68
|
|
|
return $post; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|