PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / actions / semrush / semrush-login-action.php

semrush-login-action.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.5, at src/actions/semrush/semrush-login-action.php

61 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Actions\SEMrush;
4
5 use Yoast\WP\SEO\Config\SEMrush_Client;
6 use Yoast\WP\SEO\Exceptions\OAuth\Authentication_Failed_Exception;
7
8 /**
9 * Class SEMrush_Login_Action
10 */
11 class SEMrush_Login_Action {
12
13 /**
14 * The SEMrush_Client instance.
15 *
16 * @var SEMrush_Client
17 */
18 protected $client;
19
20 /**
21 * SEMrush_Login_Action constructor.
22 *
23 * @param SEMrush_Client $client The API client.
24 */
25 public function __construct( SEMrush_Client $client ) {
26 $this->client = $client;
27 }
28
29 /**
30 * Authenticates with SEMrush to request the necessary tokens.
31 *
32 * @param string $code The authentication code to use to request a token with.
33 *
34 * @return object The response object.
35 */
36 public function authenticate( $code ) {
37 // Code has already been validated at this point. No need to do that again.
38 try {
39 $tokens = $this->client->request_tokens( $code );
40
41 return (object) [
42 'tokens' => $tokens->to_array(),
43 'status' => 200,
44 ];
45 } catch ( Authentication_Failed_Exception $e ) {
46 return $e->get_response();
47 }
48 }
49
50 /**
51 * Performs the login request, if necessary.
52 */
53 public function login() {
54 if ( $this->client->has_valid_tokens() ) {
55 return;
56 }
57
58 // Prompt with login screen.
59 }
60 }
61