PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
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 / watchers / woocommerce-beta-editor-watcher.php

woocommerce-beta-editor-watcher.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at src/integrations/watchers/woocommerce-beta-editor-watcher.php

147 lines 4.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\Integrations\Watchers;
4
5 use Yoast\WP\SEO\Conditionals\Admin_Conditional;
6 use Yoast\WP\SEO\Conditionals\Not_Admin_Ajax_Conditional;
7 use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
8 use Yoast\WP\SEO\Helpers\Notification_Helper;
9 use Yoast\WP\SEO\Helpers\Short_Link_Helper;
10 use Yoast\WP\SEO\Integrations\Integration_Interface;
11 use Yoast\WP\SEO\Presenters\Admin\Woocommerce_Beta_Editor_Presenter;
12 use Yoast_Notification;
13 use Yoast_Notification_Center;
14
15 /**
16 * Shows a notification for users who have Woocommerce product beta editor enabled.
17 */
18 class Woocommerce_Beta_Editor_Watcher implements Integration_Interface {
19
20 /**
21 * The notification ID.
22 */
23 public const NOTIFICATION_ID = 'wpseo-woocommerce-beta-editor-warning';
24
25 /**
26 * The short link helper.
27 *
28 * @var Short_Link_Helper
29 */
30 protected $short_link_helper;
31
32 /**
33 * The Yoast notification center.
34 *
35 * @var Yoast_Notification_Center
36 */
37 protected $notification_center;
38
39 /**
40 * The notification helper.
41 *
42 * @var Notification_Helper
43 */
44 protected $notification_helper;
45
46 /**
47 * The WooCommerce conditional.
48 *
49 * @var WooCommerce_Conditional
50 */
51 protected $woocommerce_conditional;
52
53 /**
54 * The Woocommerce beta editor presenter.
55 *
56 * @var Woocommerce_Beta_Editor_Presenter
57 */
58 protected $presenter;
59
60 /**
61 * Woocommerce_Beta_Editor_Watcher constructor.
62 *
63 * @param Yoast_Notification_Center $notification_center The notification center.
64 * @param Notification_Helper $notification_helper The notification helper.
65 * @param Short_Link_Helper $short_link_helper The short link helper.
66 * @param WooCommerce_Conditional $woocommerce_conditional The WooCommerce conditional.
67 */
68 public function __construct(
69 Yoast_Notification_Center $notification_center,
70 Notification_Helper $notification_helper,
71 Short_Link_Helper $short_link_helper,
72 WooCommerce_Conditional $woocommerce_conditional
73 ) {
74 $this->notification_center = $notification_center;
75 $this->notification_helper = $notification_helper;
76 $this->short_link_helper = $short_link_helper;
77 $this->woocommerce_conditional = $woocommerce_conditional;
78 $this->presenter = new Woocommerce_Beta_Editor_Presenter( $this->short_link_helper );
79 }
80
81 /**
82 * Returns the conditionals based on which this loadable should be active.
83 *
84 * @return string[] The conditionals.
85 */
86 public static function get_conditionals() {
87 return [ Admin_Conditional::class, Not_Admin_Ajax_Conditional::class ];
88 }
89
90 /**
91 * Initializes the integration.
92 *
93 * On admin_init, it is checked whether the notification about Woocommerce product beta editor enabled should be shown.
94 *
95 * @return void
96 */
97 public function register_hooks() {
98 \add_action( 'admin_init', [ $this, 'manage_woocommerce_beta_editor_notification' ] );
99 }
100
101 /**
102 * Manage the Woocommerce product beta editor notification.
103 *
104 * Shows the notification if needed and deletes it if needed.
105 *
106 * @return void
107 */
108 public function manage_woocommerce_beta_editor_notification() {
109 if ( \get_option( 'woocommerce_feature_product_block_editor_enabled' ) === 'yes' && $this->woocommerce_conditional->is_met() ) {
110 $this->maybe_add_woocommerce_beta_editor_notification();
111 }
112 else {
113 $this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID );
114 }
115 }
116
117 /**
118 * Add the Woocommerce product beta editor enabled notification if it does not exist yet.
119 *
120 * @return void
121 */
122 public function maybe_add_woocommerce_beta_editor_notification() {
123 if ( ! $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID ) ) {
124 $notification = $this->notification();
125 $this->notification_helper->restore_notification( $notification );
126 $this->notification_center->add_notification( $notification );
127 }
128 }
129
130 /**
131 * Returns an instance of the notification.
132 *
133 * @return Yoast_Notification The notification to show.
134 */
135 protected function notification() {
136 return new Yoast_Notification(
137 $this->presenter->present(),
138 [
139 'type' => Yoast_Notification::ERROR,
140 'id' => self::NOTIFICATION_ID,
141 'capabilities' => 'wpseo_manage_options',
142 'priority' => 1,
143 ],
144 );
145 }
146 }
147