add_action( 'admin_init', 'wpse_57647_register_settings' );
/*
* Register settings
*/
function wpse_57647_register_settings()
{
register_setting(
'general',
'html_guidelines_message',
'textarea' // <--- Customize this if there are multiple fields
);
add_settings_section(
'site-guide',
'Publishing Guidelines',
'__return_false',
'general'
);
add_settings_field(
'html_guidelines_message',
'Enter custom message',
'wpse_57647_print_text_editor',
'general',
'site-guide'
);
}
/*
* Print settings field content
*/
function wpse_57647_print_text_editor()
{
$the_guides = html_entity_decode( get_option( 'html_guidelines_message' ) );
echo wp_editor(
$the_guides,
'sitepublishingguidelines',
array( 'textarea_name' => 'html_guidelines_message' )
);
}
function add_option_field_to_general_admin_page(){
$option_name = 'my_option';
// регистрируем опцию
register_setting( 'general', $option_name );
// добавляем поле
add_settings_field(
'myprefix_setting-id',
'Название опции',
'myprefix_setting_callback_function',
'general',
'default',
array(
'id' => 'myprefix_setting-id',
'option_name' => 'my_option'
)
);
}
add_action('admin_menu', 'add_option_field_to_general_admin_page');
function myprefix_setting_callback_function( $val ){
$id = $val['id'];
$option_name = $val['option_name'];
?>
<input
type="text"
name="<? echo $option_name ?>"
id="<? echo $id ?>"
value="<? echo esc_attr( get_option($option_name) ) ?>"
/>
<?
}
add_action('admin_init','wpse_57647_register_settings');
function wpse_57647_register_settings(){
register_setting(
'general',
'html_guidelines_message',
'textarea' // <--- Customize this if there are multiple fields
);
add_settings_section(
'site-guide',
'Publishing Guidelines',
'__return_false',
'general'
);
add_settings_field(
'html_guidelines_message',
'Enter custom message',
'wpse_57647_print_text_editor',
'general',
'site-guide'
);
}
/*
* Print settings field content
*/
function wpse_57647_print_text_editor(){
$the_guides=!empty(get_option('html_guidelines_message'))?html_entity_decode(get_option('html_guidelines_message')):'';
echo '<textarea cols="44" placeholder="'.__('Поле для ввода текста','VAB').'"name="html_guidelines_message" id="html_guidelines_message" value="">'.$the_guides.'</textarea>';
}
function add_option_field_to_general_admin_page(){
$option_name='my_option';
// регистрируем опцию
register_setting('general',$option_name);
// добавляем поле
add_settings_field(
'myprefix_setting-id',
'Название опции',
'myprefix_setting_callback_function',
'general',
'default',
array(
'id'=>'myprefix_setting-id',
'option_name'=>'my_option'
)
);
}
add_action('admin_menu','add_option_field_to_general_admin_page');
function myprefix_setting_callback_function($val){
$id=$val['id'];
$option_name=$val['option_name'];
$the_guides=!empty(get_option($option_name))?html_entity_decode(get_option($option_name)):'';
echo '<textarea cols="44" placeholder="'.__('Поле для ввода текста','VAB').'"name="'.$option_name.'" id="'.$option_name.'" value="">'.$the_guides.'</textarea>';
}
customize_register
, добавлять опции и элементы управления с помощью методов add_setting()
и add_control()
$wp_customize->add_setting( 'themeslug_textarea_setting_id', array(
'capability' => 'edit_theme_options',
'default' => 'Lorem Ipsum Dolor Sit amet',
'sanitize_callback' => 'sanitize_textarea_field',
) );
$wp_customize->add_control( 'themeslug_textarea_setting_id', array(
'type' => 'textarea',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Text Area' ),
'description' => __( 'This is a custom textarea.' ),
) );