[wp-trac] [WordPress Trac] #30947: wp-includes files should not contain hooks

WordPress Trac noreply at wordpress.org
Thu Jan 8 04:36:07 UTC 2015


#30947: wp-includes files should not contain hooks
----------------------------+-----------------------
 Reporter:  wonderboymusic  |      Owner:
     Type:  enhancement     |     Status:  new
 Priority:  normal          |  Milestone:  4.2
Component:  General         |    Version:  trunk
 Severity:  normal          |   Keywords:  has-patch
  Focuses:                  |
----------------------------+-----------------------
 It is general good practice to have 2 types of PHP files: those that
 declare symbols, and those that cause side effects (vars, functions calls,
 class invocations, includes, etc).

 There are some random `add_action()` and `add_filter()` calls littered
 around some files in `wp-includes/`. These should be moved to `wp-includes
 /default-filters.php` with the rest of the registered hooks. It seems like
 this was the best practice for awhile and then we randomly stopped. This
 file loads way before any of the includes, so the hooks will be registered
 for any request that loads WordPress, even `SHORTINIT` - a lot of the
 hooks registered won't run anyways (that's already the case).

 I made sure the hooks are in the same order - corresponding to the order
 their files load.

 Almost all static analysis tools + `hackificator` (see Hack) complain
 about this. Also a requirement of PSR-2, which I know we don't care about,
 but doesn't hurt.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30947>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list