: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace Yoast\WP\SEO\Introductions\User_Interface;
use Yoast\WP\SEO\Conditionals\No_Conditionals;
use Yoast\WP\SEO\Helpers\User_Helper;
use Yoast\WP\SEO\Introductions\Application\Introductions_Collector;
use Yoast\WP\SEO\Introductions\Infrastructure\Introductions_Seen_Repository;
use Yoast\WP\SEO\Routes\Route_Interface;
* Registers a route to set whether the user has seen an introduction.
class Introductions_Seen_Route implements Route_Interface {
public const ROUTE_PREFIX = '/introductions/(?P<introduction_id>[\w-]+)/seen';
* Holds the introductions collector instance.
* @var Introductions_Collector
private $introductions_collector;
* @var Introductions_Seen_Repository
private $introductions_seen_repository;
* @param Introductions_Seen_Repository $introductions_seen_repository The repository.
* @param User_Helper $user_helper The user helper.
* @param Introductions_Collector $introductions_collector The introduction collector.
public function __construct(
Introductions_Seen_Repository $introductions_seen_repository,
User_Helper $user_helper,
Introductions_Collector $introductions_collector
$this->introductions_seen_repository = $introductions_seen_repository;
$this->user_helper = $user_helper;
$this->introductions_collector = $introductions_collector;
* Registers routes with WordPress.
public function register_routes() {
'callback' => [ $this, 'set_introduction_seen' ],
'permission_callback' => [ $this, 'permission_edit_posts' ],
'sanitize_callback' => 'sanitize_text_field',
'sanitize_callback' => 'rest_sanitize_boolean',
* Sets whether the introduction is seen.
* @param WP_REST_Request $request The request object.
* @return WP_REST_Response|WP_Error The success or failure response.
public function set_introduction_seen( WP_REST_Request $request ) {
$params = $request->get_params();
$introduction_id = $params['introduction_id'];
$is_seen = $params['is_seen'];
if ( $this->introductions_collector->is_available_introduction( $introduction_id ) ) {
$user_id = $this->user_helper->get_current_user_id();
$result = $this->introductions_seen_repository->set_introduction( $user_id, $introduction_id, $is_seen );
} catch ( Exception $exception ) {
'wpseo_introductions_seen_error',
$exception->getMessage(),
return new WP_REST_Response(
return new WP_REST_Response( [], 400 );
* @return bool True when user has 'edit_posts' permission.
public function permission_edit_posts() {
return \current_user_can( 'edit_posts' );