-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to distribute on first publish rather than after? #374
Comments
@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 |
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 |
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? |
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) |
I had the same issue, I did to manage to fix it like this. If some one still needs it :) |
Where above code should be used, is it in functions.php ? under "edit theme" |
Yes |
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
The text was updated successfully, but these errors were encountered: