This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Removing Sidebar Layouts

  • Creator
    Topic
  • #9104
    mizzinc
    Participant

    When applying ‘add_filter( ‘themeblvd_sidebar_layouts’, ‘my_sidebar_layouts’ );’ in a child theme this removes sidebar layouts everywhere except for in Layout Options unless ‘add_filter’ is called before ‘require_once( get_template_directory() . ‘/framework/themeblvd.php’ );’

    Could you explain why that is please and if there is anything that can be done to make this work after the ‘require_once( get_template_directory() . ‘/framework/themeblvd.php’ );’ is included?

    Thank you,

Viewing 10 replies - 1 through 10 (of 10 total)
  • Author
    Replies
  • #9106
    Jason Bobich
    Keymaster

    In order for the Options API to be possible the options get setup when the framework runs, opposed to being hooked later like many other things are. So, when you add your filter, the option has already been setup.

    But there’s nothing wrong putting code in your Child theme before the framework, if that’s what needs to be done. Including the framework file in your Child theme just opens up the flexibility of what you can do, as it give you the power to pick if you want to add code before or after the theme runs.

    However, another approach, would be just to remove the option like the following.

    themeblvd_remove_option( 'layout', 'main', 'sidebar_layout');

    Note: This would go after the framework is included.

    http://dev.themeblvd.com/tutorial/add-remove-edit-theme-option/

    http://dev.themeblvd.com/tutorial/default-framework-options/

    #9107
    Jason Bobich
    Keymaster

    Just to note, in an ideal world, if you’re keeping things organized and clean, the above code might look nicer grouped in a function with any other similar mods like:

    /**
     * Any modifications to options go here.
     */
    function my_option_mods(){
    	
    	themeblvd_remove_option( 'layout', 'main', 'sidebar_layout');
    	// any other option mods ...
    	
    }
    add_action( 'after_setup_theme', 'my_option_mods' );
    #9112
    mizzinc
    Participant

    Amazing support once again.

    Definitely keeping things organised and clean here. Thanks to your reference I utilised ‘themeblvd_edit_option’ called after ‘require_once( get_template_directory() . ‘/framework/themeblvd.php’ );’

    First filtering sidebar layouts.

    function my_sidebar_layouts( $layouts ){
    	unset( $layouts['double_sidebar'] );
    	unset( $layouts['double_sidebar_right'] );
    	unset( $layouts['double_sidebar_left'] );
    	return $layouts;
    }
    add_filter( 'themeblvd_sidebar_layouts', 'my_sidebar_layouts' );

    Then this action.

    function my_option_mods(){
    	$imagepath =  get_template_directory_uri() . '/framework/admin/assets/images/';
    	// Generate sidebar layout options
    	$sidebar_layouts = array();
    	$layouts = themeblvd_sidebar_layouts();
    		foreach( $layouts as $layout )
    			$sidebar_layouts[$layout['id']] = $imagepath.'layout-'.$layout['id'].'.png';
    				
    	themeblvd_edit_option( 'layout', 'main', 'sidebar_layout', 'options', $sidebar_layouts );
    		
    }
    add_action( 'after_setup_theme', 'my_option_mods' );
    #10188
    mizzinc
    Participant

    Updated to Version 1.1
    How do we approach removing sidebar layouts now?

    #10212
    Jason Bobich
    Keymaster

    I’m not sure anything had changed in this regard? What are you currently doing that isn’t working? What specifically isn’t working? I would think this should still work the same.

    #10235
    mizzinc
    Participant

    Sorry that was a bit vague.

    Employing the same method above does not edit the ‘Default Sidebar Layout’ options in Theme Options > Layout.

    #10264
    Jason Bobich
    Keymaster

    So, this is actually an awesome find you’ve stumbled across here. There is a problem with the themeblvd_edit_option function, which is basically just a typo from the re-structuring that happenned with the Options API in 2.3.

    I’ll have this fixed in the next update which I’ll post soon, but if this is a must you need right away, you can fix it in the framework if you want.

    Open this file: /framework/api/class-tb-options-api.php

    And on line 829, find this method:

    public function edit_option( $tab_id, $section_id, $option_id, $att, $value ) {
    
    	if ( ! isset( $_themeblvd_core_options[$tab_id] ) ) {
    		return;
    	}
    
    	if ( ! isset( $_themeblvd_core_options[$tab_id]['sections'][$section_id] ) ) {
    		return;
    	}
    
    	if ( ! isset( $_themeblvd_core_options[$tab_id]['sections'][$section_id]['options'][$option_id] ) ) {
    		return;
    	}
    
    	$this->raw_options[$tab_id]['sections'][$section_id]['options'][$option_id][$att] = $value;
    }

    The three places where it says $_themeblvd_core_options, it should say $this->raw_options. So, the updated method should be this:

    public function edit_option( $tab_id, $section_id, $option_id, $att, $value ) {
    
    	if ( ! isset( $this->raw_options[$tab_id] ) ) {
    		return;
    	}
    
    	if ( ! isset( $this->raw_options[$tab_id]['sections'][$section_id] ) ) {
    		return;
    	}
    
    	if ( ! isset( $this->raw_options[$tab_id]['sections'][$section_id]['options'][$option_id] ) ) {
    		return;
    	}
    
    	$this->raw_options[$tab_id]['sections'][$section_id]['options'][$option_id][$att] = $value;
    }
    #10265
    mizzinc
    Participant

    Thanks Jason, its not a must at the moment but out of interest I did apply the fix to the framework which has not resolved the issue. I will re-check my implementation though and wait for your posted update.

    #10268
    Jason Bobich
    Keymaster

    Hmm, I pasted your two chunks of code here as-is on my end and everything was working for me when I view the theme options, seeing those sidebar layouts removed.

    #10270
    mizzinc
    Participant

    Yeah, it was my implementation. Works a treat!

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.