ThemeForest

OptionTree 2.0

3256 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 more
ParkerAndKent says

Derek, could u explaine, please? I use these lines of code:
$primary_link_color = ot_get_option( 'primary_link_color' );

if ( empty( $primary_link_color ) )
return;
So, if $primary_link_color is empty it’s returns nothing, how could I also make returns nothing if I have standard value? For example, my standard value for $primary_link_color is #777777, it’s possible to make it works like above lines of code?

I think you have to hard code your default value in the if statement:

$primary_link_color = ot_get_option( 'primary_link_color' );

if ( empty( $primary_link_color ) || $primary_link_color == '#777777')
return;

Another solution would be to create an array with all the settings ids as keys and their ‘std’ as value.

$settings = get_option('option_tree_settings', array());
$std = array();
for ($i = 0; $i < count($settings['settings']); $i++) {
    $std[$settings['settings'][$i]['id']] = $settings['settings'][$i]['std'];
}

and so then:

$primary_link_color = ot_get_option( 'primary_link_color' );

if ( empty( $primary_link_color ) || $primary_link_color == $std[ 'primary_link_color'])
return;

Parker

3256 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 more
ParkerAndKent says

Derek, could u explaine, please? I use these lines of code:
$primary_link_color = ot_get_option( 'primary_link_color' );

if ( empty( $primary_link_color ) )
return;
So, if $primary_link_color is empty it’s returns nothing, how could I also make returns nothing if I have standard value? For example, my standard value for $primary_link_color is #777777, it’s possible to make it works like above lines of code?

Additionally,

my personal suggestion.

Declare a global variable and get the options:

global $option_tree;

$option_tree = get_option('option_tree');

Then, when you need to get an option in your theme just refer to the global variable:

global $option_tree;
$primary_link_color = $option_tree['primary_link_color'];

If you call for each option the ot_get_option function then you will make the same number of db requests… better to call the get_option function one time only.

Parker

391 posts
  • Bought between 50 and 99 items
  • Europe
  • Exclusive Author
  • Has been a member for 1-2 years
  • Sold between 5 000 and 10 000 dollars
Pixelous says


Derek, could u explaine, please? I use these lines of code:
$primary_link_color = ot_get_option( 'primary_link_color' );

if ( empty( $primary_link_color ) )
return;
So, if $primary_link_color is empty it’s returns nothing, how could I also make returns nothing if I have standard value? For example, my standard value for $primary_link_color is #777777, it’s possible to make it works like above lines of code?

I think you have to hard code your default value in the if statement:

$primary_link_color = ot_get_option( 'primary_link_color' );

if ( empty( $primary_link_color ) || $primary_link_color == '#777777')
return;

Another solution would be to create an array with all the settings ids as keys and their ‘std’ as value.

$settings = get_option('option_tree_settings', array());
$std = array();
for ($i = 0; $i < count($settings['settings']); $i++) {
    $std[$settings['settings'][$i]['id']] = $settings['settings'][$i]['std'];
}

and so then:

$primary_link_color = ot_get_option( 'primary_link_color' );

if ( empty( $primary_link_color ) || $primary_link_color == $std[ 'primary_link_color'])
return;
Parker

Wow, Parker, thanks, everything works perfect but don’t now which variant to use now, seems the first is less. As for the second, I have declared this:

$settings = get_option('option_tree_settings', array());
$std = array();
for ($i = 0; $i < count($settings['settings']); $i++) {
    $std[$settings['settings'][$i]['id']] = $settings['settings'][$i]['std'];
}

Then in my function this:

// Don't do anything if the body background color is empty or the default.
global $std;
if ( empty( $body_background_color ) || $body_background_color == $std[ 'body_background_color'] )
return;

What do u suggest to use? The first?

3256 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 more
ParkerAndKent says

^

Well,

that depends on your needs… if hard coding the default value is ok for you then go with that option.

With the second method, anytime you decide to change the default value you’d just need to edit the std value of your option, without needing to go through your theme files to change the hardcoded values.

Parker

391 posts
  • Bought between 50 and 99 items
  • Europe
  • Exclusive Author
  • Has been a member for 1-2 years
  • Sold between 5 000 and 10 000 dollars
Pixelous says

Sorry, guys, so many questions but are we able to make standard values for Typography fields? http://snag.gy/liyRQ.jpg

391 posts
  • Bought between 50 and 99 items
  • Europe
  • Exclusive Author
  • Has been a member for 1-2 years
  • Sold between 5 000 and 10 000 dollars
Pixelous says

Could anyone explain, how to make Google Fonts available for Typography option? I have done this:

function filter_ot_recognized_font_families( $array, $field_id ) {

  /* only run the filter when the field ID is my_google_fonts_headings */
  if ( $field_id == 'my_google_fonts_headings' ) {
    $array = array(
      'sans-serif'    => 'sans-serif',
      'open-sans'     => '"Open Sans", sans-serif',
      'droid-sans'    => '"Droid Sans", sans-serif'
    );
  }

  return $array;

}
add_filter( 'ot_recognized_font_families', 'filter_ot_recognized_font_families', 10, 1 );

But don’t understand how this could help.

114 posts
  • Attended a Community Meetup
  • Author had a File in an Envato Bundle
  • Bought between 50 and 99 items
  • Elite Author
  • Envato Staff
  • Exclusive Author
  • Has been a member for 4-5 years
+3 more
valendesigns staff says

Could anyone explain, how to make Google Fonts available for Typography option? I have done this:
function filter_ot_recognized_font_families( $array, $field_id ) {

  /* only run the filter when the field ID is my_google_fonts_headings */
  if ( $field_id == 'my_google_fonts_headings' ) {
    $array = array(
      'sans-serif'    => 'sans-serif',
      'open-sans'     => '"Open Sans", sans-serif',
      'droid-sans'    => '"Droid Sans", sans-serif'
    );
  }

  return $array;

}
add_filter( 'ot_recognized_font_families', 'filter_ot_recognized_font_families', 10, 1 );
But don’t understand how this could help.
add_filter( 'ot_recognized_font_families', 'filter_ot_recognized_font_families', 10, 2 );
114 posts
  • Attended a Community Meetup
  • Author had a File in an Envato Bundle
  • Bought between 50 and 99 items
  • Elite Author
  • Envato Staff
  • Exclusive Author
  • Has been a member for 4-5 years
+3 more
valendesigns staff says

I need to update the docs those should have a 2 and not a 1 for the amount of variables being passed, sorry!

2554 posts Nice Guy
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 5-6 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 200 and 499 users
+5 more
RubenBristian says

Hi Derek

Version 2.0 rocks!! Is there any way to include a custom meta box only in a page template?

114 posts
  • Attended a Community Meetup
  • Author had a File in an Envato Bundle
  • Bought between 50 and 99 items
  • Elite Author
  • Envato Staff
  • Exclusive Author
  • Has been a member for 4-5 years
+3 more
valendesigns staff says

Hi Derek Version 2.0 rocks!! Is there any way to include a custom meta box only in a page template?

Can you elaborate because there are a couple ways I can interoperate that question?

by
by
by
by
by