Make WordPress Core

Opened 13 years ago

Closed 11 years ago

#21412 closed enhancement (maybelater)

Hookable dropins

Reported by: mikeschinkel's profile 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 13 years ago.
hookable-dropins.diff
hooks.php (19.7 KB) - added by mikeschinkel 13 years ago.
hooks.php which contains the files moved out of plugin.php.
dropins.php (435 bytes) - added by mikeschinkel 13 years ago.
dropins.php - To enable loading .php files from /wp-content/dropins/

Download all attachments as: .zip

Change History (12)

@mikeschinkel
13 years ago

hookable-dropins.diff

@mikeschinkel
13 years ago

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

@mikeschinkel
13 years ago

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

#2 @ashfame
13 years ago

  • Cc ashishsainiashfame@… added

#3 @kurtpayne
13 years ago

  • Cc kpayne@… added

#4 follow-up: @scribu
13 years 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).

#5 @hsatterwhite
13 years ago

  • Cc whsatterwhite@… added

#6 @beaulebens
13 years ago

  • Cc beau@… added

#7 in reply to: ↑ 4 @mikeschinkel
13 years 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?

#8 @kirasong
13 years ago

  • Cc mike.schroder@… added

#9 @wonderboymusic
11 years 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.