diff --git a/includes/classes/ExternalConnections/WordPressExternalConnection.php b/includes/classes/ExternalConnections/WordPressExternalConnection.php index b6cb7cfd3..9618db053 100644 --- a/includes/classes/ExternalConnections/WordPressExternalConnection.php +++ b/includes/classes/ExternalConnections/WordPressExternalConnection.php @@ -489,6 +489,23 @@ public function push( $post, $args = array() ) { $post_type = $dt_post->get_post_type(); $path = self::$namespace; + /** + * Allow bypassing of external post distribution. + * + * @hook dt_should_push_external_post + * + * @param {bool} true If Distributor should push the post. + * @param {WP_Post} $post The post object. + * @param {array} $args The arguments passed into wp_insert_post(). + * @param {WordPressExternalConnection} $this The Distributor connection being pushed to. + * + * @return {bool} If Distributor should push the post. + */ + $should_push = apply_filters( 'dt_should_push_external_post', true, $post, $args, $this ); + if ( ! $should_push ) { + return new \WP_Error( 'post-not-allowed-to-push', esc_html__( 'Post is configured to not be pushed via dt_should_push_external_post filter.', 'distributor' ) ); + } + /* * First let's get the actual route. We don't know the "plural" of our post type */ diff --git a/includes/classes/InternalConnections/NetworkSiteConnection.php b/includes/classes/InternalConnections/NetworkSiteConnection.php index ee5034565..4c5c0e700 100644 --- a/includes/classes/InternalConnections/NetworkSiteConnection.php +++ b/includes/classes/InternalConnections/NetworkSiteConnection.php @@ -81,6 +81,23 @@ public function push( $post, $args = array() ) { } $post_id = $post->ID; + /** + * Allow bypassing of post distribution. + * + * @hook dt_should_push_network_post + * + * @param {bool} true If Distributor should push the post. + * @param {WP_Post} $post The post object. + * @param {array} $args The arguments passed into wp_insert_post(). + * @param {NetworkSiteConnection} $this The Distributor connection being pushed to. + * + * @return {bool} If Distributor should push the post. + */ + $should_push = apply_filters( 'dt_should_push_network_post', true, $post, $args, $this ); + if ( ! $should_push ) { + return new \WP_Error( 'post-not-allowed-to-push', esc_html__( 'Post is configured to not be pushed via dt_should_push_network_post filter.', 'distributor' ) ); + } + $args = wp_parse_args( $args, array(