【预留存档】移除 WordPress 中的「找回密码」功能

在某些场景中我们需要将WordPress中的「找回密码」/「更改密码」功能去掉——即登录页面中找不到链接,实际访问中也无法使用。来看下具体代码:

以下代码将仅允许管理员用户使用「找回密码」/「更改密码」功能

<?php
class Password_Reset_Removed
{
  function __construct()
  {
    add_filter( 'show_password_fields', array( $this, 'disable' ) );
    add_filter( 'allow_password_reset', array( $this, 'disable' ) );
    add_filter( 'gettext',              array( $this, 'remove' ) );
  }
  function disable()
  {
    if ( is_admin() ) {
      $userdata = wp_get_current_user();
      $user = new WP_User($userdata->ID);
      if ( !emptyempty( $user->roles ) && is_array( $user->roles ) && $user->roles[0] == 'administrator' )
        return true;
    }
    return false;
  }
  function remove($text)
  {
    return str_replace( array('Lost your password?', 'Lost your password'), '', trim($text, '?') );
  }
}
$pass_reset_removed = new Password_Reset_Removed();
?>

温馨提示:本文最后更新于2017年8月28日,已超过 2 年没有更新,如果文章内容或图片资源失效,请留言反馈,源码下载吧会及时处理,谢谢!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
Warning: strpos() expects parameter 1 to be string, array given in /home/wwwroot/AMH_PHP7.4/domain/LULA_YMXZB/web/wp-content/themes/YMXZB/modules/common/Post.php on line 441 Warning: strpos() expects parameter 1 to be string, array given in /home/wwwroot/AMH_PHP7.4/domain/LULA_YMXZB/web/wp-content/themes/YMXZB/modules/common/Post.php on line 441
上一篇

WordPress中文图片自动重命名的3种方法汇总

2020-10-12 1:06:39

下一篇

【预留存档】WordPress 屏蔽后台仪表盘无用模块、导航栏“显示选项”和“帮助”选项卡

2020-10-12 1:58:38