-
Notifications
You must be signed in to change notification settings - Fork 158
Open
Labels
type:questionFurther information is requested.Further information is requested.
Milestone
Description
Describe your question
I am trying to implement automatic push of a post from one site to another when publishing it, I use external connection from the Distributor plugin. I get a connection, then all the sites that are connected and I try to push a post to a specific site, but I can't do it. Can you tell me if this is really possible to implement and if so, how can I do it? Thanks
add_action( 'save_post_products', 'auto_distribute_product_on_save', 99, 3 );
public function auto_distribute_product_on_save( $post_id, $post, $update ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( wp_is_post_revision( $post_id ) ) return;
if ( ! class_exists( '\Distributor\Connections' ) ) return;
$factory = Connections::factory();
$registered = $factory->get_registered( 'external' );
if(!empty($registered['networkblog'])){
$blogs = get_sites();
$current_site = get_current_site();
foreach ($blogs as $blog){
if($blog->id !== $current_site->id){
$network_connection = new $registered['networkblog']($blog);
if(method_exists($network_connection, 'push')){
$res = $network_connection->push($post);
}
}
}
}
}
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
type:questionFurther information is requested.Further information is requested.
Type
Projects
Status
To Do