Wordpress plugin development - get all active widgets

I am developing a wordpress plugin that creates a widget that will act on another widget. I searched, but did not seem to find (if it exists) a hook in which all active widget instances will be indicated. any help would be appreciated if you came across this. thank

+3
source share
2 answers

get_option('sidebars_widgets') provides an associative array containing a list of widgets for each sidebar, as well as a list of all inactive widgets.

get_option('widget_widgetname') will provide you with an associative array containing the settings for all instances of your widget.

+11
source

for example, to remove a widget from a page

add_filter( 'sidebars_widgets', 'disable_widgets' );

function disable_widgets( $sidebars_widgets ) {
global $qode_options_proya;
    //print_r($sidebars_widgets);//gives a list of widgets
    if(is_admin()){return $sidebars_widgets;}
    if(get_post_meta( get_the_ID(), 'hide_allwidgets_checkbox', true )=="on"){return false; }


    if(get_post_meta( get_the_ID(), 'hide_footer', true )=="on"){unset($sidebars_widgets["footer_column_1"]);}
    if(get_post_meta( get_the_ID(), 'hide_topmenu_checkbox', true )=="on"){unset($sidebars_widgets["header_top"]); }
    return $sidebars_widgets;
}

, print_r ($ sidebars_widgets);,

0

All Articles