简体   繁体   English

如何将数据显示到由WordPress中的插件功能生成的管理面板中

[英]How to display data into Admin panel which is generated by plugin function in wordpress

I am developing a new Plugin and I get the database value into our plugin 我正在开发一个新的插件,并将数据库值添加到我们的插件中

function But How to pass these data to view file.I Used following code into the 功能但是如何传递这些数据来查看文件。

plugin main file. 插件主文件。

 <?php
        /*
            Plugin Name: All Attendees
            Plugin URI: http://my-awesomeness-emporium.com
            Description: a plugin to create awesomeness and spread joy
            Version: 1.2
            Author: Mr. Awesome
            Author URI: http://mrtotallyawesome.com
            License: GPL2
        */
    ?>



<?php 

    add_action('init', 'my_register_styles');
    function my_register_styles() {
        add_action('admin_menu', 'all_attendees');
    }
    function all_attendees(){

        $wpdb = EventPlus::getRegistry()->db->getDb();
        $sql = "SELECT id,reg_type,quantity,event_id,lname,fname,payment,payment_status,email FROM wp_evr_attendee ORDER BY id DESC Limit 30";
        $rows = $wpdb->get_results($sql);
        echo "<pre>";print_r($rows);die;
    }

?>

If you want display and create template page in dashboard, in that admin template files(main-menu.php,sub-menu.php) you can write whatever you want. 如果要在仪表板中显示和创建模板页面,则可以在该管理模板文件(main-menu.php,sub-menu.php)中编写所需的内容。

Go through the below code and paste it in your plugin main file. 浏览以下代码并将其粘贴到您的插件主文件中。

add_action('admin_menu', 'menu_page_name');

function menu_page_name() 
{
    // Add the top-level admin menu


    $page_title = 'title';
    $menu_title = 'title';
    $capability = 'manage_options';
    $menu_slug = 'slug_name';
    $function = 'callback_main_menu';

    add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function);

    // Add submenu page with same slug as parent to ensure no duplicates

     add_submenu_page($menu_slug, 'Plugin Name', 'Plugin Name', $capability, 'pluginname', 'callback_sub_menu');

}

function callback_main_menu() 
{
    if (!current_user_can('manage_options')) 
    {
    wp_die('You do not have sufficient permissions to access this page.');
    }
    else
    {
//include your admin template here
    include('templates/main-menu.php');   
    }

    // Render the HTML for the Help page or include a file that does
}
function callback_sub_menu() 
{
    if (!current_user_can('manage_options')) 
    {
    wp_die('You do not have sufficient permissions to access this page.');
    }
    else
    {
//include your admin template here
    include('templates/sub-menu.php');   
    }

    // Render the HTML for the Help page or include a file that does
}

If you want to display data or etc on frontend, go through the below code 如果要在前端显示数据等,请执行以下代码

function plugin_short_code(){
//Return your functionality here
retrn $result;

    }

add_shortcode('plugin_shortcode', 'plugin_short_code');

You can use this shortcode in your frontend 您可以在前端使用此短代码

There are multiple way to display plugin data, One way is use short code API 有多种显示插件数据的方法,一种是使用短代码API

example: 例:

 function call_back_function(){
   //function in plugin file with return value,
   //  custom fetch query 
}

add_shortcode('shotcode', 'call_back_function');


echo do_shortcode('[shotcode]'); //for display

You can display data in tabular format same as word press post / page tradition as well. 您也可以按表格格式显示数据,与Word Press Post / Page传统相同。

WP list table for word press admin WP列表表的单词新闻管理员

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

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