如果我在这个 wordpress 函数中使用变量,它怎么可能不起作用?
////////
// Creating theme settings
////////
create_theme_setting('theme_social_options');
////////
// function to create theme settings easily
////////
function create_theme_setting($option_name) {
////////
// Theme settings initialize social options
////////
function theme_intialize_options() {
// If the social options don't exist, create them.
if (false == get_option($option_name)) {
add_option($option_name);
}
add_settings_section(
'social_settings_section', // ID used to identify this section and with which to register options
'Social Options', // Title to be displayed on the administration page
'social_options_callback', // Callback used to render the description of the section
$option_name //
);
add_settings_field(
'twitter',
'Twitter',
'twitter_callback',
$option_name,
'social_settings_section'
);
register_setting(
$option_name,
$option_name,
'theme_sanitize_options'
);
}
add_action('admin_init', 'theme_intialize_options');
//
//
function social_options_callback() {
echo '<p>Provide the URL to the social networks you\'d like to display.</p>';
}
//
//
function twitter_callback() {
//First, we read the options
$options = get_option($option_name);
//Next, we need to make sure the element is defined in the options. If not, we'll set an empty string.
$url = '';
if(isset($options['twitter'])) {
$url = $options['twitter'];
}
//Render the output
echo '<input type="text" id="twitter" name="' . $option_name . '[twitter]" value="' . $options['twitter'] . '" />';
}
//
//
function theme_sanitize_options($input) {
$output = array();
//Loop through each of the options sanitizing the data
foreach($input as $key => $val) {
if (isset($input[$key])) {
$output[$key] = esc_url_raw(strip_tags(stripslashes($input[$key])));
}
}
//Return the new collection
return apply_filters('theme_sanitize_options', $output, $input);
}
} //End create_theme_setting