WordPress.org

Ready to get started?Download WordPress

Forums

Magazine Basic
Suggestion for pbt_widgets_init (1 post)

  1. ruslanbes
    Member
    Posted 2 years ago #

    Hi,
    I had a problem with a pbt_widgets_init function in functions.php:

    add_action( 'widgets_init', 'pbt_widgets_init' );
    
    function pbt_widgets_init() {
    	wp_register_script( 'effects', THEME_URL . '/js/effects.js', array( 'jquery' ), '', true );
    
    	// include the widgets
    	include( THEME_TEMPLATE . '/widgets/widget_login.php' );
    	include( THEME_TEMPLATE . '/widgets/widget_feature.php' ); 
    
    	// Initiating the sidebars
    	register_sidebar( array(
    		'name' => 'Sidebar One',
    		'before_widget' => '<div id="%1$s" class="side-widget %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h2>',
    		'after_title' => '</h2>',
    	) );
    
    	if ( 0 != pbt_theme_option( 'sidebar_width2' ) ) {
    		register_sidebar( array(
    			'name' => 'Sidebar Two',
    			'before_widget' => '<div id="%1$s" class="side-widget %2$s">',
    			'after_widget' => '</div>',
    			'before_title' => '<h2>',
    			'after_title' => '</h2>',
    		) );
    	}
    }

    The problem is that one of the plug-ins I use (VKontakte API) calls the 'widgets_init' action manually second time after WordPress does that. I'm not sure why would it need that. However if the pbt_widgets_init is called twice then the two includes:

    // include the widgets
    	include( THEME_TEMPLATE . '/widgets/widget_login.php' );
    	include( THEME_TEMPLATE . '/widgets/widget_feature.php' );

    will raise the Fatal error because of the duplicated function name.

    What I did locally is:
    - I changed them to include_once and
    - I changed two register_sidebar code to include "id" property:

    register_sidebar( array(
    		'name' => 'Sidebar One',
    		'id'   => 'sidebar'
    		'before_widget' => '<div id="%1$s" class="side-widget %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h2>',
    		'after_title' => '</h2>',
    	) );
    
    	if ( 0 != pbt_theme_option( 'sidebar_width2' ) ) {
    		register_sidebar( array(
    			'name' => 'Sidebar Two',
    			'id'   => 'secondsidebar',
    			'before_widget' => '<div id="%1$s" class="side-widget %2$s">',
    			'after_widget' => '</div>',
    			'before_title' => '<h2>',
    			'after_title' => '</h2>',
    		) );
    	}

    After that the hook could be called safely arbitrary number of times.
    I guess it's safe to do that changes in the theme as it seems it has no serious side-effects
    http://wordpress.org/extend/themes/magazine-basic/

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic