Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to extend parent theme sections and settings to Options Tree in Child Theme #402

Closed
mohsin-sharpen opened this issue Nov 7, 2014 · 5 comments

Comments

@mohsin-sharpen
Copy link

Hi,
I am developing a child theme based on a Valenti theme that use Option Tree for it's options.

Is it possible to add a new section & settings with my child theme settings to the already defined sections & settings by parent theme?

If it is possible then can some give me an example or guide me in this regard.

Your prompt response would be highly appreciated...!

Currently Valenti Theme using Option Tree version 2.4.0

@valendesigns
Copy link
Owner

How are the theme options created in your parent theme?

@mohsin-sharpen
Copy link
Author

Something like this...!

File name is cb-to.php

array( 'sidebar' => 'Get help here' ), 'sections' => array( array( 'id' => 'ot_general', 'title' => 'General' ) ), 'settings' => array( array( 'id' => 'cb_logo_url', 'label' => 'Logo', 'desc' => 'Upload your logo (Recommended size: 260px x 70px). Automatically loads Retina version if available. See documentation for more details.', 'std' => '', 'type' => 'upload', 'section' => 'ot_general', 'rows' => '', 'post_type' => '', 'taxonomy' => '', 'min_max_step' => '', 'class' => '' ) ) ); /_ allow settings to be filtered before saving */ $custom_settings = apply_filters('option_tree_settings_args', $custom_settings); /\* settings are not the same update the DB */ if ($saved_settings !== $custom_settings) { update_option('option_tree_settings', $custom_settings); } } Included in functions.php file like this // Fire Up The Framework add_filter('ot_show_pages', '__return_false'); add_filter('ot_show_new_layout', '__return_false'); add_filter('ot_theme_mode', '__return_true'); load_template(get_template_directory() . '/option-tree/ot-loader.php'); load_template(get_template_directory() . '/option-tree/includes/meta-boxes.php'); require_once get_template_directory() . '/library/cb-to.php';

@valendesigns
Copy link
Owner

You can use the option_tree_settings_args filter that's in that code to add settings specific to only the child theme since the parent theme will load that file and your child theme will extend it. Alternatively, you could overload that file and add more options to the array from your child theme.

Cheers,
Derek=

@mohsin-sharpen
Copy link
Author

Do I have to overload the file cb-to.php only with the new sections/settings or I have to add the previous options as well.

Can you please check the method I am writing here; is fine or still needs to do some amendments as I am not good at applying filters.

Method:
In Child Theme, functions.php
require_once get_stylesheet_directory_uri() . '/library/new-cb-to.php';

And In "new-cb-to.php" file, is the code below ok

add_filter("option_tree_settings" . '_args', 'my_ot_setting');

function my_ot_setting($custom_settings)
{
//do some work with the settings and the sections, ie append your settings.
$custom_settings = array(
'sections' => array(
array(
'id' => 'ot_dx_advertising',
'title' => 'DX Advertisement'
)
),
'settings' => array(
array(
'id' => 'dx_banner_code',
'label' => 'Banner Code',
'desc' => 'Enter your ad code.',
'std' => '',
'type' => 'textarea-simple',
'section' => 'ot_dx_advertising',
'rows' => '4',
'post_type' => '',
'taxonomy' => '',
'min_max_step' => '',
'class' => '',
'condition' => 'dx_banner_selection:not(cb_banner_off)'
)
)
);

return $custom_settings;

}

Can you please see my above code. Am i on right track?

@valendesigns
Copy link
Owner

Your code above would write over all the sections and settings. You need to do something like this, so it extends your parent theme options.

function my_ot_setting( $custom_settings ) {

  // Add section
  if ( isset( $custom_settings['sections'] ) ) {
    $custom_settings['sections'][] = array(
      'id'            => 'ot_dx_advertising',
      'title'         => 'DX Advertisement'
    );
  }

  // Add settings
  if ( isset( $custom_settings['settings'] ) ) {
    $custom_settings['settings'][] = array(
      'id'            => 'dx_banner_code',
      'label'         => 'Banner Code',
      'desc'          => 'Enter your ad code.',
      'std'           => '',
      'type'          => 'textarea-simple',
      'section'       => 'ot_dx_advertising',
      'rows'          => '4',
      'post_type'     => '',
      'taxonomy'      => '',
      'min_max_step'  => '',
      'class'         => '',
      'condition'     => 'dx_banner_selection:not(cb_banner_off)'
    );
  }

  return $custom_settings;

}
add_filter( 'option_tree_settings_args', 'my_ot_setting' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants