is_active_widget example

require_once ABSPATH . 'wp-admin/includes/widgets.php'; // For next_widget_id_number().
        $sort = $wp_registered_widgets;
        usort( $sort, array( $this, '_sort_name_callback' ) );
        $done = array();

        foreach ( $sort as $widget ) {
            if ( in_array( $widget['callback']$done, true ) ) { // We already showed this multi-widget.                 continue;
            }

            $sidebar = is_active_widget( $widget['callback']$widget['id'], false, false );
            $done[]  = $widget['callback'];

            if ( ! isset( $widget['params'][0] ) ) {
                $widget['params'][0] = array();
            }

            $available_widget = $widget;
            unset( $available_widget['callback'] ); // Not serializable to JSON.
            $args = array(
                'widget_id'   => $widget['id'],
                

    public function __construct() {
        $widget_ops = array(
            'classname'                   => 'widget_recent_comments',
            'description'                 => __( 'Your site’s most recent comments.' ),
            'customize_selective_refresh' => true,
            'show_instance_in_rest'       => true,
        );
        parent::__construct( 'recent-comments', __( 'Recent Comments' )$widget_ops );
        $this->alt_option_name = 'widget_recent_comments';

        if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) {
            add_action( 'wp_head', array( $this, 'recent_comments_style' ) );
        }
    }

    /** * Outputs the default styles for the Recent Comments widget. * * @since 2.8.0 */
    public function recent_comments_style() {
        /** * Filters the Recent Comments default widget styles. * * @since 3.1.0 * * @param bool $active Whether the widget is active. Default true. * @param string $id_base The widget ID. */
global $wp_registered_widgets$wp_registered_widget_controls;

    $sort = $wp_registered_widgets;
    usort( $sort, '_sort_name_callback' );
    $done = array();

    foreach ( $sort as $widget ) {
        if ( in_array( $widget['callback']$done, true ) ) { // We already showed this multi-widget.             continue;
        }

        $sidebar = is_active_widget( $widget['callback']$widget['id'], false, false );
        $done[]  = $widget['callback'];

        if ( ! isset( $widget['params'][0] ) ) {
            $widget['params'][0] = array();
        }

        $args = array(
            'widget_id'   => $widget['id'],
            'widget_name' => $widget['name'],
            '_display'    => 'template',
        );

        
class Akismet_Widget extends WP_Widget {

    function __construct() {
        load_plugin_textdomain( 'akismet' );
        
        parent::__construct(
            'akismet_widget',
            __( 'Akismet Widget' , 'akismet'),
            array( 'description' => __( 'Display the number of spam comments Akismet has caught' , 'akismet') )
        );

        if ( is_active_widget( false, false, $this->id_base ) ) {
            add_action( 'wp_head', array( $this, 'css' ) );
        }
    }

    function css() {
?> <style type="text/css"> .a-stats { width: auto; } .a-stats a { background: #7CA821; background-image:-moz-linear-gradient(0% 100% 90deg,#5F8E14,#7CA821); background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#7CA821),to(#5F8E14)); border: 1px solid #5F8E14; border-radius:3px; color: #CFEA93; cursor: pointer; display: block; font-weight: normal; height: 100%; -moz-border-radius:3px; padding: 7px 0 8px; text-align: center; text-decoration: none; -webkit-border-radius:3px; width: 100%; } .a-stats a:hover { text-decoration: none; background-image:-moz-linear-gradient(0% 100% 90deg,#6F9C1B,#659417); background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#659417),to(#6F9C1B)); } .a-stats .count { color: #FFF; display: block; font-size: 15px; line-height: 16px; padding: 0 13px; white-space: nowrap; } </style>
Home | Imprint | This part of the site doesn't use cookies.