duanci5913 2015-04-22 12:19
浏览 118
已采纳

如何为WordPress管理面板创建自己的后端功能

I'm trying to call a function in the admin panel to fetch and call database records from the backend.

Here is my code:

 // 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() {  

Here I can't understand what I missed in this code?

  • 写回答

1条回答 默认 最新

  • dongxu1875 2015-04-23 07:37
    关注

    Here is the solution ☺ :

    // 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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作