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 / integrations / third-party / wpml-wpseo-notification.php

wpml-wpseo-notification.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.7, at src/integrations/third-party/wpml-wpseo-notification.php

121 lines 3.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\Integrations\Third_Party;
4
5 use Yoast\WP\SEO\Conditionals\Third_Party\WPML_Conditional;
6 use Yoast\WP\SEO\Conditionals\Third_Party\WPML_WPSEO_Conditional;
7 use Yoast\WP\SEO\Helpers\Short_Link_Helper;
8 use Yoast\WP\SEO\Integrations\Integration_Interface;
9 use Yoast_Notification;
10 use Yoast_Notification_Center;
11
12 /**
13 * Adds a notification to the dashboard if the WPML plugin is installed,
14 * but the Yoast SEO Multilingual plugin (a glue plugin to make Yoast SEO and WPML work nicely together)
15 * is not.
16 */
17 class WPML_WPSEO_Notification implements Integration_Interface {
18
19 /**
20 * The notification ID.
21 *
22 * @internal
23 */
24 const NOTIFICATION_ID = 'wpml-wpseo-not-installed';
25
26 /**
27 * The short link helper.
28 *
29 * @var Short_Link_Helper
30 */
31 protected $short_link_helper;
32
33 /**
34 * The notification center.
35 *
36 * @var Yoast_Notification_Center
37 */
38 protected $notification_center;
39
40 /**
41 * The WPML WPSEO conditional.
42 *
43 * @var WPML_WPSEO_Conditional
44 */
45 protected $wpml_wpseo_conditional;
46
47 /**
48 * WPML WPSEO notification constructor.
49 *
50 * @param Short_Link_Helper $short_link_helper The short link helper.
51 * @param Yoast_Notification_Center $notification_center The notification center.
52 * @param WPML_WPSEO_Conditional $wpml_wpseo_conditional The WPML WPSEO conditional.
53 */
54 public function __construct(
55 Short_Link_Helper $short_link_helper,
56 Yoast_Notification_Center $notification_center,
57 WPML_WPSEO_Conditional $wpml_wpseo_conditional
58 ) {
59 $this->short_link_helper = $short_link_helper;
60 $this->notification_center = $notification_center;
61 $this->wpml_wpseo_conditional = $wpml_wpseo_conditional;
62 }
63
64 /**
65 * Initializes the integration.
66 *
67 * @return void
68 */
69 public function register_hooks() {
70 \add_action( 'admin_notices', [ $this, 'notify_not_installed' ] );
71 }
72
73 /**
74 * Returns the conditionals based in which this loadable should be active.
75 *
76 * This integration should only be active when WPML is installed and activated.
77 *
78 * @return array The conditionals.
79 */
80 public static function get_conditionals() {
81 return [ WPML_Conditional::class ];
82 }
83
84 /**
85 * Notify the user that the Yoast SEO Multilingual plugin is not installed
86 * (when the WPML plugin is installed).
87 *
88 * Remove the notification again when it is installed.
89 *
90 * @return void
91 */
92 public function notify_not_installed() {
93 if ( ! $this->wpml_wpseo_conditional->is_met() ) {
94 $this->notification_center->add_notification( $this->get_notification() );
95 return;
96 }
97 $this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID );
98 }
99
100 /**
101 * Generates the notification to show to the user when WPML is installed,
102 * but the Yoast SEO Multilingual plugin is not.
103 *
104 * @return Yoast_Notification The notification.
105 */
106 protected function get_notification() {
107 return new Yoast_Notification(
108 \sprintf(
109 /* translators: %1$s expands to an opening anchor tag, %2$s expands to an closing anchor tag. */
110 \__( 'We notice that you have installed WPML. To make sure your canonical URLs are set correctly, %1$sinstall and activate the Yoast SEO Multilingual add-on%2$s as well!', 'wordpress-seo' ),
111 '<a href="' . \esc_url( $this->short_link_helper->get( 'https://yoa.st/wpml-yoast-seo' ) ) . '" target="_blank">',
112 '</a>'
113 ),
114 [
115 'id' => self::NOTIFICATION_ID,
116 'type' => Yoast_Notification::WARNING,
117 ]
118 );
119 }
120 }
121