From 565acba197961407a1930d0cd4f03ba72f4a20ee Mon Sep 17 00:00:00 2001
From: Mohammad Jangda <batmoo@gmail.com>
Date: Wed, 16 Oct 2013 06:08:41 +0000
Subject: [PATCH] Make the push_post command more verbose

see #38
---
 includes/class-wp-cli.php                     | 25 +++++++++++++++++++
 includes/class-wp-push-syndication-server.php |  2 ++
 2 files changed, 27 insertions(+)

diff --git a/includes/class-wp-cli.php b/includes/class-wp-cli.php
index 708c5a5..3270f82 100644
--- a/includes/class-wp-cli.php
+++ b/includes/class-wp-cli.php
@@ -16,6 +16,8 @@ class Syndication_CLI_Command extends WP_CLI_Command {
 			WP_CLI::error( __( 'Invalid post_id', 'push-syndication' ) );
 		}
 
+		$this->_make_em_talk_push();
+
 		$server = $this->_get_syndication_server();
 		$sites = $server->get_sites_by_post_ID( $post_id );
 
@@ -86,6 +88,29 @@ class Syndication_CLI_Command extends WP_CLI_Command {
 		}, 10, 5 );
 	}
 
+	private function _make_em_talk_push() {
+		if ( $this->enabled_verbosity )
+			return;
+
+		$this->enabled_verbosity = true;
+		
+		add_filter( 'syn_pre_push_post_sites', function( $sites, $post_id, $slave_states ) {
+			WP_CLI::line( sprintf( "Processing post_id #%d (%s)", $post_id, get_the_title( $post_id ) ) );
+			WP_CLI::line( sprintf( "-- pushing to %s sites and deleting from %s sites", number_format( count( $sites['selected_sites'] ) ), number_format( count( $sites['removed_sites'] ) ) ) );
+
+			return $sites;
+		}, 10, 3 );
+
+		add_action( 'syn_post_push_new_post', function( $result, $post_ID, $site, $transport_type, $client, $info ) {
+			WP_CLI::line( sprintf( '-- Added remote post #%d (%s)', $post_ID, $site->post_title ) );
+		}, 10, 6 );
+
+		add_action( 'syn_post_push_edit_post', function( $result, $post_ID, $site, $transport_type, $client, $info ) {
+			WP_CLI::line( sprintf( '-- Updated remote post #%d (%s)', $post_ID, $site->post_title ) );
+		}, 10, 6 );
+
+	}
+
 	private function _get_syndication_server() {
 		global $push_syndication_server;
 		return $push_syndication_server;
diff --git a/includes/class-wp-push-syndication-server.php b/includes/class-wp-push-syndication-server.php
index c661f20..40c35ee 100644
--- a/includes/class-wp-push-syndication-server.php
+++ b/includes/class-wp-push-syndication-server.php
@@ -835,6 +835,8 @@ class WP_Push_Syndication_Server {
 		$slave_post_states = get_post_meta( $post_ID, '_syn_slave_post_states', true );
 		$slave_post_states = !empty( $slave_post_states ) ? $slave_post_states : array() ;
 
+		$sites = apply_filters( 'syn_pre_push_post_sites', $sites, $post_ID, $slave_post_states );
+
 		if( !empty( $sites['selected_sites'] ) ) {
 
 			foreach( $sites['selected_sites'] as $site ) {
-- 
GitLab