【发布时间】:2018-06-27 04:45:58
【问题描述】:
如何在 WordPress 的 add_settings_field 中添加 媒体选择器?
这是我添加到 WordPress 中设置 -> 常规 页面的额外字段:
/**
* Add more input fields in general settings.
*/
add_action('admin_init', 'extended_general_settings');
function extended_general_settings() {
add_settings_section(
'other_site_details', // Section ID
'Other Site Details', // Section Title
'extended_general_settings_description_callback', // Callback
'general' // What Page? This makes the section show up on the General Settings Page
);
add_settings_field( // Content
'meta_description', // Option ID
'Meta Description', // Label
'extended_generals_setting_textarea_callback', // !important - This is where the args go!
'general', // Page it will be displayed (General Settings)
'other_site_details', // Name of our section
array( // The $args
'meta_description' // Should match Option ID
)
);
add_settings_field( // Keywords
'meta_keywords', // Option ID
'Meta Keywords', // Label
'extended_generals_setting_textarea_callback', // !important - This is where the args go!
'general', // Page it will be displayed (General Settings)
'other_site_details', // Name of our section
array( // The $args
'meta_keywords' // Should match Option ID
)
);
add_settings_field( // Telephone
'telephone', // Option ID
'Telephone', // Label
'extended_general_settings_textbox_callback', // !important - This is where the args go!
'general', // Page it will be displayed (General Settings)
'other_site_details', // Name of our section
array( // The $args
'telephone' // Should match Option ID
)
);
add_settings_field( // Email
'email', // Option ID
'Email', // Label
'extended_general_settings_textbox_callback', // !important - This is where the args go!
'general', // Page it will be displayed
'other_site_details', // Name of our section (General Settings)
array( // The $args
'email' // Should match Option ID
)
);
register_setting('general','meta_description', 'esc_attr');
register_setting('general','meta_keywords', 'esc_attr');
register_setting('general','telephone', 'esc_attr');
register_setting('general','email', 'esc_attr');
}
function extended_general_settings_description_callback() { // Section Callback
echo '<p>Add additional site info below here:</p>';
}
function extended_general_settings_textbox_callback($args) { // Textbox Callback
$option = get_option($args[0]);
echo '<input type="text" id="'. $args[0] .'" name="'. $args[0] .'" value="' . $option . '" class="regular-text ltr"/>';
}
function extended_generals_setting_textarea_callback($args) { // Textbox Callback
$option = get_option($args[0]);
echo '<textarea rows="6" cols="40" id="'. $args[0] .'" name="'. $args[0] .'" class="regular-text ltr">' . $option . '</textarea>';
}
但我想添加媒体选择器,以便我可以从媒体库中选择一张图片,我已将所有图片上传到该媒体库中。
这可能吗?
【问题讨论】: