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

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