本文介绍了如何在 Wordpress 仪表板小部件中显示 WooCommerce 新用户注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我想创建一个 wordpress 仪表板小部件,在仪表板上显示 WooCommerce 注册用户.
目前正在使用他的代码
add_action('wp_dashboard_setup', 'register_my_dashboard_widget');函数 register_my_dashboard_widget() {wp_add_dashboard_widget('my_dashboard_widget','我的仪表板小部件','my_dashboard_widget_display');}函数 my_dashboard_widget_display() {echo '这里的上下文';}
我创建了一个小部件,但不知道如何在那里显示注册用户.
解决方案注释并在代码中添加说明.
使用的函数:
get_users()
- 检索列表用户匹配标准.$args
wp_dashboard_setup()
- 注册仪表板小部件.function action_wp_dashboard_setup() {wp_add_dashboard_widget('my_dashboard_widget',//Widget slug.esc_html__( 'My Dashboard Widget', 'woocommerce' ),//标题'my_dashboard_widget_function'//显示函数);}add_action('wp_dashboard_setup', 'action_wp_dashboard_setup');函数 my_dashboard_widget_function() {//参数$args = 数组('role_in' =>array( 'administrator', 'customer'),//用户角色'orderby' =>'用户注册','订单' =>'ASC','数字' =>-1//全部);//获取用户$users = get_users( $args );//输出echo '';echo '';//真的如果 ( $users ) {foreach ( $users 作为 $user ) {echo ' 用户名 = ' .$user->display_name .'</li>';}} 别的 {echo '没有找到用户';}回声'</ul>';回声'</div>';}
I would like to create a wordpress dashboard widget which shows WooCommerce registered user at dashboard.
Currently using his code
add_action( 'wp_dashboard_setup', 'register_my_dashboard_widget' );
function register_my_dashboard_widget() {
wp_add_dashboard_widget(
'my_dashboard_widget',
'My Dashboard Widget',
'my_dashboard_widget_display'
);
}
function my_dashboard_widget_display() {
echo 'the context here';
}
I have created a widget but don't know how to show registered user there.
解决方案Comment with explanation added in the code.
Functions used:
get_users()
- Retrieve list of users matching criteria. $args
wp_dashboard_setup()
- Registers dashboard widgets.
function action_wp_dashboard_setup() {
wp_add_dashboard_widget(
'my_dashboard_widget', // Widget slug.
esc_html__( 'My Dashboard Widget', 'woocommerce' ), // Title
'my_dashboard_widget_function' // Display function
);
}
add_action( 'wp_dashboard_setup', 'action_wp_dashboard_setup' );
function my_dashboard_widget_function() {
// Args
$args = array(
'role_in' => array( 'administrator', 'customer'), // user roles
'orderby' => 'user_registered',
'order' => 'ASC',
'number' => -1 // all
);
// Get users
$users = get_users( $args );
// Output
echo '<div class="main">';
echo '<ul>';
// True
if ( $users ) {
foreach ( $users as $user ) {
echo '<li>User name = ' . $user->display_name . '</li>';
}
} else {
echo '<li>no users found</li>';
}
echo '</ul>';
echo '</div>';
}
这篇关于如何在 Wordpress 仪表板小部件中显示 WooCommerce 新用户注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论