summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/sync/class.jetpack-sync-module-posts.php')
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-posts.php53
1 files changed, 40 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 80815acb..3a5145bb 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-posts.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-posts.php
@@ -46,7 +46,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
$this->init_meta_whitelist_handler( 'post', array( $this, 'filter_meta' ) );
add_action( 'export_wp', $callable );
- add_action( 'jetpack_sync_import_end', $callable );
+ add_action( 'jetpack_sync_import_end', $callable, 10, 2 );
// Movable type, RSS, Livejournal
add_action( 'import_done', array( $this, 'sync_import_done' ) );
@@ -60,14 +60,17 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
if ( $this->import_end ) {
return;
}
+
+ $importer_name = $this->get_importer_name( $importer );
+
/**
* Sync Event that tells that the import is finished
*
* @since 5.0.0
*
- * $param string $importer
+ * $param string $importer
*/
- do_action( 'jetpack_sync_import_end', $importer );
+ do_action( 'jetpack_sync_import_end', $importer, $importer_name );
$this->import_end = true;
}
@@ -78,8 +81,8 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
}
$this->import_end = true;
- $importer = 'unknown';
- $backtrace = wp_debug_backtrace_summary(null, 0, false );
+ $importer = 'unknown';
+ $backtrace = wp_debug_backtrace_summary( null, 0, false );
if ( $this->is_importer( $backtrace, 'Blogger_Importer' ) ) {
$importer = 'blogger';
}
@@ -92,19 +95,27 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
$importer = 'wordpress';
}
+ $importer_name = $this->get_importer_name( $importer );
+
/** This filter is already documented in sync/class.jetpack-sync-module-posts.php */
- do_action( 'jetpack_sync_import_end', $importer );
+ do_action( 'jetpack_sync_import_end', $importer, $importer_name );
+ }
+
+ private function get_importer_name( $importer ) {
+ $importers = get_importers();
+ return isset( $importers[ $importer ] ) ? $importers[ $importer ][0] : 'Unknown Importer';
}
-
+
private function is_importer( $backtrace, $class_name ) {
foreach ( $backtrace as $trace ) {
if ( strpos( $trace, $class_name ) !== false ) {
return true;
}
}
+
return false;
}
-
+
public function init_full_sync_listeners( $callable ) {
add_action( 'jetpack_full_sync_posts', $callable ); // also sends post meta
}
@@ -154,7 +165,13 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
* @return array
*/
function expand_wp_insert_post( $args ) {
- return array( $args[0], $this->filter_post_content_and_add_links( $args[1] ), $args[2], $args[3] );
+ $post_id = $args[0];
+ $post = $args[1];
+ $update = $args[2];
+ $is_auto_save = isset( $args[3] ) ? $args[3] : false; //See https://github.com/Automattic/jetpack/issues/7372
+ $just_published = isset( $args[4] ) ? $args[4] : false; //Preventative in light of above issue
+
+ return array( $post_id, $this->filter_post_content_and_add_links( $post ), $update, $is_auto_save, $just_published );
}
function filter_blacklisted_post_types( $args ) {
@@ -311,7 +328,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
}
}
- public function wp_insert_post( $post_ID, $post = null , $update = null ) {
+ public function wp_insert_post( $post_ID, $post = null, $update = null ) {
if ( ! is_numeric( $post_ID ) || is_null( $post ) ) {
return;
}
@@ -322,7 +339,13 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
$is_auto_save = false;
}
- call_user_func( $this->action_handler, $post_ID, $post, $update, $is_auto_save );
+ if ( ! in_array( $post_ID, $this->just_published ) ) {
+ $just_published = false;
+ } else {
+ $just_published = true;
+ }
+
+ call_user_func( $this->action_handler, $post_ID, $post, $update, $is_auto_save, $just_published );
$this->send_published( $post_ID, $post );
$this->send_trashed( $post_ID, $post );
}
@@ -337,6 +360,10 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
return;
}
+ $post_flags = array(
+ 'post_type' => $post->post_type
+ );
+
/**
* Filter that is used to add to the post flags ( meta data ) when a post gets published
*
@@ -345,7 +372,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
* @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 );
+ $flags = apply_filters( 'jetpack_published_post_flags', $post_flags, $post );
/**
* Action that gets synced when a post type gets published.
@@ -377,7 +404,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
*
* @param int $post_ID
*/
- do_action( 'jetpack_trashed_post', $post_ID );
+ do_action( 'jetpack_trashed_post', $post_ID, $post->post_type );
$this->just_trashed = array_diff( $this->just_trashed, array( $post_ID ) );
}