distributor icon indicating copy to clipboard operation
distributor copied to clipboard

Not use / check for the logged in user when pushing and mapping while on WP-CLI

Open jmslbam opened this issue 3 years ago • 0 comments

Is your enhancement related to a problem? Please describe. I'm pushing post via WP-CLI from 1 site to other sites via a InternalConnection (multisite)

I noticed that it didn't work properly because of this line where it check on a user capability

https://github.com/10up/distributor/blob/develop/includes/classes/InternalConnections/NetworkSiteConnection.php#L623 ! current_user_can( 'edit_post', $post_id )

So I added wp bvdb-resave run --user=1 to let WP-CLI know we are logged in, and so passing the current_user_can check. Describe the solution you'd like Are you open to added a check for the WP_CLI constant? so it does pass this check and you don't need to run WP-CLI in a logged in state, because doing that kills performance.

Designs ...

Describe alternatives you've considered Passing --user=1

Additional context I saw that there were some other place in the Internal connection where get_current_user_id would get used. get_available_authorized_sites could be set to all when you are a on WP-CLI. https://github.com/10up/distributor/blob/develop/includes/classes/InternalConnections/NetworkSiteConnection.php#L702 I don't have a clear vision on build_available_authorized_sites, but I don't think this needs to be rewritten because you can return early in get_available_authorized_sites when you are on WP-CLI.

get_current_user_id used as fallback for the post_author in the push method is ok. One could add a check around the value if you are on WP-CLI and if the passed post_author is empty and you're not logged in, then you could trigger a noticed and keep it on 0 which get_current_user_id returns. Or skip pushing it when it's 0. https://github.com/10up/distributor/blob/develop/includes/classes/InternalConnections/NetworkSiteConnection.php#L78

I know this can be a mayor speed improvement will bulk processing posts from the terminal via WP-CLI. Just wanted to check if I'm on the correct track with my Thought Train :) and if you would be open to it.

jmslbam avatar Apr 27 '21 09:04 jmslbam