Tag Info

Hot answers tagged

7

You're absolutely right that you can pass reusable form field markup to add_settings_field(). The trick is to define the data type for each setting, and then pass the same callback to each call to add_settings_field(). Within that callback, you simply add a switch that includes cases for each data type. Here's how I do it in Oenology: First, I dynamically ...


3

Look at the declaration for the function: function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) The last parameter takes your arguments and passes them to the callback function. Example from my plugin Public Contact Data foreach ( $this->fields as $type => $desc ) { $handle = ...


2

I built a similar system for my Easy Digital Downloads plugin and I think it behaves the way you want it. I recorded a video tutorial of how the system works. Maybe watch it to get an idea or two?


2

add_settings_field() accepts six arguments, the last one is an array of arguments: add_settings_field($id, $title, $callback, $page, $section, $args); You can add custom values here, so you can reuse one callback. A simple example: add_settings_field( 'foo', 'Foo', 'wpse_settingsfield_callback', 'my_page', 'my_section', array ( ...


1

Better way is use a wordpress options plugins. One of the best is Advanced Custom Fields. http://www.advancedcustomfields.com/ If you buy a option page addon, then you can create a unlimited option page with lot of features. Please what out a video. http://www.advancedcustomfields.com/add-ons/options-page/ Very usefull plugin and addon.


1

Well the second bit of code is technically the correct way to do it. However, at the end of the add_settings_field() you can pass arguements. Please view the WordPress Add_Settings_Field function reference. This will help you in getting the best understanding of how the add_settings_field() function really works. Now, with that said, you could use a ...


1

I made one change... $wp_customize->add_setting( // ID 'primm_slider_speed', // Arguments array array( 'default' => '5000', 'type' => 'theme_mod' <-- made change right here. ) ); 'type' = 'option' just didn't work. 'type' = 'theme_mod' totally nailed it. Option set ...


1

jQuery can only clone what is on the current page or what is loaded over AJAX, so setting something up on the backend and cloning it on the front is not possible. What you can do is create a string and print to the front as a Javascript variable or as a hidden div that you can then clone with jQuery. WordPress does this on the backend if you look near the ...


1

Do not use different callbacks, use the the sixth parameter for add_settings_field() instead. That is an array, and you can pass any data to the callback here. Example: foreach( $theOptions as $k => $v ) { add_settings_field( $k, $v, 'my_callback', $the_options, $the_group, array ( ...


1

FWIW, to get this to work as intended, I went ahead with the wp_dropdown_categories function approach, settling for a js on-load hack to facilitate selection of currently excluded categories witin the dropdown. /* Add Settings Field --"Exclude Categories"-- under options-reading.php page */ class Add_Settings_Field { public function __construct() { ...


1

First of all you need function to calculate lighter and darker colors. Once you have values in hex form a fast way is: convert hex to rgb conver rgb to hsl lighter and darker hsl (that is easy) revert lighter and darker colors from to hsl to hex (hsl > rgb > hex) Settings API use update_option to store data, and so a update_option_{$option} is triggered ...


1

I had the same problem, and here what works for me: function journal_check_cats_callback() { $options = get_option('journal_theme_blog_2_col'); $pag = journal_theme_blog_2_col; $_cats = get_terms( 'category' ); $html = ''; foreach ($_cats as $term) { $checked = in_array($term->term_id, $options) ? ...


1

I'm assuming $settings is an assigned variable elsewhere in your code? If so, then ya gotta globalise it son (variable scope in PHP): function outputFavIcon() { global $settings; ?> And spell it right too ;) <?php if ( isset ( $settings['generel_settings' /* <- typo? */]['fav_icon'] ) ) {



Only top voted, non community-wiki answers of a minimum length are eligible