Skip to content

Implementation of automatic push of a post #1317

@maxim-wla

Description

@maxim-wla

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

No one assigned

    Labels

    type:questionFurther information is requested.

    Type

    No type

    Projects

    Status

    To Do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions