如何获得插件wordpress选项的价值?

时间:2019-06-21 21:53:03

标签: php wordpress plugins

我有一个CSS值,该值存储在自定义CSS的插件中

如何检索该选项?

//1  added the section

add_settings_section(
    'custom_css_textarea',
    'Enter Custom Styles here.',
    'simpledir_callback_custom_css_textarea',
    'simpledir'
);

//2 added the feild

add_settings_field(
        'custom_css_textarea',
        'Custom Css textarea',
        'simpledir_callback_custom_css_textarea',
        'simpledir',
        'simpledir_custom_section_admin',
        [ 'id' => 'custom_css_textarea', 'label' => 'Remove new post and comment links from the Toolbar' ]
    );

//3 made a callback function 

如何访问此textarea值?它很容易更新并保存,但是我不知道如何在回调函数之外获取它

$css = get_option( 'custom-css-textarea' );

1 个答案:

答案 0 :(得分:1)

您的name_section和id_field具有相同的值。 这对我有用

add_settings_section(
   'name_section',
   __( 'Title of Page', 'textdomain' ),
   'callback_render',
   'page_for_show_section');

add_settings_field( 
    'id_field', 
    __( 'Label', 'textdomain' ), 
    'callback_for_render_option'),
    'page_for_show_section',
    'name_section', 
    // The array of arguments to pass to the callback. In this case, just a description.
    array(                              
            'Activate this setting to display the header.'
        )
    );