[wp-trac] [WordPress Trac] #39766: Plugin does not gracefully fail when editing active plugin causes fatal error

WordPress Trac noreply at wordpress.org
Thu Sep 21 19:30:42 UTC 2017


#39766: Plugin does not gracefully fail when editing active plugin causes fatal
error
-------------------------------------+-----------------------------
 Reporter:  ovann86                  |       Owner:  westonruter
     Type:  defect (bug)             |      Status:  accepted
 Priority:  high                     |   Milestone:  4.9
Component:  Plugins                  |     Version:  4.7.2
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:  administration
-------------------------------------+-----------------------------
Changes (by westonruter):

 * keywords:  needs-patch => has-patch needs-testing
 * owner:   => westonruter
 * status:  new => accepted


Comment:

 I believe I've found the problem and have a solution. It's PHP's opcache
 that is indeed causing the problem. The solution here seems to simply be
 to call `opcache_invalidate()` on the file right after it is written.

 I also noticed a two problems with catching fatal errors when editing a
 plugin's file other than the main one, in particular editing
 `akismet/class.akismet-admin.php` instead of `akismet/admin.php`:

 1. Since `akismet/class.akismet-admin.php` only gets included in the
 admin, the fatal error would not get raised when attempted sandbox
 activation. The solution here is simply to define `WP_ADMIN` and trigger
 the `init` and `admin_init` actions, as well as any other key actions that
 plugins would hook into during loading.
 2. With 1 fixed, when you are taken back to the plugin editor after trying
 to save an error causing the plugin to get deactivated, only the `file`
 param is provided and the plugin editor assumed the `plugin` was the
 `file` if the `plugin` param was absent. So when you tried to re-save the
 file to re-activate the plugin, then WordPress would complain about the
 plugin not having a file editor, because for example it incorrectly
 identified `akismet/class.akismet-admin.php` as the plugin file. The fix
 here is just to try to look up the plugin for a given file.

 Lastly, in the case of trying to save with a file with errors in it, the
 resulting notice about the plugin being deactivated strangely had a green
 success `updated` style as opposed to an `error` style.

 These issues are addressed in [attachment:39766.0.diff].

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39766#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list