我已經在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