如何为WordPress管理面板

时间:2015-04-22 12:19:26

标签: php wordpress

我试图在管理面板中调用一个函数来从后端获取和调用数据库记录。

这是我的代码:

 // Add the admin options page
function cusplugin_menu_page() {
    add_options_page(__('cusplugin Custom Plugin Settings', 'cusplugin'), __('cusplugin Custom Plugin Settings', 'cusplugin'), 'manage_options', 'cusplugin', 'cusplugin_options_page');
}
add_action('admin_menu', 'cusplugin_menu_page');

// Add the admin settings and such 

function cusplugin_section_callback() {
    echo __('On this page you can add Custom Style (CSS) to change the layout of Contact Form.', 'cusplugin');
}

function cusplugin_field_callback() {
    $cusplugin_setting = esc_textarea(get_option('cusplugin-setting'));
    echo "<textarea name='cusplugin-setting' rows='10' cols='60' maxlength='1000'>$cusplugin_setting</textarea>";
}

// Display the admin options page
function cusplugin_options_page() {  

在这里,我无法理解我在这段代码中遗漏了什么?

1 个答案:

答案 0 :(得分:0)

这是解决方案☺:

// Add the admin options page
function cusplugin_menu_page() {
    add_options_page(__('cusplugin Custom Plugin Settings', 'cusplugin'), __('cusplugin Custom Plugin Settings', 'cusplugin'), 'manage_options', 'cusplugin', 'cusplugin_options_page');
}

add_action('admin_menu', 'cusplugin_menu_page');

// Add the admin settings and such 
function cusplugin_admin_init() {
    register_setting('cusplugin-options', 'cusplugin-setting', 'cusplugin_sanitize_text_field');
    add_settings_section('cusplugin-section', __('Description', 'cusplugin'), 'cusplugin_section_callback', 'cusplugin');
    add_settings_field('cusplugin-field', __('Custom Style', 'cusplugin'), 'cusplugin_field_callback', 'cusplugin', 'cusplugin-section');
}

add_action('admin_init', 'cusplugin_admin_init');

function cusplugin_section_callback() {
    echo __('On this page you can add Custom Style (CSS) to change the layout of Contact Form.', 'cusplugin');
}

function cusplugin_field_callback() {
    $cusplugin_setting = esc_textarea(get_option('cusplugin-setting'));
    echo "<textarea name='cusplugin-setting' rows='10' cols='60' maxlength='1000'>$cusplugin_setting</textarea>";
} 

// Display the admin options page
function cusplugin_options_page() {
// Enter user code here to duiplay options in admin section
}