PHPackages                             sirbrillig/phpcs-no-get-current-user - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. sirbrillig/phpcs-no-get-current-user

ActivePhpcodesniffer-standard

sirbrillig/phpcs-no-get-current-user
====================================

A phpcs sniff to disallow get\_current\_user.

v1.1.1(1y ago)3101.5k↓47.6%BSD-2-ClausePHPPHP ^7.0 || ^8.0

Since Jan 18Pushed 1y agoCompare

[ Source](https://github.com/sirbrillig/phpcs-no-get-current-user)[ Packagist](https://packagist.org/packages/sirbrillig/phpcs-no-get-current-user)[ RSS](/packages/sirbrillig-phpcs-no-get-current-user/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

NoGetCurrentUser
================

[](#nogetcurrentuser)

A [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) sniff to disallow using `get_current_user()`.

Particularly when using a PHP framework like WordPress, it's very unlikely that most code will want to use the PHP function `get_current_user()`. It can also easily be confused with other framework functions like WordPress's `wp_get_current_user()`. This sniff makes using the function an error, although legitimate uses can still be made if the sniff is disabled for specific lines.

Installation
------------

[](#installation)

To use these rules in a project which is set up using [composer](https://href.li/?https://getcomposer.org/), we recommend using the [phpcodesniffer-composer-installer library](https://href.li/?https://github.com/DealerDirect/phpcodesniffer-composer-installer) which will automatically use all installed standards in the current project with the composer type `phpcodesniffer-standard` when you run phpcs.

```
composer require --dev squizlabs/php_codesniffer dealerdirect/phpcodesniffer-composer-installer
composer require --dev sirbrillig/phpcs-no-get-current-user

```

Configuration
-------------

[](#configuration)

When installing sniff standards in a project, you edit a `phpcs.xml` file with the `rule` tag inside the `ruleset` tag. The `ref` attribute of that tag should specify a standard, category, sniff, or error code to enable. It’s also possible to use these tags to disable or modify certain rules. The [official annotated file](https://href.li/?https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml) explains how to do this.

```

 My library.

```

Sniff Codes
-----------

[](#sniff-codes)

There is one sniff code that is reported by this sniff.

- `NoGetCurrentUser.Disallowed.NoGetCurrentUser.Found`

In any given file, you can use phpcs comments to disable these sniffs. For example:

```
$php_user = get_current_user(); // phpcs:ignore NoGetCurrentUser.Disallowed.NoGetCurrentUser.Found
```

For a whole file, you can ignore a sniff like this:

```
