wordpress-seo icon indicating copy to clipboard operation
wordpress-seo copied to clipboard

Can't create or edit files when using the 'wpseo_allow_system_file_edit' to allow file editing

Open polevaultweb opened this issue 5 years ago • 3 comments

  • [x] I've read and understood the contribution guidelines.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened.

My site uses the constant DISALLOW_FILE_EDIT to stop users editing plugins. This means I can't use the File Editor in the plugin. The filter wpseo_allow_system_file_edit can be used to show the menu item - great!

However, the code that actually does the creating or editing of files only checks current_user_can( 'edit_files' ) instead of using the WPSEO_Utils::allow_system_file_edit method which uses the filter.

Please describe what you expected to happen and why.

I expect to be able to actually make edits to the files when file editing is disabled but the filter 'wpseo_allow_system_file_edit' is used to allow it.

How can we reproduce this behavior?

  1. define( 'DISALLOW_FILE_EDIT', true); in wp-config.php
  2. can't see File editor in SEO > Tools
  3. Add add_filter( 'wpseo_allow_system_file_edit', '__return_true' ); in an mu-plugin or functions.php
  4. You now see the File Editor, try to make a change, eg. create robots.txt - you will see the error "You cannot create a robots.txt file."

Technical info

  • If relevant, which editor is affected (or editors):
  • [ ] Classic Editor
  • [ ] Gutenberg
  • [ ] Classic Editor plugin
  • Which browser is affected (or browsers):
  • [ ] Chrome
  • [ ] Firefox
  • [ ] Safari
  • [ ] Other

Used versions

  • WordPress version:
  • Yoast SEO version:
  • Gutenberg plugin version:
  • Classic Editor plugin version:
  • Relevant plugins in case of a bug:
  • Tested with theme:

polevaultweb avatar Aug 22 '20 17:08 polevaultweb