Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run NetworkSiteConnection::update_syndicated on correct hook when using Gutenberg #518

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions includes/classes/InternalConnections/NetworkSiteConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,12 @@ public static function connect_syndicated_on_untrash( $post_id ) {
/**
* Update syndicated post when original changes
*
* @param int $post_id Post ID.
* @param int|WP_Post $post Post ID or WP_Post
* depending on which action the method is hooked to.
*/
public static function update_syndicated( $post_id ) {
public static function update_syndicated( $post ) {
$post = get_post( $post );
$post_id = $post->ID;
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || wp_is_post_revision( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
Expand All @@ -584,6 +587,12 @@ public static function update_syndicated( $post_id ) {
return;
}

// If using Gutenberg, short circuit early and run this method later to make sure terms and meta are saved before syndicating.
if ( \Distributor\Utils\is_using_gutenberg( $post ) && doing_action( 'save_post' ) && ! isset( $_GET['meta-box-loader'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
add_action( "rest_after_insert_{$post->post_type}", array( '\Distributor\InternalConnections\NetworkSiteConnection', 'update_syndicated' ) );
return;
}

$connection_map = get_post_meta( $post_id, 'dt_connection_map', true );

if ( empty( $connection_map ) || ! is_array( $connection_map ) || empty( $connection_map['internal'] ) ) {
Expand Down