Conversation
32adb91 to
1b9dda1
Compare
faisal-alvi
left a comment
There was a problem hiding this comment.
@peterwilsoncc Thanks so much for the work on this!
I tested the feature locally and noticed that two copies are created when a post is auto-distributed. I assume only one copy should be created. Could you please take a look?
I’ve also shared a couple of additional points below for your consideration.
Lastly, it might be helpful to add some test coverage for this feature to ensure long-term stability.
| * @param integer $user_id User ID. | ||
| * @return array | ||
| */ | ||
| function get_connections( $post_id = 0, $user_id = 0 ) { |
There was a problem hiding this comment.
Just wondering – do we already have some of these common functions in a helper class or utility file that we could leverage here? That might help keep things consistent and reusable.
Same question for the other functions added below, like get_external_connections and get_internal_connections.
There was a problem hiding this comment.
We have similar code in Distributor\PushUI\get_connections() that is behind a nonce and capability check, so not appropriate in this instance as it needs to run on cron.
Do you want me to see if I can share the functionality between this and the admin-ajax endpoint and move this to the utils namespace?
There was a problem hiding this comment.
Yeah, if you believe separating those common functions and moving them to the utils namespace would be beneficial for future enhancements (and it does not require too much efforts), then we should go ahead with that. Otherwise, I’m also fine keeping it as is for now; happy to go with your judgment on this.
|
@faisal-alvi I'm not seeing the double posting. Is there any chance you have a site on a multisite instance set up as both an internal and external connection? I'll try to figure out how to test this as the unit tests use mocks. I'll check the reliability of wp-cron in wp-env. |
|
@peterwilsoncc Regarding the double posting: I have a multisite setup (subdirectory structure) with one main site and one subsite. I had set up an external connection from the subsite by adding the main site URL; that was the only external connection configured. However, it seems that in a multisite network, the sites are already internally connected by default, and we might not need to set up an external connection manually. Is that correct? When I published a post from the subsite, two copies were auto-distributed to the main site. But when I removed the external connection and tested again, only one copy was distributed; so it looks like the feature works as expected, and the duplicate was likely due to the external + internal connection both being active. If my assumption is correct that sites in a multisite are automatically connected internally, could you clarify how we can limit distribution to specific subsites, rather than distributing to all? As for the tests, I’d lean towards adding an E2E test rather than a PHP unit test. If you think it’s feasible and worth the effort, then I think adding an E2E test would be a solid approach. |
dkotter
left a comment
There was a problem hiding this comment.
Overall this looks good to me, noting Faisal has a number of comments he's already added. One thing that may be nice to add is a filter around the connections, making it easier to remove some of those from auto-distribution. Right now you can filter the posts that get auto-distributed and the post types that get auto-distributed but not seeing an easy way to filter the connections that get auto-distributed to
@faisal-alvi Yes, that's correct. Without auto-distribution it's fine to do so but with auto-distribution it will cause the double posting you're seeing. I'll have to figure out how to handle this in the tests.
@dkotter I was thinking a developer might be able to use the same filter for the purpose: add_filter( 'dt_auto_distribute_post', 'no_external', 10, 4 );
function no_external( $should_distribute, $post, $user_id, $connection_type ) {
if ( $connection_type === 'external' ) {
return false;
}
return $should_distribute;
}Is that adequate or would you prefer another filter so we can bypass the relevant code in |
Yeah, I think that works fine. Probably worth adding this to our documentation snippets |
|
@peterwilsoncc thoughts on looking to cover #1317 here as well? |
|
@peterwilsoncc Is there anything else you were wanting to change/add here or is this good for merge? |
I pushed 2dbe340 as a one final thing: it modifies when the auto-distribution setup runs to wait until Otherwise, I'm happy if you are. |
Description of the Change
Allows developers to enable auto-distribution of posts via the use of a filter.
Todo:
draftCloses #456
How to test the Change
add_filter( 'dt_auto_distribution_enabled', '__return_true' );add_filter( 'dt_auto_distribution_default_status', function() { return 'draft'; } );Changelog Entry
Credits
Props @peterwilsoncc
Checklist: