WordPress 后台用户列表添加更多操作功能

在WordPress后台用户列表,管理员可以编辑和删除用户,如果你想添加更多的操作,比如你的网站有站内信,你可以添加一个快捷发送站内信的链接。下面我们来添加一个访问用户网址的链接:

user-row-actions-wpdaxue_com

如果用户注册时填写了网址,那就添加一个“访问网站”链接,将下面的代码添加到主题的 functions.php:

/**
 * WordPress 后台用户列表添加更多操作功能
 * https://www.wpdaxue.com/user-row-actions.html
 */
add_filter( 'user_row_actions', 'wpdaxue_user_row_actions', 10, 2 );
function wpdaxue_user_row_actions( $actions, $user_object ) {
	if($user_object->user_url) { // 如果存在网址
		$actions['website'] = '<a href="'.$user_object->user_url.'" target="_blank">访问网站</a>';
	}
	return $actions;
}

你可以根据自己的需要,参考第 7-9 行的代码,判断一个参数是否存在,如果存在就添加到操作那里,需要注意的是 $actions[ ] 里的参数应该是唯一的。使用 “$user_object->对象”来获取信息,比如上面的 $user_object->user_url 获取的是用户的网址。

来源:

https://www.wpdaxue.com/user-row-actions.html

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?