Skip to content

Commit

Permalink
Create fallback for get site options on sub sites that do not have va…
Browse files Browse the repository at this point in the history
…lues set for host or index name this fixes #25. Change post transition detection for posts transitioning OUT of publish status - delete these posts from the index - this fixes #21.
  • Loading branch information
Aaron Holbrook committed Jun 27, 2014
1 parent 0f48731 commit 1463593
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
12 changes: 11 additions & 1 deletion classes/class-ep-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ public function get_option( $site_id = null ) {
$site_id = get_current_blog_id();
}

if ( isset( $option[$site_id] ) ) {
if ( isset( $option[ $site_id ] ) ) {
// Fallback to main host info if sub site doesn't exist
if ( empty( $option[ $site_id ]['host'] ) ) {
$option[ $site_id ]['host'] = $option[0]['host'];
}

// Fallback to main index_name if sub site doesn't exist
if ( empty( $option[ $site_id ]['index_name'] ) ) {
$option[ $site_id ]['index_name'] = $option[0]['index_name'];
}

return $option[$site_id];
} else {
if ( $site_id === 0 ) {
Expand Down
39 changes: 22 additions & 17 deletions classes/class-ep-sync-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,34 @@ public function action_trash_post( $post_id ) {
* @since 0.1.0
*/
public function action_sync_on_transition( $new_status, $old_status, $post ) {
if ( 'publish' != $new_status ) {
return;
}

if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! current_user_can( 'edit_post', $post->ID ) || 'revision' == get_post_type( $post->ID ) ) {
return;
}
if ( 'publish' === $new_status || 'publish' === $old_status) {
// Either the post is now published or it is no longer published, either way we need to do something

$site_config = ep_get_option();
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! current_user_can( 'edit_post', $post->ID ) || 'revision' == get_post_type( $post->ID ) ) {
return;
}

$post_type = get_post_type( $post->ID );
$site_config = ep_get_option();

if ( in_array( $post_type, $site_config['post_types'] ) ) {
// If post type is supposed to be sync, let's sync this post
$post_type = get_post_type( $post->ID );

$global_config = ep_get_option( 0 );
$host_site_id = null;
if ( ! empty( $global_config['cross_site_search_active'] ) ) {
$host_site_id = 0;
}
if ( in_array( $post_type, $site_config['post_types'] ) ) {
// If post type is supposed to be synced then we can proceed
if ( 'publish' === $new_status ) {
// This post is now a published post, let's sync this post

$this->sync_post( $post->ID, null, $host_site_id );
$global_config = ep_get_option( 0 );
$host_site_id = null;
if ( ! empty( $global_config['cross_site_search_active'] ) ) {
$host_site_id = 0;
}

$this->sync_post( $post->ID, null, $host_site_id );
} else {
// This post is no longer a published post, delete it from the index
$this->action_trash_post( $post->ID );
}
}
}
}

Expand Down

0 comments on commit 1463593

Please sign in to comment.