kasparsd / widget-context-wporg

Widget Context for WordPress
https://widgetcontext.com
Other
42 stars 13 forks source link

New filters so that other plugins can override widget context visibility checks #8

Closed thejamescollins closed 11 years ago

thejamescollins commented 11 years ago

Example use case:

A user might like the 'single post' checkbox to only apply to posts (and not other custom post types).

Currently it would apply to any custom post type.

With these new filters, the default behaviour doesn't change.

However following code could be used in another plugin to implement the above logic:

function widget_context_currently_override( $currently ) {

    if( empty( $currently ) ) {
        return $currently;
    }

    if ( isset($currently['is_single']) && $currently['is_single'] && 'post' !== get_post_type() ) {
        // Ensure the widget doesn't display for other post types
        unset($currently['is_single']);
    }

    return $currently;
}
add_filter( 'widget_context_currently', 'widget_context_currently_override' );
thejamescollins commented 11 years ago

@kasparsd, the proposed changes above don't change the existing behaviour in the plugin, but they make the plugin more flexible by allowing other plugins to implement their own custom display logic.

Please let me know what you think when you have a chance.

thejamescollins commented 11 years ago

Related: http://wordpress.org/support/topic/custom-post-types-support-2?replies=1