From 2880d80e12c7c4440ce06d41d7cd25e6388e9243 Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Tue, 28 Feb 2023 16:16:31 -0800 Subject: [PATCH] Contributors: Don't send inactivity emails to banned users. Fixes #221 --- .env/0-sandbox.php | 2 ++ .gitignore | 1 + composer.json | 1 - plugins/wporg-5ftf/includes/contributor.php | 9 +++++++ plugins/wporg-5ftf/tests/bootstrap.php | 4 +++- plugins/wporg-5ftf/tests/test-contributor.php | 24 ++++++++++++++++--- 6 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.env/0-sandbox.php b/.env/0-sandbox.php index e7ccbdb..5d0efff 100644 --- a/.env/0-sandbox.php +++ b/.env/0-sandbox.php @@ -7,6 +7,8 @@ namespace { defined( 'WPINC' ) || die(); + define( 'WPORG_SUPPORT_FORUMS_BLOGID', 419 ); + /** * Stub. */ diff --git a/.gitignore b/.gitignore index 2440a9b..aba9404 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ plugins/* themes/wporg-5ftf/css/style.css themes/wporg-5ftf/css/style-editor.css themes/pub +themes/twenty* /uploads /db.php diff --git a/composer.json b/composer.json index 77b85d9..9e095c1 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ } }, "require": {}, - "_comment" : "PHPUnit 7.x is the latest version that's compatible with Core, see https://core.trac.wordpress.org/ticket/46149", "require-dev" : { "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "wp-coding-standards/wpcs": "2.3.*", diff --git a/plugins/wporg-5ftf/includes/contributor.php b/plugins/wporg-5ftf/includes/contributor.php index ec0d3a1..1347358 100644 --- a/plugins/wporg-5ftf/includes/contributor.php +++ b/plugins/wporg-5ftf/includes/contributor.php @@ -795,6 +795,15 @@ function prune_unnotifiable_users( array $contributors ) : array { unset( $contributors[ $index ] ); continue; } + + // bbPress is not active on this site, so fetch it directly from the database. + global $wpdb; + $forums_role = get_user_meta( $contributor['user_id'], $wpdb->base_prefix . WPORG_SUPPORT_FORUMS_BLOGID . '_capabilities', true ); + + if ( isset( $forums_role['bbp_blocked'] ) && true === $forums_role['bbp_blocked'] ) { + unset( $contributors[ $index ] ); + continue; + } } return $contributors; diff --git a/plugins/wporg-5ftf/tests/bootstrap.php b/plugins/wporg-5ftf/tests/bootstrap.php index 668a577..d101d4f 100755 --- a/plugins/wporg-5ftf/tests/bootstrap.php +++ b/plugins/wporg-5ftf/tests/bootstrap.php @@ -21,7 +21,9 @@ require_once $_tests_dir . '/includes/functions.php'; * Manually load the plugin being tested. */ function _manually_load_plugin() { - require dirname( dirname( __FILE__ ) ) . '/index.php'; + define( 'WPORG_SUPPORT_FORUMS_BLOGID', 1 ); + + require dirname( __FILE__, 2 ) . '/index.php'; require __DIR__ . '/helpers.php'; } tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); diff --git a/plugins/wporg-5ftf/tests/test-contributor.php b/plugins/wporg-5ftf/tests/test-contributor.php index d7fb76f..f2cb0f0 100644 --- a/plugins/wporg-5ftf/tests/test-contributor.php +++ b/plugins/wporg-5ftf/tests/test-contributor.php @@ -217,42 +217,60 @@ class Test_Contributor extends WP_UnitTestCase { * @covers WordPressDotOrg\FiveForTheFuture\Contributor\prune_unnotifiable_users */ public function test_prune_unnotifiable_users() { + global $wpdb; + + update_user_meta( + self::$users['kimi']->ID, + $wpdb->base_prefix . WPORG_SUPPORT_FORUMS_BLOGID . '_capabilities', + array( 'bbp_blocked' => true ) + ); + $contributors = array( 'active + due for email' => array( + 'user_id' => self::$users['jane']->ID, 'last_logged_in' => strtotime( '1 week ago' ), 'user_registered' => strtotime( '1 year ago' ), '5ftf_last_inactivity_email' => 0, ), 'active + not due for email' => array( + 'user_id' => self::$users['ashish']->ID, 'last_logged_in' => strtotime( '1 week ago' ), 'user_registered' => strtotime( '1 year ago' ), '5ftf_last_inactivity_email' => strtotime( '1 month ago' ), ), 'inactive + due for email' => array( + 'user_id' => self::$users['andrea']->ID, 'last_logged_in' => strtotime( '4 months ago' ), 'user_registered' => strtotime( '1 year ago' ), '5ftf_last_inactivity_email' => strtotime( '4 months ago' ), ), 'inactive + not due for email' => array( + 'user_id' => self::$users['caleb']->ID, 'last_logged_in' => strtotime( '4 months ago' ), 'user_registered' => strtotime( '1 year ago' ), '5ftf_last_inactivity_email' => strtotime( '2 months ago' ), ), 'new user' => array( + 'user_id' => self::$users['jane']->ID, 'last_logged_in' => 0, 'user_registered' => strtotime( '1 week ago' ), '5ftf_last_inactivity_email' => 0, ), + + 'inactive + blocked' => array( + 'user_id' => self::$users['kimi']->ID, + 'last_logged_in' => strtotime( '4 months ago' ), + 'user_registered' => strtotime( '1 year ago' ), + '5ftf_last_inactivity_email' => strtotime( '4 months ago' ), + ), ); $expected = array( 'inactive + due for email' ); - - $actual = Contributor\prune_unnotifiable_users( $contributors ); - + $actual = Contributor\prune_unnotifiable_users( $contributors ); $this->assertSame( $expected, array_keys( $actual ) ); } }