Home>Support>Activate widget using register_activation_hook

Activate widget using register_activation_hook

Hi there,

I’ve been trying to automatically activate widgets – I created plugin to work with SO Widgets bundle as framework, in a way that my widgets get activated when user activate my plugin, but no luck.

I tried with instructions from here:
https://siteorigin.com/thread/enable-new-widget-by-default/, like this:

register_activation_hook(__FILE__, 'my_plugin_on_activation');
my_plugin_on_activation() {
SiteOrigin_Widgets_Bundle::single()->activate_widget('my-widget-id'); // I used proper id
}

and even with hook “siteorigin_widgets_active_widgets” (as instructed in linked thread) …

Any ideas ?

Thanks

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 8 years, 1 month ago micemade

    Hi,
    thanks for thread approval. :)
    I still have issues with register_activation_hook (I added this hook in main plugin file).
    Tried with this code (no luck):

    register_activation_hook( __FILE__, 'mm_nw_on_plugin_activation' );
    function mm_nw_on_plugin_activation() {
    	
    	add_filter('siteorigin_widgets_active_widgets', 'mm_nw_activate_widgets');
    }
    
    function mm_nw_activate_widgets( $active ){
    	// array of Micemade widget ID's
    	$mm_nw_widgets = array( 'micemade_hero','micemade_wc_catalog','micemade_wc_product','micemade_gmap','micemade_slick_slider' );
    	
    	// set each to true
    	foreach( $mm_nw_widgets as $mm_nw_w ) {
    		$active[$mm_nw_w] = true;
    	}
    	
        return $active;
    }

    so then I used simply
    add_filter(‘siteorigin_widgets_active_widgets’, ‘mm_nw_activate_widgets’); , without register hook
    but this keeps widgets activated, not possible to deactivate …

    Cheers

  2. 8 years, 1 month ago Alex S
    Hi, I Work Here

    Hi Micemade,

    Very sorry for the delay.

    I’m going to forward this to the development team.

  3. 8 years, 1 month ago micemade

    Thanks, I hope they will come up with some solution. :)

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More