Отключить редактирование профиля для одного аккаунта - PullRequest
2 голосов
/ 12 сентября 2011

Я создал публичную учетную запись в WordPress, которую я отправлю 100 пользователям.
Таким образом, логин будет:

Имя пользователя: публичный
Пароль: 123example

Единственное, что я хочу - это скрыть страницу профиля для этой конкретной учетной записи, чтобы они не могли изменить пароль, адрес электронной почты и т. Д.

Как этого добиться? Может, поменять какой-нибудь php?

Ответы [ 3 ]

2 голосов
/ 25 января 2012

Последняя часть ответа @ 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');
1 голос
/ 23 сентября 2011

этот скрипт охватывает все аспекты вопроса, прочитайте комментарии к коду для дальнейшего объяснения.

<?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');
?>
1 голос
/ 12 сентября 2011

Вам необходимо изменить код страницы своего профиля, чтобы он не отображал редактируемые области, и не запускать действие «обновить профиль», если идентификатор пользователя [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();
}

Не видя ваш код, трудно быть более конкретным, но это должно сработать с опережением, даже если вы не совсем хотите, чтобы он работал.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...