Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPCS 3.0 #111

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"codeception/module-db": "^1.0",
"codeception/module-webdriver": "^1.0",
"codeception/util-universalframework": "^1.0",
"dealerdirect/phpcodesniffer-composer-installer": "0.7.2",
"ergebnis/composer-normalize": "^2",
"johnbillion/plugin-infrastructure": "dev-trunk",
"lucatume/wp-browser": "^3.0.21",
Expand All @@ -39,9 +38,8 @@
"phpstan/phpstan-phpunit": "^1.0",
"roots/wordpress-core-installer": "^1.0.0",
"roots/wordpress-full": "*",
"squizlabs/php_codesniffer": "3.7.1",
"szepeviktor/phpstan-wordpress": "1.3.0",
"wp-coding-standards/wpcs": "2.3.0"
"wp-coding-standards/wpcs": "^3.0.0"
},
"autoload-dev": {
"psr-4": {
Expand All @@ -51,9 +49,9 @@
"config": {
"allow-plugins": {
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true,
"roots/wordpress-core-installer": true
"roots/wordpress-core-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true
},
"classmap-authoritative": true,
"preferred-install": "dist",
Expand Down Expand Up @@ -84,7 +82,7 @@
"integration-tests"
],
"test:phpcs": [
"phpcs -nps --colors --report-code --report-summary --report-width=80 --cache=tests/cache/phpcs.json --basepath='./' ."
"phpcs -ps --colors --report-code --report-summary --report-width=80 --basepath='./' ."
],
"test:phpstan": [
"codecept build",
Expand Down
20 changes: 14 additions & 6 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0"?>
<ruleset name="User Switching">
<arg name="cache" value="tests/cache/phpcs.json"/>

<config name="minimum_wp_version" value="5.1"/>
<config name="testVersion" value="7.2-"/>

<!--
Expand All @@ -27,34 +29,40 @@
<exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
<exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
<exclude name="PEAR.Functions.FunctionCallSignature.MultipleArguments" />
<exclude name="Universal.Files.SeparateFunctionsFromOO.Mixed" />

<!-- These are all false positives: -->
<exclude name="WordPress.Security.NonceVerification.Recommended" />

<!-- Sanity: -->
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning" />
<exclude name="WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned" />
<exclude name="WordPress.PHP.YodaConditions.NotYoda" />
</rule>

<rule ref="WordPress-Docs" />

<rule ref="WordPress.Security.EscapeOutput">
<properties>
<property type="array" name="customAutoEscapedFunctions" value="bp_get_button"/>
<property name="customAutoEscapedFunctions" type="array">
<element value="bp_get_button"/>
</property>
</properties>
</rule>

<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array" value="user-switching"/>
<property name="text_domain" type="array">
<element value="user-switching"/>
</property>
</properties>
</rule>

<rule ref="WordPress.WP.DeprecatedFunctions">
<rule ref="WordPress.WP.Capabilities">
<properties>
<property name="minimum_supported_version" value="5.1" />
<property name="custom_capabilities" type="array">
<element value="switch_to_user"/>
<element value="switch_off"/>
</property>
</properties>
</rule>

</ruleset>
7 changes: 2 additions & 5 deletions user-switching.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
* Main singleton class for the User Switching plugin.
*/
class user_switching {

/**
* The name used to identify the application during a WordPress redirect.
*
Expand Down Expand Up @@ -1195,7 +1194,6 @@ public static function get_instance() {
* Private class constructor. Use `get_instance()` to get the instance.
*/
private function __construct() {}

}

if ( ! function_exists( 'user_switching_set_olduser_cookie' ) ) {
Expand Down Expand Up @@ -1404,16 +1402,15 @@ function switch_to_user( $user_id, $remember = false, $set_old_user = true ) {
* Attaches the original user ID and session token to the new session when a user switches to another user.
*
* @param array<string, mixed> $session Array of extra data.
* @param int $user_id User ID.
* @return array<string, mixed> Array of extra data.
*/
$session_filter = function( array $session, $user_id ) use ( $old_user_id, $old_token ) {
$session_filter = function ( array $session ) use ( $old_user_id, $old_token ) {
$session['switched_from_id'] = $old_user_id;
$session['switched_from_session'] = $old_token;
return $session;
};

add_filter( 'attach_session_information', $session_filter, 99, 2 );
add_filter( 'attach_session_information', $session_filter, 99 );

wp_clear_auth_cookie();
wp_set_auth_cookie( $user_id, $remember, '', $new_token );
Expand Down