Skip to content

Details about the option types

Darko Gjorgjijoski edited this page Mar 3, 2021 · 1 revision

The following options are available for use:

Background:

The Background option type has filters that allow you to remove fields or change the defaults. For example, you can filter opb_recognized_background_fields to remove unwanted fields from all Background options or an individual one. You can also filter opb_recognized_background_repeat, opb_recognized_background_attachment, opb_recognized_background_position, and opb_type_background_size_choices. These filters allow you to fine tune the select lists for your specific needs.

Border:

The Border option type is used to set width, unit, style, and color values. The text input excepts a numerical value and the unit select lets you choose the unit of measurement to add to that value. Currently the default units are px, %, em, and pt. However, you can change them with the opb_recognized_border_unit_types filter. The style select lets you choose the border style. The default styles are hidden, dashed, solid, double, groove, ridge, inset, and outset. However, you can change them with the opb_recognized_border_style_types filter. The colorpicker saves a hexadecimal color code.

Box Shadow:

The Box Shadow option type is used to set inset, offset-x, offset-y, blur-radius, spread-radius, and color values.

Category Checkbox:

The Category Checkbox option type displays a list of category IDs. It allows the user to check multiple category IDs and will return that value as an array for use in a custom function or loop.

Category Select:

The Category Select option type displays a list of category IDs. It allows the user to select only one category ID and will return that value for use in a custom function or loop.

Checkbox:

The Checkbox option type displays a group of choices. It allows the user to check multiple choices and will return that value as an array for use in a custom function or loop.

Colorpicker:

The Colorpicker option type saves a hexadecimal color code for use in CSS. Use it to modify the color of something in your theme.

Colorpicker Opacity:

The Colorpicker Opacity option type saves a hexadecimal color code with an opacity value from 0 to 1 in increments of 0.01. Though the value is saved as hexadecimal, if used within the CSS option type the color and opacity values will be converted into a valid RGBA CSS value.

CSS:

The CSS option type is a textarea that when used properly can add dynamic CSS to your theme from within OptionBuilder. Unfortunately, due server limitations you will need to create a file named dynamic.css at the root level of your theme and change permissions using chmod so the server can write to the file. I have had the most success setting this single file to 0777 but feel free to play around with permissions until everything is working. A good starting point is 0666. When the server can save to the file, CSS will automatically be updated when you save your Theme Options.

This example assumes you have an option with the ID of demo_background. Which means this option will automatically insert the value of demo_background into the dynamic.css when the Theme Options are saved.

Input:

body {
  {{demo_background}}
  background-color: {{demo_background|background-color}};
}

Output:

/* BEGIN demo_background */
body {
  background: color image repeat attachment position;
  background-color: color;
}
/* END demo_background */

Custom Post Type Checkbox:

The Custom Post Type Select option type displays a list of IDs from any available WordPress post type or custom post type. It allows the user to check multiple post IDs for use in a custom function or loop. Requires at least one valid post_type in the post_type field.

Custom Post Type Select:

The Custom Post Type Select option type displays a list of IDs from any available WordPress post type or custom post type. It will return a single post ID for use in a custom function or loop. Requires at least one valid post_type in the post_type field.

Date Picker:

The Date Picker option type is tied to a standard form input field which displays a calendar pop-up that allow the user to pick any date when focus is given to the input field. The returned value is a date formatted string.

Date Time Picker:

The Date Time Picker option type is tied to a standard form input field which displays a calendar pop-up that allow the user to pick any date and time when focus is given to the input field. The returned value is a date and time formatted string.

Dimension:

The Dimension option type is used to set width and height values. The text inputs except numerical values and the select lets you choose the unit of measurement to add to that value. Currently the default units are px, %, em, and pt. However, you can change them with the opb_recognized_dimension_unit_types filter.

Gallery:

The Gallery option type saves a comma separated list of image attachment IDs. You will need to create a front-end function to display the images in your theme.

Google Fonts:

The Google Fonts option type will dynamically enqueue any number of Google Web Fonts into the document HEAD. As well, once the option has been saved each font family will automatically be inserted into the font-family array for the Typography option type. You can further modify the font stack by using the opb_google_font_stack filter, which is passed the $font_stack, $family, and $field_id parameters. The $field_id parameter is being passed from opb_recognized_font_families, so it will be the ID of a Typography option type. This will allow you to add additional web safe fonts to individual font families on an as-need basis.

JavaScript:

The JavaScript option type is a textarea that uses the ace.js code editor to highlight your JavaScript and display errors as you type.

Link Color:

The Link Color option type is used to set all link color states.

List Item:

The List Item option type replaced the Slider option type and allows for a great deal of customization. You can add settings to the List Item and those settings will be displayed to the user when they add a new List Item. Typical use is for creating sliding content or blocks of code for custom layouts.

Measurement:

The Measurement option type is a mix of input and select fields. The text input excepts a value and the select lets you choose the unit of measurement to add to that value. Currently the default units are px, %, em, and pt. However, you can change them with the opb_measurement_unit_types filter.

Example filter to add new units to the Measurement option type. Added to functions.php.

function filter_measurement_unit_types( $array, $field_id ) {

  /* only run the filter on measurement with a field ID of my_measurement */
  if ( $field_id == 'my_measurement' ) {
    $array['in'] = 'inches';
    $array['ft'] = 'feet';
  }

  return $array;
}
add_filter( 'opb_measurement_unit_types', 'filter_measurement_unit_types', 10, 2 );

Example filter to completely change the units in the Measurement option type. Added to functions.php.

function filter_measurement_unit_types( $array, $field_id ) {

  /* only run the filter on measurement with a field ID of my_measurement */
  if ( $field_id == 'my_measurement' ) {
    $array = array(
      'in' => 'inches',
      'ft' => 'feet'
    );
  }

  return $array;
}
add_filter( 'opb_measurement_unit_types', 'filter_measurement_unit_types', 10, 2 );

Numeric Slider:

The Numeric Slider option type displays a jQuery UI slider. It will return a single numerical value for use in a custom function or loop.

On/Off:

The On/Off option type displays a simple switch that can be used to turn things on or off. The saved return value is either on or off.

Page Checkbox:

The Page Checkbox option type displays a list of page IDs. It allows the user to check multiple page IDs for use in a custom function or loop.

Page Select:

The Page Select option type displays a list of page IDs. It will return a single page ID for use in a custom function or loop.

Post Checkbox:

The Post Checkbox option type displays a list of post IDs. It allows the user to check multiple post IDs for use in a custom function or loop.

Post Select:

The Post Select option type displays a list of post IDs. It will return a single post ID for use in a custom function or loop.

Radio:

The Radio option type displays a group of choices. It allows the user to choose one and will return that value as a string for use in a custom function or loop.

Radio Image:

the Radio Images option type is primarily used for layouts. However, you can filter the image list using opb_radio_images. As well, you can add your own custom images using the choices array.

This example executes the opb_radio_images filter on layout images attached to the my_radio_images field. Added to functions.php.

function filter_radio_images( $array, $field_id ) {

  /* only run the filter where the field ID is my_radio_images */
  if ( $field_id == 'my_radio_images' ) {
    $array = array(
      array(
        'value'   => 'left-sidebar',
        'label'   => __( 'Left Sidebar', 'option-builder' ),
        'src'     => OPB_URL . '/assets/images/layout/left-sidebar.png'
      ),
      array(
        'value'   => 'right-sidebar',
        'label'   => __( 'Right Sidebar', 'option-builder' ),
        'src'     => OPB_URL . '/assets/images/layout/right-sidebar.png'
      )
    );
  }

  return $array;

}
add_filter( 'opb_radio_images', 'filter_radio_images', 10, 2 );

Select:

The Select option type is used to list anything you want that would be chosen from a select list.

Sidebar Select:

This option type makes it possible for users to select a WordPress registered sidebar to use on a specific area. By using the two provided filters, opb_recognized_sidebars, and opb_recognized_sidebars_{$field_id} we can be selective about which sidebars are available on a specific content area.

For example, if we create a WordPress theme that provides the ability to change the Blog Sidebar and we don't want to have the footer sidebars available on this area, we can unset those sidebars either manually or by using a regular expression if we have a common name like footer-sidebar-$i.

Slider:

The Slider option type is technically deprecated. Use the List Item option type instead, as it's infinitely more customizable. Typical use is for creating sliding image content.

Social Links:

The Social Links option type utilizes a drag & drop interface to create a list of social links. There are a few filters that make extending this option type easy. You can set the opb_type_social_links_load_defaults filter to false and turn off loading default values. Use the opb_type_social_links_defaults filter to change the default values that are loaded. To filter the settings array use the opb_social_links_settings filter.

Spacing:

The Spacing option type is used to set spacing values such as padding or margin in the form of top, right, bottom, and left. The text inputs except numerical values and the select lets you choose the unit of measurement to add to that value. Currently the default units are px, %, em, and pt. However, you can change them with the opb_recognized_spacing_unit_types filter.

Tab:

The Tab option type will break a section or metabox into tabbed content.

Tag Checkbox:

The Tag Checkbox option type displays a list of tag IDs. It allows the user to check multiple tag IDs and will return that value as an array for use in a custom function or loop.

Tag Select:

The Tag Select option type displays a list of tag IDs. It allows the user to select only one tag ID and will return that value for use in a custom function or loop.

Taxonomy Checkbox:

The Taxonomy Checkbox option type displays a list of taxonomy IDs. It allows the user to check multiple taxonomy IDs and will return that value as an array for use in a custom function or loop.

Taxonomy Select:

The Taxonomy Select option type displays a list of taxonomy IDs. It allows the user to select only one taxonomy ID and will return that value for use in a custom function or loop.

Text:

The Text option type is used to save string values. For example, any optional or required text that is of reasonably short character length.

Textarea:

The Textarea option type is a large string value used for custom code or text in the theme and has a WYSIWYG editor that can be filtered to change the how it is displayed. For example, you can filter wpautop, media_buttons, tinymce, and quicktags.

Example filters to alter the Textarea option type. Added to functions.php.

This example keeps WordPress from executing the wpautop filter on the line breaks. The default is true which means it wraps line breaks with an HTML p tag.

function filter_textarea_wpautop( $content, $field_id ) {

  /* only run the filter on the textarea with a field ID of my_textarea */
  if ( $field_id == 'my_textarea' ) {
    return false;
  }

  return $content;

}
add_filter( 'opb_wpautop', 'filter_textarea_wpautop', 10, 2 );

This example keeps WordPress from executing the media_buttons filter on the textarea WYSIWYG. The default is true which means show the buttons.

function filter_textarea_media_buttons( $content, $field_id ) {

  /* only run the filter on the textarea with a field ID of my_textarea */
  if ( $field_id == 'my_textarea' ) {
    return false;
  }

  return $content;

}
add_filter( 'opb_media_buttons', 'filter_textarea_media_buttons', 10, 2 );

This example keeps WordPress from executing the tinymce filter on the textarea WYSIWYG. The default is true which means show the tinymce.

function filter_textarea_tinymce( $content, $field_id ) {

  /* only run the filter on the textarea with a field ID of my_textarea */
  if ( $field_id == 'my_textarea' ) {
    return false;
  }

  return $content;

}
add_filter( 'opb_tinymce', 'filter_textarea_tinymce', 10, 2 );

This example alters the quicktags filter on the textarea WYSIWYG. The default is array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' ) which means show those quicktags. It also means you can filter in your own custom quicktags.

function filter_textarea_quicktags( $content, $field_id ) {

  /* only run the filter on the textarea with a field ID of my_textarea */
  if ( $field_id == 'my_textarea' ) {
    return array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,spell,close,fullscreen' );
  } else if ( $field_id == 'my_other_textarea' ) {
    return false; /* show no quicktags */
  }

  return $content;

}
add_filter( 'opb_quicktags', 'filter_textarea_quicktags', 10, 1 );

Textarea Simple:

The Textarea Simple option type is a large string value used for custom code or text in the theme. The Textarea Simple does not have a WYSIWYG editor.

This example tells WordPress to execute the wpautop filter on the line breaks. The default is false which means it does not wraps line breaks with an HTML p tag. Added to functions.php.

function filter_textarea_simple_wpautop( $content, $field_id ) {

  /* only run the filter on the textarea with a field ID of my_textarea */
  if ( $field_id == 'my_textarea' ) {
    return true;
  }

  return $content;

}
add_filter( 'opb_wpautop', 'filter_textarea_simple_wpautop', 10, 2 );

Textblock:

The Textblock option type is used only on the Theme Option page. It will allow you to create & display HTML, but has no title above the text block. You can then use the Textblock to add a more detailed set of instruction on how the options are used in your theme. You would never use this in your themes template files as it does not save a value.

Textblock Titled:

The Textblock Titled option type is used only on the Theme Option page. It will allow you to create & display HTML, and has a title above the text block. You can then use the Textblock Titled to add a more detailed set of instruction on how the options are used in your theme. You would never use this in your themes template files as it does not save a value.

Typography:

The Typography option type has filters that allow you to remove fields or change the defaults. For example, you can filter opb_recognized_typography_fields to remove unwanted fields from all Background options or an individual one. You can also filter opb_recognized_font_families, opb_recognized_font_sizes, opb_recognized_font_styles, opb_recognized_font_variants, opb_recognized_font_weights, opb_recognized_letter_spacing, opb_recognized_line_heights, opb_recognized_text_decorations and opb_recognized_text_transformations. These filters allow you to fine tune the select lists for your specific needs.

This example would filter opb_recognized_font_families to build your own font stack. Added to functions.php.

function filter_opb_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( 'opb_recognized_font_families', 'filter_opb_recognized_font_families', 10, 2 );

Upload:

The Upload option type is used to upload any WordPress supported media. After uploading, users are required to press the "Send to OptionBuilder" button in order to populate the input with the URI of that media. There is one caveat of this feature. If you import the theme options and have uploaded media on one site the old URI will not reflect the URI of your new site. You will have to re-upload or FTP any media to your new server and change the URIs if necessary.