WordPress.org

Make WordPress Core

Opened 21 months ago

Closed 2 months ago

#21412 closed enhancement (maybelater)

Hookable dropins

Reported by: mikeschinkel Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Cache API Keywords: has-patch dev-feedback
Focuses: Cc:

Description

This ticket is the result of a discussion on the wp-hackers list where I proposed the idea in this message.

Currently for dropins there can be only one[1] per install which means that, especially for advanced-cache.php where multiple plugins cannot easily:

  • Cache different mime types with different plugins
  • Provide basic functionality and leave the complexity to other plugins because hooks are not available (this is likely needed for a good page caching API to ever emerge from the work of plugins.)

For caching this results in plugins like WP Super Cache and WP Total Cache that significantly violate a sancrosact WordPress philosophy of "Decisions, not Options". To see what I mean, just visit the settings page for either of these plugins. (Note: I'm not criticizing the plugins or their developers, instead saying that WordPress doesn't give them much of a choice.)

It turns out however that fixing this is really lightweight and easy, at least for advanced-cache.php. I will attach the following files but here is the short list of changes to core required:

  • Move the hooks-related function out of /wp-includes/plugin.php into another file which I called /wp-includes/hooks.php and include /wp-includes/hooks.php in /wp-settings.php close to the top after /wp-includes/versions.php is included.
  • Include another new file /wp-includes/dropsin.php in /wp-settings.php after /wp-includes/hooks.php which contains a wp_load_dropins() function that include()s all .php files found in /wp-includes/dropins/.
  • Lastly add the following two (2) lines before advanced-cache.php is included:
// Load any potential dropins found /wp-content/dropins/
wp_load_dropins();

// Run the hook-based page cache.
do_action( 'page_cache' );

With this future caching plugins can implement the page_cache hook by dropping a file into /wp-content/cache/ instead of adding an /wp-content/advanced-cache.php.

If this idea is blessed then we could add a deprecation notice for /wp-content/advanced-cache.php and also potentially replace (some of) the other dropins with do_actions( "{$dropin_hook}" ).

[1] Gratuitous Highlander reference.

Attachments (3)

hookable-dropins.diff (21.6 KB) - added by mikeschinkel 21 months ago.
hookable-dropins.diff
hooks.php (19.7 KB) - added by mikeschinkel 21 months ago.
hooks.php which contains the files moved out of plugin.php.
dropins.php (435 bytes) - added by mikeschinkel 21 months ago.
dropins.php - To enable loading .php files from /wp-content/dropins/

Download all attachments as: .zip

Change History (12)

mikeschinkel21 months ago

hookable-dropins.diff

mikeschinkel21 months ago

hooks.php which contains the files moved out of plugin.php.

mikeschinkel21 months ago

dropins.php - To enable loading .php files from /wp-content/dropins/

comment:2 ashfame21 months ago

  • Cc ashishsainiashfame@… added

comment:3 kurtpayne21 months ago

  • Cc kpayne@… added

comment:4 follow-up: scribu21 months ago

Move the hooks-related function out of /wp-includes/plugin.php into another file which I called /wp-includes/hooks.php

If you do that, the plugin.php file is left with just a handful of functions (198 lines, mostly docs).

comment:5 hsatterwhite21 months ago

  • Cc whsatterwhite@… added

comment:6 beaulebens21 months ago

  • Cc beau@… added

comment:7 in reply to: ↑ 4 mikeschinkel21 months ago

Replying to scribu:

If you do that, the plugin.php file is left with just a handful of functions (198 lines, mostly docs).

So what's your suggestion, just move where plugin.php is included?

comment:8 DH-Shredder21 months ago

  • Cc mike.schroder@… added

comment:9 wonderboymusic2 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

19 months of silence. Most people just alter advanced-cache.php to suit their needs. Most widely-used dropins change infrequently and are flexible enough to allow changes without causing painful merges when a new version is released.

Note: See TracTickets for help on using tickets.