Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../src/introduc.../user-int...
File: introductions-seen-route.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Introductions\User_Interface;
[2] Fix | Delete
[3] Fix | Delete
use Exception;
[4] Fix | Delete
use WP_Error;
[5] Fix | Delete
use WP_REST_Request;
[6] Fix | Delete
use WP_REST_Response;
[7] Fix | Delete
use Yoast\WP\SEO\Conditionals\No_Conditionals;
[8] Fix | Delete
use Yoast\WP\SEO\Helpers\User_Helper;
[9] Fix | Delete
use Yoast\WP\SEO\Introductions\Application\Introductions_Collector;
[10] Fix | Delete
use Yoast\WP\SEO\Introductions\Infrastructure\Introductions_Seen_Repository;
[11] Fix | Delete
use Yoast\WP\SEO\Main;
[12] Fix | Delete
use Yoast\WP\SEO\Routes\Route_Interface;
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Registers a route to set whether the user has seen an introduction.
[16] Fix | Delete
*
[17] Fix | Delete
* @makePublic
[18] Fix | Delete
*/
[19] Fix | Delete
class Introductions_Seen_Route implements Route_Interface {
[20] Fix | Delete
[21] Fix | Delete
use No_Conditionals;
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Represents the prefix.
[25] Fix | Delete
*
[26] Fix | Delete
* @var string
[27] Fix | Delete
*/
[28] Fix | Delete
public const ROUTE_PREFIX = '/introductions/(?P<introduction_id>[\w-]+)/seen';
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Holds the introductions collector instance.
[32] Fix | Delete
*
[33] Fix | Delete
* @var Introductions_Collector
[34] Fix | Delete
*/
[35] Fix | Delete
private $introductions_collector;
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Holds the repository.
[39] Fix | Delete
*
[40] Fix | Delete
* @var Introductions_Seen_Repository
[41] Fix | Delete
*/
[42] Fix | Delete
private $introductions_seen_repository;
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Holds the user helper.
[46] Fix | Delete
*
[47] Fix | Delete
* @var User_Helper
[48] Fix | Delete
*/
[49] Fix | Delete
private $user_helper;
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Constructs the class.
[53] Fix | Delete
*
[54] Fix | Delete
* @param Introductions_Seen_Repository $introductions_seen_repository The repository.
[55] Fix | Delete
* @param User_Helper $user_helper The user helper.
[56] Fix | Delete
* @param Introductions_Collector $introductions_collector The introduction collector.
[57] Fix | Delete
*/
[58] Fix | Delete
public function __construct(
[59] Fix | Delete
Introductions_Seen_Repository $introductions_seen_repository,
[60] Fix | Delete
User_Helper $user_helper,
[61] Fix | Delete
Introductions_Collector $introductions_collector
[62] Fix | Delete
) {
[63] Fix | Delete
$this->introductions_seen_repository = $introductions_seen_repository;
[64] Fix | Delete
$this->user_helper = $user_helper;
[65] Fix | Delete
$this->introductions_collector = $introductions_collector;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Registers routes with WordPress.
[70] Fix | Delete
*
[71] Fix | Delete
* @return void
[72] Fix | Delete
*/
[73] Fix | Delete
public function register_routes() {
[74] Fix | Delete
\register_rest_route(
[75] Fix | Delete
Main::API_V1_NAMESPACE,
[76] Fix | Delete
self::ROUTE_PREFIX,
[77] Fix | Delete
[
[78] Fix | Delete
[
[79] Fix | Delete
'methods' => 'POST',
[80] Fix | Delete
'callback' => [ $this, 'set_introduction_seen' ],
[81] Fix | Delete
'permission_callback' => [ $this, 'permission_edit_posts' ],
[82] Fix | Delete
'args' => [
[83] Fix | Delete
'introduction_id' => [
[84] Fix | Delete
'required' => true,
[85] Fix | Delete
'type' => 'string',
[86] Fix | Delete
'sanitize_callback' => 'sanitize_text_field',
[87] Fix | Delete
],
[88] Fix | Delete
'is_seen' => [
[89] Fix | Delete
'required' => false,
[90] Fix | Delete
'type' => 'bool',
[91] Fix | Delete
'default' => true,
[92] Fix | Delete
'sanitize_callback' => 'rest_sanitize_boolean',
[93] Fix | Delete
],
[94] Fix | Delete
],
[95] Fix | Delete
],
[96] Fix | Delete
]
[97] Fix | Delete
);
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Sets whether the introduction is seen.
[102] Fix | Delete
*
[103] Fix | Delete
* @param WP_REST_Request $request The request object.
[104] Fix | Delete
*
[105] Fix | Delete
* @return WP_REST_Response|WP_Error The success or failure response.
[106] Fix | Delete
*/
[107] Fix | Delete
public function set_introduction_seen( WP_REST_Request $request ) {
[108] Fix | Delete
$params = $request->get_params();
[109] Fix | Delete
$introduction_id = $params['introduction_id'];
[110] Fix | Delete
$is_seen = $params['is_seen'];
[111] Fix | Delete
[112] Fix | Delete
if ( $this->introductions_collector->is_available_introduction( $introduction_id ) ) {
[113] Fix | Delete
try {
[114] Fix | Delete
$user_id = $this->user_helper->get_current_user_id();
[115] Fix | Delete
$result = $this->introductions_seen_repository->set_introduction( $user_id, $introduction_id, $is_seen );
[116] Fix | Delete
} catch ( Exception $exception ) {
[117] Fix | Delete
return new WP_Error(
[118] Fix | Delete
'wpseo_introductions_seen_error',
[119] Fix | Delete
$exception->getMessage(),
[120] Fix | Delete
(object) []
[121] Fix | Delete
);
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
return new WP_REST_Response(
[125] Fix | Delete
[
[126] Fix | Delete
'json' => (object) [
[127] Fix | Delete
'success' => $result,
[128] Fix | Delete
],
[129] Fix | Delete
],
[130] Fix | Delete
( $result ) ? 200 : 400
[131] Fix | Delete
);
[132] Fix | Delete
}
[133] Fix | Delete
return new WP_REST_Response( [], 400 );
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Permission callback.
[138] Fix | Delete
*
[139] Fix | Delete
* @return bool True when user has 'edit_posts' permission.
[140] Fix | Delete
*/
[141] Fix | Delete
public function permission_edit_posts() {
[142] Fix | Delete
return \current_user_can( 'edit_posts' );
[143] Fix | Delete
}
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function