![](/img/trans.png)
[英]how to create a custom form who store data in wordpress and display in admin panel
[英]How to display data into Admin panel which is generated by plugin function in wordpress
我正在开发一个新的插件,并将数据库值添加到我们的插件中
功能但是如何传递这些数据来查看文件。
插件主文件。
<?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;
}
?>
如果要在仪表板中显示和创建模板页面,则可以在该管理模板文件(main-menu.php,sub-menu.php)中编写所需的内容。
浏览以下代码并将其粘贴到您的插件主文件中。
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');
您可以在前端使用此短代码
有多种显示插件数据的方法,一种是使用短代码API
例:
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
您也可以按表格格式显示数据,与Word Press Post / Page传统相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.