Commit 4434ed6110f for woocommerce

commit 4434ed6110fe41834f1420512b8874e1c7891cfa
Author: Warren Holmes <warren.holmes@automattic.com>
Date:   Wed May 27 17:19:40 2026 +0800

    Remove obsolete "Product reviews have moved!" admin notice (#65110)

diff --git a/plugins/woocommerce/changelog/remove-reviews-moved-notice b/plugins/woocommerce/changelog/remove-reviews-moved-notice
new file mode 100644
index 00000000000..b5aaefc1f56
--- /dev/null
+++ b/plugins/woocommerce/changelog/remove-reviews-moved-notice
@@ -0,0 +1,4 @@
+Significance: patch
+Type: tweak
+
+Remove the obsolete 'Product reviews have moved!' notice from the Comments screen.
diff --git a/plugins/woocommerce/src/Internal/Admin/ProductReviews/ReviewsCommentsOverrides.php b/plugins/woocommerce/src/Internal/Admin/ProductReviews/ReviewsCommentsOverrides.php
index 1ff056b81a4..d1eb1ba12ad 100644
--- a/plugins/woocommerce/src/Internal/Admin/ProductReviews/ReviewsCommentsOverrides.php
+++ b/plugins/woocommerce/src/Internal/Admin/ProductReviews/ReviewsCommentsOverrides.php
@@ -10,113 +10,13 @@ use WP_Screen;
  */
 class ReviewsCommentsOverrides {

-	const REVIEWS_MOVED_NOTICE_ID = 'product_reviews_moved';
-
 	/**
 	 * Constructor.
 	 */
 	public function __construct() {
-		add_action( 'admin_notices', array( $this, 'display_notices' ) );
-		add_filter( 'woocommerce_dismiss_admin_notice_capability', array( $this, 'get_dismiss_capability' ), 10, 2 );
 		add_filter( 'comments_list_table_query_args', array( $this, 'exclude_reviews_from_comments' ) );
 	}

-	/**
-	 * Renders admin notices.
-	 *
-	 * @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
-	 */
-	public function display_notices(): void {
-		$screen = get_current_screen();
-
-		if ( empty( $screen ) || $screen->base !== 'edit-comments' ) {
-			return;
-		}
-
-		$this->maybe_display_reviews_moved_notice();
-	}
-
-	/**
-	 * May render an admin notice informing the user that reviews were moved to a new page.
-	 *
-	 * @return void
-	 */
-	protected function maybe_display_reviews_moved_notice() : void {
-		if ( $this->should_display_reviews_moved_notice() ) {
-			$this->display_reviews_moved_notice();
-		}
-	}
-
-	/**
-	 * Checks if the admin notice informing the user that reviews were moved to a new page should be displayed.
-	 *
-	 * @return bool
-	 */
-	protected function should_display_reviews_moved_notice() : bool {
-		// Do not display if the user does not have the capability  to see the new page.
-		if ( ! WC()->call_function( 'current_user_can', Reviews::get_capability() ) ) {
-			return false;
-		}
-
-		// Do not display if the current user has dismissed this notice.
-		if ( WC()->call_function( 'get_user_meta', get_current_user_id(), 'dismissed_' . static::REVIEWS_MOVED_NOTICE_ID . '_notice', true ) ) {
-			return false;
-		}
-
-		return true;
-	}
-
-	/**
-	 * Renders an admin notice informing the user that reviews were moved to a new page.
-	 *
-	 * @return void
-	 */
-	protected function display_reviews_moved_notice() : void {
-		?>
-		<div class="notice notice-info is-dismissible">
-			<p><strong><?php esc_html_e( 'Product reviews have moved!', 'woocommerce' ); ?></strong></p>
-			<p><?php esc_html_e( 'Product reviews can now be managed from Products > Reviews.', 'woocommerce' ); ?></p>
-			<p class="submit">
-				<a href="<?php echo esc_url( admin_url( 'edit.php?post_type=product&page=product-reviews' ) ); ?>" class="button-primary"><?php esc_html_e( 'Visit new location', 'woocommerce' ); ?></a>
-			</p>
-
-			<form action="<?php echo esc_url( admin_url( 'edit-comments.php' ) ); ?>" method="get">
-				<input type="hidden" name="wc-hide-notice" value="<?php echo esc_attr( static::REVIEWS_MOVED_NOTICE_ID ); ?>" />
-
-				<?php if ( ! empty( $_GET['comment_status'] ) ): ?>
-					<input type="hidden" name="comment_status" value="<?php echo esc_attr( $_GET['comment_status'] ); ?>" />
-				<?php endif; ?>
-
-				<?php if ( ! empty( $_GET['paged'] ) ): ?>
-					<input type="hidden" name="paged" value="<?php echo esc_attr( $_GET['paged'] ); ?>" />
-				<?php endif; ?>
-
-				<?php wp_nonce_field( 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ); ?>
-
-				<button type="submit" class="notice-dismiss">
-					<span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice.', 'woocommerce' ); ?></span>
-				</button>
-			</form>
-		</div>
-		<?php
-	}
-
-	/**
-	 * Gets the capability required to dismiss the notice.
-	 *
-	 * This is required so that users who do not have the manage_woocommerce capability (e.g. Editors) can still dismiss
-	 * the notice displayed in the Comments page.
-	 *
-	 * @param string|mixed $default_capability The default required capability.
-	 * @param string|mixed $notice_name The notice name.
-	 * @return string
-	 *
-	 * @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
-	 */
-	public function get_dismiss_capability( $default_capability, $notice_name ) {
-		return $notice_name === self::REVIEWS_MOVED_NOTICE_ID ? Reviews::get_capability() : $default_capability;
-	}
-
 	/**
 	 * Excludes product reviews from showing in the comments page.
 	 *
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsCommentsOverridesTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsCommentsOverridesTest.php
index c2098e02767..a7a550ecec3 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsCommentsOverridesTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsCommentsOverridesTest.php
@@ -3,7 +3,6 @@
 namespace Automattic\WooCommerce\Tests\Internal\Admin\ProductReviews;

 use Automattic\WooCommerce\Internal\Admin\ProductReviews\ReviewsCommentsOverrides;
-use Generator;
 use ReflectionClass;
 use ReflectionException;
 use WC_Unit_Test_Case;
@@ -38,203 +37,6 @@ class ReviewsCommentsOverridesTest extends WC_Unit_Test_Case {
 		parent::tearDown();
 	}

-	/**
-	 * @testdox `display_notices` determines whether to display notices for the $current_screen_base.
-	 *
-	 * @covers \Automattic\WooCommerce\Internal\Admin\ProductReviews\ReviewsCommentsOverrides::display_notices()
-	 * @dataProvider provider_test_display_notices()
-	 *
-	 * @param string $current_screen_base    The current WP_Screen base value.
-	 * @param bool   $should_display_notices Whether notices should be displayed.
-	 *
-	 * @return void
-	 * @throws ReflectionException If the method doesn't exist.
-	 */
-	public function test_display_notices( string $current_screen_base, bool $should_display_notices ) : void {
-		global $current_screen;
-
-		$current_screen = \WP_Screen::get( $current_screen_base ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
-
-		// phpcs:disable Squiz.Commenting
-		$instance = new class() extends ReviewsCommentsOverrides {
-			public $maybe_display_reviews_moved_notice_called = 0;
-
-			protected function maybe_display_reviews_moved_notice() : void {
-				$this->maybe_display_reviews_moved_notice_called++;
-			}
-		};
-		// phpcs:enable Squiz.Commenting
-
-		$method = ( new ReflectionClass( $instance ) )->getMethod( 'display_notices' );
-		$method->setAccessible( true );
-
-		$method->invoke( $instance );
-
-		$this->assertSame( (int) $should_display_notices, $instance->maybe_display_reviews_moved_notice_called );
-	}
-
-	/** @see test_display_notices() */
-	public function provider_test_display_notices() : Generator {
-		yield 'Comments page' => [ 'edit-comments', true ];
-		yield 'Posts page' => [ 'edit', false ];
-		yield 'Product Reviews page' => [ 'product_page_product-reviews', false ];
-	}
-
-	/**
-	 * @testdox `maybe_display_reviews_moved_notice` displays the notice if the $current_screen_base is 'edit-comments'.
-	 *
-	 * @covers \Automattic\WooCommerce\Internal\Admin\ProductReviews\ReviewsCommentsOverrides::maybe_display_reviews_moved_notice()
-	 * @dataProvider provider_test_maybe_display_reviews_moved_notice()
-	 *
-	 * @param bool $should_display_notice Whether the reviews moved notice should be displayed.
-	 *
-	 * @return void
-	 * @throws ReflectionException If the method is not found.
-	 */
-	public function test_maybe_display_reviews_moved_notice( bool $should_display_notice ) : void {
-
-		// phpcs:disable Squiz.Commenting
-		$instance = new class($should_display_notice) extends ReviewsCommentsOverrides {
-			public $should_display_reviews_moved_notice_called = 0;
-			public $display_reviews_moved_notice_called = 0;
-
-			public function __construct( $should_display_notice ) {
-				$this->should_display_notice = $should_display_notice;
-				parent::__construct();
-			}
-
-			protected function should_display_reviews_moved_notice() : bool {
-				$this->should_display_reviews_moved_notice_called++;
-				return $this->should_display_notice;
-			}
-
-			protected function display_reviews_moved_notice() : void {
-				$this->display_reviews_moved_notice_called++;
-			}
-		};
-		// phpcs:enable Squiz.Commenting
-
-		$reflection = new ReflectionClass( $instance );
-		$method = $reflection->getMethod( 'maybe_display_reviews_moved_notice' );
-		$method->setAccessible( true );
-
-		$method->invoke( $instance );
-
-		$this->assertSame( 1, $instance->should_display_reviews_moved_notice_called );
-		$this->assertSame( (int) $should_display_notice, $instance->display_reviews_moved_notice_called );
-	}
-
-	/** @see test_maybe_display_reviews_moved_notice() */
-	public function provider_test_maybe_display_reviews_moved_notice() : Generator {
-		yield [ true ];
-		yield [ false ];
-	}
-
-	/**
-	 * @testdox `maybe_display_reviews_moved_notice` determines whether the notice should be displayed based on user capabilities and notice dismissal state.
-	 *
-	 * @covers \Automattic\WooCommerce\Internal\Admin\ProductReviews\ReviewsCommentsOverrides::should_display_reviews_moved_notice()
-	 * @dataProvider provider_test_should_display_reviews_moved_notice()
-	 *
-	 * @param bool $user_has_capability       Whether the user has the capability to see the new page.
-	 * @param bool $user_has_dismissed_notice Whether the user has dismissed this notice before.
-	 * @param bool $expected                  Whether the reviews moved notice should be displayed.
-	 *
-	 * @return void
-	 * @throws ReflectionException Throws if the method is not accessible.
-	 */
-	public function test_should_display_reviews_moved_notice( bool $user_has_capability, bool $user_has_dismissed_notice, bool $expected ) : void {
-		$this->register_legacy_proxy_function_mocks(
-			[
-				'current_user_can' => function( $capability, ...$args ) use ( $user_has_capability ) {
-					if ( 'moderate_comments' === $capability ) {
-						return $user_has_capability;
-					} else {
-						return current_user_can( $capability, $args );
-					}
-				},
-				'get_user_meta' => function ( int $user_id, string $key = '', bool $single = false ) use ( $user_has_dismissed_notice ) {
-					if ( 'dismissed_product_reviews_moved_notice' === $key ) {
-						return $user_has_dismissed_notice;
-					} else {
-						return get_user_meta( $user_id, $key, $single );
-					}
-				},
-			]
-		);
-
-		$reflection = new ReflectionClass( ReviewsCommentsOverrides::class );
-		$method = $reflection->getMethod( 'should_display_reviews_moved_notice' );
-		$method->setAccessible( true );
-
-		$should_display_notice = $method->invoke( wc_get_container()->get( ReviewsCommentsOverrides::class ) );
-
-		$this->assertSame( $expected, $should_display_notice );
-	}
-
-	/** @see test_should_display_reviews_moved_notice() */
-	public function provider_test_should_display_reviews_moved_notice() : Generator {
-		yield 'user does not have the capability to see the new page' => [ false, false, false ];
-		yield 'user already dismissed this notice' => [ true, true, false ];
-		yield 'user has the capability and have not dismissed the notice' => [ true, false, true ];
-	}
-
-	/**
-	 * @testdox `display_reviews_moved_notice` displays the notice.
-	 *
-	 * @covers \Automattic\WooCommerce\Internal\Admin\ProductReviews\ReviewsCommentsOverrides::display_reviews_moved_notice()
-	 *
-	 * @return void
-	 * @throws ReflectionException Thrown when the method does not exist.
-	 */
-	public function test_display_reviews_moved_notice() : void {
-		$overrides = wc_get_container()->get( ReviewsCommentsOverrides::class );
-		$method = ( new ReflectionClass( $overrides ) )->getMethod( 'display_reviews_moved_notice' );
-		$method->setAccessible( true );
-
-		ob_start();
-
-		$method->invoke( $overrides );
-
-		$output = trim( ob_get_clean() );
-
-		$nonce = wp_create_nonce( 'woocommerce_hide_notices_nonce' );
-
-		$this->assertStringContainsString( '<div class="notice notice-info is-dismissible">', $output );
-		$this->assertStringContainsString( '<a href="http://' . WP_TESTS_DOMAIN . '/wp-admin/edit.php?post_type=product&#038;page=product-reviews" class="button-primary">', $output );
-		$this->assertStringContainsString( '<input type="hidden" name="wc-hide-notice" value="product_reviews_moved" />', $output );
-		$this->assertStringContainsString( '<input type="hidden" id="_wc_notice_nonce" name="_wc_notice_nonce" value="' . $nonce . '" />', $output );
-		$this->assertStringNotContainsString( 'onclick', $output );
-	}
-
-	/**
-	 * @testdox `get_dismiss_capability` returns the $expected_capability user capability for dismissing a $notice_name.
-	 *
-	 * @covers \Automattic\WooCommerce\Internal\Admin\ProductReviews\ReviewsCommentsOverrides::get_dismiss_capability()
-	 * @dataProvider provider_test_get_dismiss_capability()
-	 *
-	 * @param string $default_capability The default required capability.
-	 * @param string $notice_name The notice name.
-	 * @param string $expected_capability The expected capability.
-	 *
-	 * @return void
-	 * @throws ReflectionException If the method doesn't exist.
-	 */
-	public function test_get_dismiss_capability( string $default_capability, string $notice_name, string $expected_capability ) : void {
-		$overrides = wc_get_container()->get( ReviewsCommentsOverrides::class );
-
-		$method = ( new ReflectionClass( $overrides ) )->getMethod( 'get_dismiss_capability' );
-		$method->setAccessible( true );
-
-		$this->assertSame( $expected_capability, $method->invoke( $overrides, $default_capability, $notice_name ) );
-	}
-
-	/** @see test_get_dismiss_capability() */
-	public function provider_test_get_dismiss_capability() : Generator {
-		yield 'another notice' => [ 'manage_woocommerce', 'other_notice', 'manage_woocommerce' ];
-		yield 'product reviews moved notice' => [ 'manage_woocommerce', ReviewsCommentsOverrides::REVIEWS_MOVED_NOTICE_ID, 'moderate_comments' ];
-	}
-
 	/**
 	 * @testdox `exclude_reviews_from_comments` excludes product reviews from the comment query in the comments page.
 	 *