简体   繁体   中英

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;
    }

?>

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
}

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

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.

WP list table for word press admin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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