diff options
author | Yury German <blueknight@gentoo.org> | 2017-01-24 23:51:34 -0500 |
---|---|---|
committer | Yury German <blueknight@gentoo.org> | 2017-01-24 23:51:34 -0500 |
commit | 3c539a4713a80181af84c1fedc742436f75c92c4 (patch) | |
tree | e1896c286f3fb98337a6297465974c65f1fe8f26 /plugins/jetpack/sync/class.jetpack-sync-module-posts.php | |
parent | Update theme twentyfifteen to 1.7 (diff) | |
download | blogs-gentoo-3c539a4713a80181af84c1fedc742436f75c92c4.tar.gz blogs-gentoo-3c539a4713a80181af84c1fedc742436f75c92c4.tar.bz2 blogs-gentoo-3c539a4713a80181af84c1fedc742436f75c92c4.zip |
updating jetpack plugin
Diffstat (limited to 'plugins/jetpack/sync/class.jetpack-sync-module-posts.php')
-rw-r--r-- | plugins/jetpack/sync/class.jetpack-sync-module-posts.php | 100 |
1 files changed, 87 insertions, 13 deletions
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-posts.php b/plugins/jetpack/sync/class.jetpack-sync-module-posts.php index 7dee0fea..74b330f7 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-posts.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-posts.php @@ -4,7 +4,7 @@ require_once dirname( __FILE__ ) . '/class.jetpack-sync-settings.php'; class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { - private $just_published; + private $just_published = array(); public function name() { return 'posts'; @@ -29,6 +29,10 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { add_action( 'jetpack_published_post', $callable, 10, 2 ); add_action( 'transition_post_status', array( $this, 'save_published' ), 10, 3 ); add_filter( 'jetpack_sync_before_enqueue_wp_insert_post', array( $this, 'filter_blacklisted_post_types' ) ); + + // listen for meta changes + $this->init_listeners_for_meta_type( 'post', $callable ); + $this->init_meta_whitelist_handler( 'post', array( $this, 'filter_meta' ) ); } public function init_full_sync_listeners( $callable ) { @@ -90,6 +94,25 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { return $args; } + // Meta + function filter_meta( $args ) { + if ( $this->is_post_type_allowed( $args[1] ) && $this->is_whitelisted_post_meta( $args[2] ) ) { + return $args; + } + + return false; + } + + function is_whitelisted_post_meta( $meta_key ) { + // _wpas_skip_ is used by publicize + return in_array( $meta_key, Jetpack_Sync_Settings::get_setting( 'post_meta_whitelist' ) ) || wp_startswith( $meta_key, '_wpas_skip_' ); + } + + function is_post_type_allowed( $post_id ) { + $post = get_post( $post_id ); + return ! in_array( $post->post_type, Jetpack_Sync_Settings::get_setting( 'post_types_blacklist' ) ); + } + function remove_embed() { global $wp_embed; remove_filter( 'the_content', array( $wp_embed, 'run_shortcode' ), 8 ); @@ -110,7 +133,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { // Expands wp_insert_post to include filtered content function filter_post_content_and_add_links( $post_object ) { - global $post; + global $post, $shortcode_tags; $post = $post_object; // return non existant post @@ -154,14 +177,36 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { if ( 0 < strlen( $post->post_password ) ) { $post->post_password = 'auto-' . wp_generate_password( 10, false ); } - + + /** + * Filter prevents some shortcodes from expanding. + * + * Since we can can expand some type of shortcode better on the .com side and make the + * expansion more relevant to contexts. For example [galleries] and subscription emails + * + * @since 4.5.0 + * + * @param array of shortcode tags to remove. + */ + $shortcodes_to_remove = apply_filters( 'jetpack_sync_do_not_expand_shortcodes', array( 'gallery', 'slideshow' ) ); + foreach ( $shortcodes_to_remove as $shortcode ) { + if ( isset ( $shortcode_tags[ $shortcode ] ) ) { + $shortcodes_and_callbacks_to_remove[ $shortcode ] = $shortcode_tags[ $shortcode ]; + } + } + + array_map( 'remove_shortcode' , array_keys( $shortcodes_and_callbacks_to_remove ) ); + /** This filter is already documented in core. wp-includes/post-template.php */ if ( Jetpack_Sync_Settings::get_setting( 'render_filtered_content' ) && $post_type->public ) { - $post->post_content_filtered = apply_filters( 'the_content', $post->post_content ); $post->post_excerpt_filtered = apply_filters( 'the_excerpt', $post->post_excerpt ); } + foreach ( $shortcodes_and_callbacks_to_remove as $shortcode => $callback ) { + add_shortcode( $shortcode, $callback ); + } + $this->add_embed(); if ( has_post_thumbnail( $post->ID ) ) { @@ -173,24 +218,53 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { $post->permalink = get_permalink( $post->ID ); $post->shortlink = wp_get_shortlink( $post->ID ); - $post->dont_email_post_to_subs = Jetpack::is_module_active( 'subscriptions' ) ? - get_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', true ) : - true; // Don't email subscription if the subscription module is not active. return $post; } public function save_published( $new_status, $old_status, $post ) { if ( 'publish' === $new_status && 'publish' !== $old_status ) { - $this->just_published = $post->ID; + $this->just_published[] = $post->ID; } } public function send_published( $post_ID, $post, $update ) { - if ( $this->just_published === $post->ID ) { - $this->just_published = null; - $flags = apply_filters( 'jetpack_published_post_flags', array(), $post ); - do_action( 'jetpack_published_post', $post_ID, $flags ); + // Post revisions cause race conditions where this send_published add the action before the actual post gets synced + if ( wp_is_post_autosave( $post ) || wp_is_post_revision( $post ) ) { + return; + } + + if ( ! empty( $this->just_published ) && in_array( $post_ID, $this->just_published ) ) { + $published = array_reverse( array_unique( $this->just_published ) ); + + // Pre 4.7 WP does not have run though send_published for every save_published call + // So lets clear out any just_published that we recorded + foreach ( $published as $just_published_post_ID ) { + if ( $post_ID !== $just_published_post_ID ) { + $post = get_post( $just_published_post_ID ); + } + + /** + * Filter that is used to add to the post flags ( meta data ) when a post gets published + * + * @since 4.4.0 + * + * @param mixed array post flags that are added to the post + * @param mixed $post WP_POST object + */ + $flags = apply_filters( 'jetpack_published_post_flags', array(), $post ); + + /** + * Action that gets synced when a post type gets published. + * + * @since 4.4.0 + * + * @param int post_id + * @param mixed array post flags that are added to the post + */ + do_action( 'jetpack_published_post', $just_published_post_ID, $flags ); + } + $this->just_published = array(); } } @@ -203,7 +277,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { return array( $posts, - $this->get_metadata( $post_ids, 'post' ), + $this->get_metadata( $post_ids, 'post', Jetpack_Sync_Settings::get_setting( 'post_meta_whitelist' ) ), $this->get_term_relationships( $post_ids ), ); } |