distributor
distributor copied to clipboard
Is there a way to distribute on first publish rather than after?
Hi, perhaps I'm missing this but is there a way to distribute the post upon publishing? At the moment, I only see the option to after publishing. Thanks
@zsection you are correct, the Push functionality is present post-publish in the toolbar.
@zsection you could likely add code that distributed content on publish using WordPress hooks. Currently the UI also involves choosing which site(s) to distribute to, and whether to distribute as draft, you would need to handle those choices in your post publish hook.
@jeffpaul @adamsilverstein I've been attempting to work on a distribute-on-publish solution (External Connection) but have been having a hard time trying to figure out the correct order/hooks to use to get this done. Would either of you happen to have a sample or direction on where to start on this?
I believe it would be do_action( 'dt_push_post', $response, $post_body, $type_url, $post_id, $args, $this );
but some guidance would be much appreciated!
You basically need to copy/paste/edit this code https://github.com/10up/distributor/blob/develop/includes/push-ui.php#L118-L134 and execute on the WP transition_post_status
hook.
@tlovett1 thanks for the details!
@Kpudlo let us know if you run into further questions, we'd otherwise welcome a PR as you get the time!
You basically need to copy/paste/edit this code https://github.com/10up/distributor/blob/develop/includes/push-ui.php#L118-L134 and execute on the WP
transition_post_status
hook.
Would this be suitable?
--
function wpdocs_run_on_publish_only( $new_status, $old_status, $post ) {
if ( ( 'publish' === $new_status && 'publish' !== $old_status )
&& 'my-custom-post-type' === $post->post_type
) {
$connection_map = (array) get_post_meta( $post->ID, 'dt_connection_map', true );
$dom_connections = [];
if ( empty( $connection_map['external'] ) ) {
$connection_map['external'] = [];
}
if ( empty( $connection_map['internal'] ) ) {
$connection_map['internal'] = [];
}
if ( ! empty( \Distributor\Connections::factory()->get_registered()['networkblog'] ) ) {
$sites = \Distributor\InternalConnections\NetworkSiteConnection::get_available_authorized_sites( 'push' );
foreach ( $sites as $site_array ) {
if ( in_array( $post->post_type, $site_array['post_types'], true ) ) {
$connection = new \Distributor\InternalConnections\NetworkSiteConnection( $site_array['site'] );
}
}
add_action( 'transition_post_status', 'wpdocs_run_on_publish_only', 10, 3 );
@peterwilsoncc perhaps this snippet would be good to add to the developer docs site?
You basically need to copy/paste/edit this code https://github.com/10up/distributor/blob/develop/includes/push-ui.php#L118-L134 and execute on the WP
transition_post_status
hook.Would this be suitable?
--
function wpdocs_run_on_publish_only( $new_status, $old_status, $post ) { if ( ( 'publish' === $new_status && 'publish' !== $old_status ) && 'my-custom-post-type' === $post->post_type ) { $connection_map = (array) get_post_meta( $post->ID, 'dt_connection_map', true ); $dom_connections = []; if ( empty( $connection_map['external'] ) ) { $connection_map['external'] = []; } if ( empty( $connection_map['internal'] ) ) { $connection_map['internal'] = []; } if ( ! empty( \Distributor\Connections::factory()->get_registered()['networkblog'] ) ) { $sites = \Distributor\InternalConnections\NetworkSiteConnection::get_available_authorized_sites( 'push' ); foreach ( $sites as $site_array ) { if ( in_array( $post->post_type, $site_array['post_types'], true ) ) { $connection = new \Distributor\InternalConnections\NetworkSiteConnection( $site_array['site'] ); } } add_action( 'transition_post_status', 'wpdocs_run_on_publish_only', 10, 3 );
Dear Sir
Where did you added this code ?
(i removed lines 118 to 134 in push-ui.php and added above snippet , but its not working)