我已经在wordpress中创建了一个公共帐户,我将发送给100个用户。
因此登录为:
禁用一个帐户的个人资料编辑
用户名:公共
密码:123example
我想的唯一一件事就是隐藏这个特定的用户帐户的个人资料页面,使他们不能更改密码,的emailadress等
如何实现这一目标?也许改变一些PHP?
我已经在wordpress中创建了一个公共帐户,我将发送给100个用户。
因此登录为:
禁用一个帐户的个人资料编辑
用户名:公共
密码:123example
我想的唯一一件事就是隐藏这个特定的用户帐户的个人资料页面,使他们不能更改密码,的emailadress等
如何实现这一目标?也许改变一些PHP?
该脚本涵盖了问题的所有方面,阅读代码注释以获得进一步的解释。
<?php
/**
* this make sure the public user where redirected
* to home instead of profile page
*/
function redirect_user_to($redirect_to, $request, $user)
{
global $user;
if ($user->user_login == 'public') {
return home_url();
}
else {
return home_url("/wp-admin/");
}
}
add_filter('login_redirect', 'redirect_user_to', 10, 3);
/**
* this remove the profile links from
* the top nav menu
*/
function remove_edit_profile()
{
global $wp_admin_bar, $current_user;
get_currentuserinfo();
if ($current_user->user_login == 'public') {
$wp_admin_bar->remove_menu('edit-profile');
$wp_admin_bar->remove_menu('my-account-with-avatar');
$wp_admin_bar->remove_menu('my-account');
}
}
add_action('wp_before_admin_bar_render', 'remove_edit_profile', 0);
/**
* this remove the "Site Admin" link from
* the WP meta widget, usually placed in
* the side bar.
*/
function my_unregister_widgets()
{
unregister_widget('WP_Widget_Meta');
register_widget('MY_Widget_Meta');
}
add_action('widgets_init', 'my_unregister_widgets');
class MY_Widget_Meta extends WP_Widget
{
function MY_Widget_Meta()
{
$widget_ops = array(
'classname' => 'widget_meta',
'description' => __("Log in/out, admin, feed and WordPress links"),
);
$this->WP_Widget('meta', __('Meta'), $widget_ops);
}
function widget($args, $instance)
{
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title']);
echo $before_widget;
if ($title) {
echo $before_title.$title.$after_title;
}
?>
<ul>
<?php
global $current_user;
get_currentuserinfo();
if ($current_user->user_login == 'public') {
}
else {
wp_register();
}
?>
<li>
<?php wp_loginout();?>
</li>
<li>
<a href="<?php bloginfo('rss2_url');?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0'));?>">
<?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>');?></a>
</li>
<li>
<a href="<?php bloginfo('comments_rss2_url');?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS'));?>">
<?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>');?></a>
</li>
<li>
<a href="http://wordpress.org/" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.'));?>">WordPress.org</a>
</li>
<?php wp_meta();?>
</ul>
<?php
echo $after_widget;
}
}
/**
* this prevent from non authorized user (public)
* to pointing to the profile page by writing into
* the address bar.
*/
function force_profile_redirect()
{
global $pagenow, $current_user;
if (strtolower($current_user->user_login) == 'public') {
wp_redirect(home_url());
}
}
add_action('admin_init', 'force_profile_redirect');
?>
你需要修改你的个人资料页面的代码,使之不显示可编辑区域,而不是运行“更新配置文件”操作,如果用户ID是[XYZ]。
对于那些实际执行配置文件的更新页面,你可以把在顶部像
// Change this line to match however you identify your logged-in user
// And change the id number to the ID of the public user
global $current_user;
get_currentuserinfo();
if ($current_user->ID == 1)
{
// Stop them seeing this page
header('Location: index.php');
// And for good measure
die();
}
有关他们提交表单,才可以更改配置文件字段的页面,你可以做这样的事情
// Change this line to match however you identify your logged-in user
// And change the id number to the ID of the public user
global $current_user;
get_currentuserinfo();
if ($current_user->ID == 1)
{
// Say no
echo '<p>You cannot edit your profile on this account.</p>';
// And for good measure
die();
}
没有看到你的代码,它很难成为更具体的,但这应该在推动工作,即使它不完全是你怎么想它的工作。
@ aSeptik的答案的最后部分可能会多一点WP友好。
function force_profile_redirect() {
global $pagenow, $current_user;
get_currentuserinfo();
if ($pagenow == 'profile.php' && $current_user->user_login == 'public') {
wp_redirect(home_url());
}
}
add_action('admin_init', 'force_profile_redirect');
在脚本中有两件事你不需要。一个是get_currentuserinfo();然后$ pagenow =='profile.php' –
工程就像一个魅力!谢谢aepep! – Justmac
这里的最后一个重定向部分可能会更友善些,尽管性能下降很小。 Arg,请参阅下面的代码我的答案。 – Evan