Plugin Contexts

  1. Mark Jaquith
    WordPress Lead Dev


    Plugins could include an additional meta header: "Context"

    This would be a list of contexts for which the plugin should be loaded. For example:

    • blog
    • admin
    • i18n
    • comment_post
    • entry_post
    • is_single
    • is_404
    • is_search

    Just to name a few. Obviously not all of these may be technically feasible, but we provide as many as we can. We could even support context negation, so you could just list the contexts where the plugin doesn't apply. On load, we figure out which plugins apply to the context, and only load those ones.

    That frees us up to load only i18n plugins when loading internationalizezd JavaScript files, without taking the full WP load hit.

    Posted: 11 years ago #
  2. lunabyte


    For performance, it's still going to pull in the file to read the context. Maybe directory separation would be better?

    --all (loads no matter what)

    Slightly confusing to someone, perhaps, but would certainly allow for running more plugins, more efficiently since it's only going to look for plugins in certain spots.

    Posted: 11 years ago #
  3. John Blackbourn
    WordPress Core Developer


    Ace idea.

    To solve the issue of the plugin file having to be loaded to check the context, how about an additional file which is optionally included with your plugin, for example plugin-name-context.php which is a very small file which contains the meta data for the context.

    This does mean a slight change to plugin architecture, but backwards compatibility would be retained as the file would be optional. If it didn't exist then the plugin would simply be included as normal.

    The context values could not only be conditional functions such as is_home(), but also file names such as edit.php.

    An example my-plugin-context.php might be:

    Plugin Name: My Super Plugin
    Plugin Context: 'is_post', 'is_single', 'is_search', 'wp-admin/post.php'

    Negated context could simply be a context prefixed with a minus symbol, eg. '-is_search'.

    Also, why not go the whole hog and have a wildcard for file names, eg. 'wp-admin/options-*.php' which would only load the plugin for options pages.

    Posted: 11 years ago #
  4. Jeff Chandler

    Mod can add this to the Not Core status area.

    Posted: 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.

  • Rating

    102 Votes
  • Status

    This is not a core suggestion