WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/26/2009 08:09:08 PM (13 years ago)
Author:
azaozz
Message:

Move recent comments widget to WP_Widget, extend is_active_widget() to use $id_base, see #8441

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/widgets.php

    r11088 r11090  
    784784
    785785/**
    786  * Whether widget is registered using callback with widget ID.
    787  *
    788  * Without the optional $widget_id parameter, returns the ID of the first sidebar in which the first instance of the widget with the given callback is found.
    789  * With the $widget_id parameter, returns the ID of the sidebar in which the widget with that callback AND that ID is found.
    790  *
    791  * @since 2.2.0
    792  *
    793  * @param callback $callback Widget callback to check.
     786 * Whether widget is displayied on the front-end.
     787 *
     788 * Either $callback or $id_base can be used
     789 * $id_base is the first argument when extending WP_Widget class
     790 * Without the optional $widget_id parameter, returns the ID of the first sidebar
     791 * in which the first instance of the widget with the given callback or $id_base is found.
     792 * With the $widget_id parameter, returns the ID of the sidebar where
     793 * the widget with that callback/$id_base AND that ID is found.
     794 *
     795 * NOTE: $widget_id and $id_base are the same for single widgets. To be effective
     796 * this function has to run after widgets have initialized, at action 'init' or later.
     797 *
     798 * @since 2.2.0
     799 *
     800 * @param callback Optional, Widget callback to check.
    794801 * @param int $widget_id Optional, but needed for checking. Widget ID.
    795 /* @return mixed false if widget is not active or id of sidebar in which the widget is active.
    796  */
    797 function is_active_widget($callback, $widget_id = false) {
     802 * @param string $id_base Optional, the base ID of a widget created by extending WP_Widget.
     803 * @return mixed false if widget is not active or id of sidebar in which the widget is active.
     804 */
     805function is_active_widget($callback = false, $widget_id = false, $id_base = false) {
    798806    global $wp_registered_widgets;
    799807
     
    801809
    802810    if ( is_array($sidebars_widgets) ) foreach ( $sidebars_widgets as $sidebar => $widgets )
     811        if ( 'wp_inactive_widgets' == $sidebar )
     812            continue;
     813
    803814        if ( is_array($widgets) ) foreach ( $widgets as $widget )
    804             if ( isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback )
     815            if ( ( $callback && isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback ) || ( $id_base && preg_replace( '/-[0-9]+$/', '', $widget ) == $id_base ) ) {
    805816                if ( !$widget_id || $widget_id == $wp_registered_widgets[$widget]['id'] )
    806817                    return $sidebar;
    807 
     818            }
    808819
    809820    return false;
Note: See TracChangeset for help on using the changeset viewer.