: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace Yoast\WP\SEO\Routes;
use Yoast\WP\SEO\Actions\Configuration\First_Time_Configuration_Action;
use Yoast\WP\SEO\Conditionals\No_Conditionals;
* First_Time_Configuration_Route class.
class First_Time_Configuration_Route implements Route_Interface {
* Represents the first time configuration route.
public const CONFIGURATION_ROUTE = '/configuration';
* Represents a site representation route.
public const SITE_REPRESENTATION_ROUTE = '/site_representation';
* Represents a social profiles route.
public const SOCIAL_PROFILES_ROUTE = '/social_profiles';
* Represents a route to enable/disable tracking.
public const ENABLE_TRACKING_ROUTE = '/enable_tracking';
* Represents a route to check if current user has the correct capabilities to edit another user's profile.
public const CHECK_CAPABILITY_ROUTE = '/check_capability';
* Represents a route to save the first time configuration state.
public const SAVE_CONFIGURATION_STATE_ROUTE = '/save_configuration_state';
* Represents a route to save the first time configuration state.
public const GET_CONFIGURATION_STATE_ROUTE = '/get_configuration_state';
* The first tinme configuration action.
* @var First_Time_Configuration_Action
private $first_time_configuration_action;
* First_Time_Configuration_Route constructor.
* @param First_Time_Configuration_Action $first_time_configuration_action The first-time configuration action.
public function __construct(
First_Time_Configuration_Action $first_time_configuration_action
$this->first_time_configuration_action = $first_time_configuration_action;
* Registers routes with WordPress.
public function register_routes() {
$site_representation_route = [
'callback' => [ $this, 'set_site_representation' ],
'permission_callback' => [ $this, 'can_manage_options' ],
'company_or_person_user_id' => [
\register_rest_route( Main::API_V1_NAMESPACE, self::CONFIGURATION_ROUTE . self::SITE_REPRESENTATION_ROUTE, $site_representation_route );
$social_profiles_route = [
'callback' => [ $this, 'set_social_profiles' ],
'permission_callback' => [ $this, 'can_manage_options' ],
\register_rest_route( Main::API_V1_NAMESPACE, self::CONFIGURATION_ROUTE . self::SOCIAL_PROFILES_ROUTE, $social_profiles_route );
$check_capability_route = [
'callback' => [ $this, 'check_capability' ],
'permission_callback' => [ $this, 'can_manage_options' ],
\register_rest_route( Main::API_V1_NAMESPACE, self::CONFIGURATION_ROUTE . self::CHECK_CAPABILITY_ROUTE, $check_capability_route );
$enable_tracking_route = [
'callback' => [ $this, 'set_enable_tracking' ],
'permission_callback' => [ $this, 'can_manage_options' ],
\register_rest_route( Main::API_V1_NAMESPACE, self::CONFIGURATION_ROUTE . self::ENABLE_TRACKING_ROUTE, $enable_tracking_route );
$save_configuration_state_route = [
'callback' => [ $this, 'save_configuration_state' ],
'permission_callback' => [ $this, 'can_manage_options' ],
\register_rest_route( Main::API_V1_NAMESPACE, self::CONFIGURATION_ROUTE . self::SAVE_CONFIGURATION_STATE_ROUTE, $save_configuration_state_route );
$get_configuration_state_route = [
'callback' => [ $this, 'get_configuration_state' ],
'permission_callback' => [ $this, 'can_manage_options' ],
\register_rest_route( Main::API_V1_NAMESPACE, self::CONFIGURATION_ROUTE . self::GET_CONFIGURATION_STATE_ROUTE, $get_configuration_state_route );
* Sets the site representation values.
* @param WP_REST_Request $request The request.
* @return WP_REST_Response
public function set_site_representation( WP_REST_Request $request ) {
->first_time_configuration_action
->set_site_representation( $request->get_json_params() );
return new WP_REST_Response( $data, $data->status );
* Sets the social profiles values.
* @param WP_REST_Request $request The request.
* @return WP_REST_Response
public function set_social_profiles( WP_REST_Request $request ) {
->first_time_configuration_action
->set_social_profiles( $request->get_json_params() );
return new WP_REST_Response(
* Checks if the current user has the correct capability to edit a specific user.
* @param WP_REST_Request $request The request.
* @return WP_REST_Response
public function check_capability( WP_REST_Request $request ) {
->first_time_configuration_action
->check_capability( $request->get_param( 'user_id' ) );
return new WP_REST_Response( $data );
* Enables or disables tracking.
* @param WP_REST_Request $request The request.
* @return WP_REST_Response
public function set_enable_tracking( WP_REST_Request $request ) {
->first_time_configuration_action
->set_enable_tracking( $request->get_json_params() );
return new WP_REST_Response( $data, $data->status );
* Checks if the current user has the right capability.
public function can_manage_options() {
return \current_user_can( 'wpseo_manage_options' );
* Checks if the current user has the capability to edit a specific user.
* @param WP_REST_Request $request The request.
public function can_edit_user( WP_REST_Request $request ) {
$response = $this->first_time_configuration_action->check_capability( $request->get_param( 'user_id' ) );
return $response->success;
* Checks if the current user has the capability to edit posts of other users.
public function can_edit_other_posts() {
return \current_user_can( 'edit_others_posts' );
* Saves the first time configuration state.
* @param WP_REST_Request $request The request.
* @return WP_REST_Response
public function save_configuration_state( WP_REST_Request $request ) {
->first_time_configuration_action
->save_configuration_state( $request->get_json_params() );
return new WP_REST_Response( $data, $data->status );
* Returns the first time configuration state.
* @return WP_REST_Response the state of the configuration.
public function get_configuration_state() {
->first_time_configuration_action
->get_configuration_state();
return new WP_REST_Response( $data, $data->status );