繁体   English   中英

如何获取插件 wordpress 选项的值?

[英]How do I get the value of my plugin wordpress option?

我有一个 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' );

您的 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.'
        )
    );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM