| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Actions\SEMrush; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 6 |
|
| 7 |
/** |
| 8 |
* Class SEMrush_Options_Action |
| 9 |
*/ |
| 10 |
class SEMrush_Options_Action { |
| 11 |
|
| 12 |
/** |
| 13 |
* The Options_Helper instance. |
| 14 |
* |
| 15 |
* @var Options_Helper |
| 16 |
*/ |
| 17 |
protected $options_helper; |
| 18 |
|
| 19 |
/** |
| 20 |
* SEMrush_Options_Action constructor. |
| 21 |
* |
| 22 |
* @param Options_Helper $options_helper The WPSEO options helper. |
| 23 |
*/ |
| 24 |
public function __construct( Options_Helper $options_helper ) { |
| 25 |
$this->options_helper = $options_helper; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Stores SEMrush country code in the WPSEO options. |
| 30 |
* |
| 31 |
* @param string $country_code The country code to store. |
| 32 |
* |
| 33 |
* @return object The response object. |
| 34 |
*/ |
| 35 |
public function set_country_code( $country_code ) { |
| 36 |
// The country code has already been validated at this point. No need to do that again. |
| 37 |
$success = $this->options_helper->set( 'semrush_country_code', $country_code ); |
| 38 |
|
| 39 |
if ( $success ) { |
| 40 |
return (object) [ |
| 41 |
'success' => true, |
| 42 |
'status' => 200, |
| 43 |
]; |
| 44 |
} |
| 45 |
return (object) [ |
| 46 |
'success' => false, |
| 47 |
'status' => 500, |
| 48 |
'error' => 'Could not save option in the database', |
| 49 |
]; |
| 50 |
} |
| 51 |
} |
| 52 |
|