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/editors/framewor.../integrat...
File: semrush.php
<?php
[0] Fix | Delete
// @phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- This namespace should reflect the namespace of the original class.
[1] Fix | Delete
namespace Yoast\WP\SEO\Editors\Framework\Integrations;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Config\SEMrush_Client;
[4] Fix | Delete
use Yoast\WP\SEO\Editors\Domain\Integrations\Integration_Data_Provider_Interface;
[5] Fix | Delete
use Yoast\WP\SEO\Exceptions\OAuth\Authentication_Failed_Exception;
[6] Fix | Delete
use Yoast\WP\SEO\Exceptions\OAuth\Tokens\Empty_Property_Exception;
[7] Fix | Delete
use Yoast\WP\SEO\Exceptions\OAuth\Tokens\Empty_Token_Exception;
[8] Fix | Delete
use Yoast\WP\SEO\Helpers\Options_Helper;
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Describes if the Semrush integration is enabled.
[12] Fix | Delete
*/
[13] Fix | Delete
class Semrush implements Integration_Data_Provider_Interface {
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* The options helper.
[17] Fix | Delete
*
[18] Fix | Delete
* @var Options_Helper
[19] Fix | Delete
*/
[20] Fix | Delete
private $options_helper;
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* The constructor.
[24] Fix | Delete
*
[25] Fix | Delete
* @param Options_Helper $options_helper The options helper.
[26] Fix | Delete
*/
[27] Fix | Delete
public function __construct( Options_Helper $options_helper ) {
[28] Fix | Delete
$this->options_helper = $options_helper;
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* If the integration is activated.
[33] Fix | Delete
*
[34] Fix | Delete
* @return bool If the integration is activated.
[35] Fix | Delete
*/
[36] Fix | Delete
public function is_enabled(): bool {
[37] Fix | Delete
return (bool) $this->options_helper->get( 'semrush_integration_active', true );
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Return this object represented by a key value array.
[42] Fix | Delete
*
[43] Fix | Delete
* @return array<string,bool> Returns the name and if the feature is enabled.
[44] Fix | Delete
*/
[45] Fix | Delete
public function to_array(): array {
[46] Fix | Delete
return [
[47] Fix | Delete
'active' => $this->is_enabled(),
[48] Fix | Delete
'countryCode' => $this->options_helper->get( 'semrush_country_code', false ),
[49] Fix | Delete
'loginStatus' => $this->options_helper->get( 'semrush_integration_active', true ) && $this->get_semrush_login_status(),
[50] Fix | Delete
];
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Returns this object represented by a key value structure that is compliant with the script data array.
[55] Fix | Delete
*
[56] Fix | Delete
* @return array<string,bool> Returns the legacy key and if the feature is enabled.
[57] Fix | Delete
*/
[58] Fix | Delete
public function to_legacy_array(): array {
[59] Fix | Delete
return [
[60] Fix | Delete
'semrushIntegrationActive' => $this->is_enabled(),
[61] Fix | Delete
'countryCode' => $this->options_helper->get( 'semrush_country_code', false ),
[62] Fix | Delete
'SEMrushLoginStatus' => $this->options_helper->get( 'semrush_integration_active', true ) && $this->get_semrush_login_status(),
[63] Fix | Delete
];
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Checks if the user is logged in to SEMrush.
[68] Fix | Delete
*
[69] Fix | Delete
* @return bool The SEMrush login status.
[70] Fix | Delete
*/
[71] Fix | Delete
private function get_semrush_login_status() {
[72] Fix | Delete
try {
[73] Fix | Delete
// Do this just in time to handle constructor exception.
[74] Fix | Delete
$semrush_client = \YoastSEO()->classes->get( SEMrush_Client::class );
[75] Fix | Delete
} catch ( Empty_Property_Exception $e ) {
[76] Fix | Delete
// Return false if token is malformed (empty property).
[77] Fix | Delete
return false;
[78] Fix | Delete
}
[79] Fix | Delete
// Get token (and refresh it if it's expired).
[80] Fix | Delete
try {
[81] Fix | Delete
$semrush_client->get_tokens();
[82] Fix | Delete
} catch ( Authentication_Failed_Exception | Empty_Token_Exception $e ) {
[83] Fix | Delete
return false;
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
return $semrush_client->has_valid_tokens();
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function