Skip to content

@markoheijnen /gist:3110599
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Register widgets to a sidebar by code
<?php
class Rockstars_Widget {
private $custom_settings = array();
public function register_default_widget( $sidebar, $class_name, $settings ) {
global $_wp_sidebars_widgets, $wp_widget_factory;
if( empty( $_wp_sidebars_widgets[ $sidebar ] ) ) {
if( isset( $wp_widget_factory->widgets[ $class_name ] ) ) {
$class = $wp_widget_factory->widgets[ $class_name ];
if( ! isset( $this->custom_settings[ $class->option_name ] ) ) {
$this->custom_settings[ $class->option_name ] = array();
add_filter( 'option_' . $class->option_name, array( $this, '_register_default_widgets_settings' ) );
}
$id = 900 + count( $this->custom_settings[ $class->option_name ] );
$this->custom_settings[ $class->option_name ][ $id ] = $settings;
$_wp_sidebars_widgets[ $sidebar ][] = $class->id_base . '-' . $id;
return true;
}
}
return false;
}
function _register_default_widgets_settings( $value ) {
$filter = substr( current_filter(), 7);
if( isset( $this->custom_settings[ $filter ] ) )
$value = $value + $this->custom_settings[ $filter ];
return $value;
}
}
$GLOBALS['rockstars_widget'] = new Rockstars_Widget();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.