10up / distributor

Share content between your websites.
https://distributorplugin.com
GNU General Public License v2.0
618 stars 156 forks source link

Gutenberg-plugin JS enqueue error for users without permission to push. #1231

Open peterwilsoncc opened 1 month ago

peterwilsoncc commented 1 month ago

Describe the bug

When a user without permission to syndicate posts visits the block editor screen, an error is thrown enqueuing the Gutenberg-plugin JavaScript as the dt-push dependency is not available.

This is caused by the is_syndicatable() check in the push-ui file preventing the registration of the dependency if it's unavailable.

https://github.com/10up/distributor/blob/0d5533154e3633a7786d46ca9f45987332489bc4/includes/push-ui.php#L407-L410

It may be possible to remove the is_syndicatable() check when enqueuing the the push UI JavaScript but the JavaScript may require the addition of a check for the user permissions.

Steps to Reproduce

  1. Add the following code to prevent pushing for all users to mu plugins
    add_filter( 'dt_syndicatable_capabilities', function() { return 'do_not_allow'; } );
  2. Enable the Query Monitor plugin
  3. Visit the post edit screen
  4. Query Monitor will report the dependency issue

Screenshots, screen recording, code snippet

Screenshot 2024-06-17 at 11 25 51 AM

Environment information

WordPress information

No response

Code of Conduct

thrijith commented 3 days ago

Hi @peterwilsoncc

If I remove the syndicatable before script enqueuing it gets rid of the error and if I login via a user who doesn't have permission to push content, the UI to push doesn't show anything https://cleanshot.thrijith.com/6h0NTlQ5gqpnjwmZ7F8D, do we need any additional checks in the JS in this case?