1 | <?php |
||
3 | class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { |
||
4 | |||
5 | public function name() { |
||
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 | // full sync |
||
24 | add_filter( 'jetpack_sync_before_send_jetpack_full_sync_posts', array( $this, 'expand_post_ids' ) ); |
||
25 | } |
||
26 | |||
27 | public function enqueue_full_sync_actions() { |
||
33 | |||
34 | function get_full_sync_actions() { |
||
37 | |||
38 | /** |
||
39 | * Process content before send |
||
40 | */ |
||
41 | |||
42 | function expand_wp_insert_post( $args ) { |
||
43 | return array( $args[0], $this->filter_post_content_and_add_links( $args[1] ), $args[2] ); |
||
44 | } |
||
45 | |||
46 | // Expands wp_insert_post to include filtered content |
||
47 | function filter_post_content_and_add_links( $post ) { |
||
48 | |||
49 | /** |
||
50 | * Filters whether to prevent sending post data to .com |
||
51 | * |
||
52 | * Passing true to the filter will prevent the post data from being sent |
||
53 | * to the WordPress.com. |
||
54 | * Instead we pass data that will still enable us to do a checksum against the |
||
55 | * Jetpacks data but will prevent us from displaying the data on in the API as well as |
||
56 | * other services. |
||
57 | * @since 4.2.0 |
||
58 | * |
||
59 | * @param boolean false prevent post data from bing sycned to WordPress.com |
||
60 | * @param mixed $post WP_POST object |
||
61 | */ |
||
62 | if ( apply_filters( 'jetpack_sync_prevent_sending_post_data', false, $post ) ) { |
||
63 | // We only send the bare necessery object to be able to create a checksum. |
||
64 | $blocked_post = new stdClass(); |
||
65 | $blocked_post->ID = $post->ID; |
||
66 | $blocked_post->post_modified = $post->post_modified; |
||
67 | $blocked_post->post_modified_gmt = $post->post_modified_gmt; |
||
68 | $blocked_post->post_status = 'jetpack_sync_blocked'; |
||
69 | return $blocked_post; |
||
70 | } |
||
71 | |||
72 | if ( 0 < strlen( $post->post_password ) ) { |
||
73 | $post->post_password = 'auto-' . wp_generate_password( 10, false ); |
||
74 | } |
||
75 | /** This filter is already documented in core. wp-includes/post-template.php */ |
||
76 | $post->post_content_filtered = apply_filters( 'the_content', $post->post_content ); |
||
77 | $post->post_excerpt_filtered = apply_filters( 'the_content', $post->post_excerpt ); |
||
78 | $post->permalink = get_permalink( $post->ID ); |
||
79 | $post->shortlink = wp_get_shortlink( $post->ID ); |
||
80 | $post->dont_email_post_to_subs = get_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', true ); |
||
81 | |||
82 | return $post; |
||
83 | } |
||
84 | |||
85 | public function expand_post_ids( $args ) { |
||
97 | } |
||
98 |