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 (
'special' => $k
)
);
}
function my_callback( $args )
{
var_dump( $args['special'] );
switch ( $args['special'] )
{
case 'foo':
// do something
break;
case 'bar':
// do something else
break;
default:
// default handler
}
}
Related Posts:
- Theme Options: If There is No Input, Don’t Display?
- Choose To Display Post Views With An Options Panel
- Set WordPress Default Template
- Set the checkbox as checked by default at options page
- Settings API callback function inserts html quotes from nowhere
- WordPress Options Page Theory Question
- Where is this function’s callback getting its arguments from?
- how to save checkbox data for custom setting?
- Reading settings in the home page precisely home.php
- Warning: call_user_func() expects parameter 1 to be a valid callback, function
- Deactivate a plugin on wp version
- Dynamically switch file in get_template_directory_uri() | Function [closed]
- Custom plugin: how do I call a PHP file if settings option is set to true?
- What is the proper way to call a function (from functions.php) on a link click?
- Calling PHP function doesn’t work in index.php
- Select area and checkbox data is not saving?
- Options.php loop won’t show!
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- start_lvl Ignored in Custom walker_nav_menu
- Enforcing password complexity
- Allowed memory size of 268435456 bytes exhausted (tried to allocate 7146491840906359738 bytes)
- How do I make my function add variables/values to the $post object?
- Check if a menu is empty?
- How do I get the author’s page url from their ID?
- Calculate percentage of post by category
- Dynamically change feature image in customiser
- Change comments form title on a page by page basis
- Creating wordpress user registration form
- Get the title before comma
- category not display in word press grammatically
- Getting a fatal error while updating
- How do I know what variables are passed in a filter/action and what their meaning is?
- “Can’t use function return value in write context” error
- Display 4 chronological posts starting with a random post
- theme options echoing multiple times
- Use is_product_category() properly
- Add before_content and after_content to register_sidebar
- How to access function from outside of a class within this class in WP plugin?
- PHP can I add line numbers to file_get_contents()
- Changing Woocommerce flat rate every nth number of items
- Convert all images to PNG on file upload
- Using file_get_contents with Gravity Forms uploads folder to create images in the media library returning false
- Replace word in “the_content” only for index.php
- Custom location for attached images
- Using fwrite() and “a” appends multiple times instead of once
- Where in PHP do I move title and meta (date) to bottom of each blog section?
- How to display posts by current user in a drop down
- Selectbox in admin panel function linking to CSS
- How do I add custom bulk actions to multiple custom post types?
- Making BuddyPress Activity Stream (Post Type) Featured Images Clickable [closed]
- Keyword checking in Gravity Forms
- how to refresh div on template part?
- How to change menu order item
- Get URL Parameters from referer
- responsive.css in the WordPress should be prioritized
- How to display login form anywhere, when user isn’t logged in, without redirecting?
- Widget back end radio button issue
- GET problem in WordPress
- Help with WordPress function inside a shortcode
- Send a mail to specific address in a custom field when a new comment is made on a specific post
- CSS change in woo commerce Place Order Text [closed]
- WP All Import / Update stock quantity from multiple XML files
- Change MySQL PDO connection to a WPDB connection
- How to style injected code in header section?
- Hide a div when a custom field is empty
- what does $options = get_option(‘test_theme’); do?
- SQL error with custom query
- Can’t log in to WordPress wp-admin after adding code to functions.php
- How to change basename url for wp-admin?
- How to exclude meta no index pages from wp_list_pages
- Products listing check if meta checkbox is checked
- How to preload header logo image in WordPress? like what’s the code and where do I put it?
- Search by date in WordPress
- Hide a div if the fiels is empty
- Illegal string offset checkbox
- require get_template_directory() . ‘path/to-my/file.php’ BREAKS customize > themes functionality
- Edit a function to take different actions based on user role
- How to put 2 php codes in functions.php without site crashing
- I got big white screen when i attach main style sheet of Html in functions.php
- Using Javascript On Page – Header and Footer Now Missing
- Unzip_file causing Media file upload error
- How to generate customized filtered output for the gallery
- WP HTTP API call response
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Escaping a Single Quote in str_replace for Nav Function
- Private messaging – Getting and displaying the avatar/url of a message recipient
- Display Year and Month from custom field + Age Calculator
- insert thumbnail image from php script
- WordPress rating by views [closed]
- Trying to see if page is category or single and displaying title with appropriate heading tag
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- Fix My Custom Function: Remove Automatic
- WP Debug enabled Undefined index error in a widget
- WP Fatal error: Call to undefined function get_template_directory_uri()
- Remove default Image Sizes
- A better way to write this php function
- Understanding responsive imagery
- How to get meta box labels?
- How do I stylize selected comments?
- Tags being Inserted in html from plugin PHP not passing through the_content