Hot answers tagged add-settings-field
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 = ...
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
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
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?
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'] ) ) {
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) ? ...
Only top voted, non community-wiki answers of a minimum length are eligible