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: wistia-embed-permission-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\Infrastructure\Wistia_Embed_Permission_Repository;
[10] Fix | Delete
use Yoast\WP\SEO\Main;
[11] Fix | Delete
use Yoast\WP\SEO\Routes\Route_Interface;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Registers a route to offer get/set of the wistia embed permission for a user.
[15] Fix | Delete
*/
[16] Fix | Delete
class Wistia_Embed_Permission_Route implements Route_Interface {
[17] Fix | Delete
[18] Fix | Delete
use No_Conditionals;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Represents the prefix.
[22] Fix | Delete
*
[23] Fix | Delete
* @var string
[24] Fix | Delete
*/
[25] Fix | Delete
public const ROUTE_PREFIX = '/wistia_embed_permission';
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Holds the repository.
[29] Fix | Delete
*
[30] Fix | Delete
* @var Wistia_Embed_Permission_Repository
[31] Fix | Delete
*/
[32] Fix | Delete
private $wistia_embed_permission_repository;
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Holds the user helper.
[36] Fix | Delete
*
[37] Fix | Delete
* @var User_Helper
[38] Fix | Delete
*/
[39] Fix | Delete
private $user_helper;
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Constructs the class.
[43] Fix | Delete
*
[44] Fix | Delete
* @param Wistia_Embed_Permission_Repository $wistia_embed_permission_repository The repository.
[45] Fix | Delete
* @param User_Helper $user_helper The user helper.
[46] Fix | Delete
*/
[47] Fix | Delete
public function __construct(
[48] Fix | Delete
Wistia_Embed_Permission_Repository $wistia_embed_permission_repository,
[49] Fix | Delete
User_Helper $user_helper
[50] Fix | Delete
) {
[51] Fix | Delete
$this->wistia_embed_permission_repository = $wistia_embed_permission_repository;
[52] Fix | Delete
$this->user_helper = $user_helper;
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Registers routes with WordPress.
[57] Fix | Delete
*
[58] Fix | Delete
* @return void
[59] Fix | Delete
*/
[60] Fix | Delete
public function register_routes() {
[61] Fix | Delete
\register_rest_route(
[62] Fix | Delete
Main::API_V1_NAMESPACE,
[63] Fix | Delete
self::ROUTE_PREFIX,
[64] Fix | Delete
[
[65] Fix | Delete
[
[66] Fix | Delete
'methods' => 'GET',
[67] Fix | Delete
'callback' => [ $this, 'get_wistia_embed_permission' ],
[68] Fix | Delete
'permission_callback' => [ $this, 'permission_edit_posts' ],
[69] Fix | Delete
],
[70] Fix | Delete
[
[71] Fix | Delete
'methods' => 'POST',
[72] Fix | Delete
'callback' => [ $this, 'set_wistia_embed_permission' ],
[73] Fix | Delete
'permission_callback' => [ $this, 'permission_edit_posts' ],
[74] Fix | Delete
'args' => [
[75] Fix | Delete
'value' => [
[76] Fix | Delete
'required' => false,
[77] Fix | Delete
'type' => 'bool',
[78] Fix | Delete
'default' => true,
[79] Fix | Delete
],
[80] Fix | Delete
],
[81] Fix | Delete
],
[82] Fix | Delete
]
[83] Fix | Delete
);
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* Gets the value of the wistia embed permission.
[88] Fix | Delete
*
[89] Fix | Delete
* @return WP_REST_Response|WP_Error The response, or an error.
[90] Fix | Delete
*/
[91] Fix | Delete
public function get_wistia_embed_permission() {
[92] Fix | Delete
try {
[93] Fix | Delete
$user_id = $this->user_helper->get_current_user_id();
[94] Fix | Delete
$value = $this->wistia_embed_permission_repository->get_value_for_user( $user_id );
[95] Fix | Delete
} catch ( Exception $exception ) {
[96] Fix | Delete
return new WP_Error(
[97] Fix | Delete
'wpseo_wistia_embed_permission_error',
[98] Fix | Delete
$exception->getMessage(),
[99] Fix | Delete
(object) []
[100] Fix | Delete
);
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
return new WP_REST_Response(
[104] Fix | Delete
[
[105] Fix | Delete
'json' => (object) [
[106] Fix | Delete
'value' => $value,
[107] Fix | Delete
],
[108] Fix | Delete
]
[109] Fix | Delete
);
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Sets the value of the wistia embed permission.
[114] Fix | Delete
*
[115] Fix | Delete
* @param WP_REST_Request $request The request object.
[116] Fix | Delete
*
[117] Fix | Delete
* @return WP_REST_Response|WP_Error The success or failure response.
[118] Fix | Delete
*/
[119] Fix | Delete
public function set_wistia_embed_permission( WP_REST_Request $request ) {
[120] Fix | Delete
$params = $request->get_json_params();
[121] Fix | Delete
$value = \boolval( $params['value'] );
[122] Fix | Delete
[123] Fix | Delete
try {
[124] Fix | Delete
$user_id = $this->user_helper->get_current_user_id();
[125] Fix | Delete
$result = $this->wistia_embed_permission_repository->set_value_for_user( $user_id, $value );
[126] Fix | Delete
} catch ( Exception $exception ) {
[127] Fix | Delete
return new WP_Error(
[128] Fix | Delete
'wpseo_wistia_embed_permission_error',
[129] Fix | Delete
$exception->getMessage(),
[130] Fix | Delete
(object) []
[131] Fix | Delete
);
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
return new WP_REST_Response(
[135] Fix | Delete
[
[136] Fix | Delete
'json' => (object) [
[137] Fix | Delete
'success' => $result,
[138] Fix | Delete
],
[139] Fix | Delete
],
[140] Fix | Delete
( $result ) ? 200 : 400
[141] Fix | Delete
);
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Permission callback.
[146] Fix | Delete
*
[147] Fix | Delete
* @return bool True when user has 'edit_posts' permission.
[148] Fix | Delete
*/
[149] Fix | Delete
public function permission_edit_posts() {
[150] Fix | Delete
return \current_user_can( 'edit_posts' );
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function