PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.7
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.7
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 / helpers / wincher-helper.php

wincher-helper.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.7, at src/helpers/wincher-helper.php

91 lines 2.4 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\Helpers;
4
5 use Yoast\WP\SEO\Conditionals\Non_Multisite_Conditional;
6 use Yoast\WP\SEO\Config\Wincher_Client;
7 use Yoast\WP\SEO\Exceptions\OAuth\Authentication_Failed_Exception;
8 use Yoast\WP\SEO\Exceptions\OAuth\Tokens\Empty_Property_Exception;
9 use Yoast\WP\SEO\Exceptions\OAuth\Tokens\Empty_Token_Exception;
10
11 /**
12 * A helper object for Wincher matters.
13 */
14 class Wincher_Helper {
15
16 /**
17 * Holds the Options Page helper instance.
18 *
19 * @var Options_Helper
20 */
21 protected $options;
22
23 /**
24 * Options_Helper constructor.
25 *
26 * @param Options_Helper $options The options helper.
27 */
28 public function __construct( Options_Helper $options ) {
29 $this->options = $options;
30 }
31
32 /**
33 * Checks if the integration should be active for the current user.
34 *
35 * @return bool Whether the integration is active.
36 */
37 public function is_active() {
38 $conditional = new Non_Multisite_Conditional();
39
40 if ( ! $conditional->is_met() ) {
41 return false;
42 }
43
44 if ( ! \current_user_can( 'publish_posts' ) && ! \current_user_can( 'publish_pages' ) ) {
45 return false;
46 }
47
48 return (bool) $this->options->get( 'wincher_integration_active', true );
49 }
50
51 /**
52 * Checks if the user is logged in to Wincher.
53 *
54 * @return bool The Wincher login status.
55 */
56 public function login_status() {
57 try {
58 $wincher = \YoastSEO()->classes->get( Wincher_Client::class );
59 } catch ( Empty_Property_Exception $e ) {
60 // Return false if token is malformed (empty property).
61 return false;
62 }
63
64 // Get token (and refresh it if it's expired).
65 try {
66 $wincher->get_tokens();
67 } catch ( Authentication_Failed_Exception $e ) {
68 return false;
69 } catch ( Empty_Token_Exception $e ) {
70 return false;
71 }
72
73 return $wincher->has_valid_tokens();
74 }
75
76 /**
77 * Returns the Wincher links that can be used to localize the global admin
78 * script. Mainly exists to avoid duplicating these links in multiple places
79 * around the code base.
80 *
81 * @return string[]
82 */
83 public function get_admin_global_links() {
84 return [
85 'links.wincher.website' => 'https://www.wincher.com?utm_medium=plugin&utm_source=yoast&referer=yoast&partner=yoast',
86 'links.wincher.pricing' => 'https://www.wincher.com/pricing?utm_medium=plugin&utm_source=yoast&referer=yoast&partner=yoast',
87 'links.wincher.login' => 'https://app.wincher.com/login?utm_medium=plugin&utm_source=yoast&referer=yoast&partner=yoast',
88 ];
89 }
90 }
91