• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 6744816013

03 Nov 2023 11:52AM UTC coverage: 49.287% (+0.06%) from 49.232%
6744816013

push

github

enricobattocchi
Merge branch 'release/21.6' into trunk

36 of 41 new or added lines in 2 files covered. (87.8%)

525 existing lines in 1 file now uncovered.

13238 of 26859 relevant lines covered (49.29%)

3.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.62
/src/integrations/watchers/woocommerce-beta-editor-watcher.php
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\Helpers\Notification_Helper;
8
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
9
use Yoast\WP\SEO\Integrations\Integration_Interface;
10
use Yoast\WP\SEO\Presenters\Admin\Woocommerce_Beta_Editor_Presenter;
11
use Yoast_Notification;
12
use Yoast_Notification_Center;
13

14
/**
15
 * Shows a notification for users who have Woocommerce product beta editor enabled.
16
 *
17
 * @class Woocommerce_Beta_Editor_Watcher
18
 */
19
class Woocommerce_Beta_Editor_Watcher implements Integration_Interface {
20

21
        /**
22
         * The notification ID.
23
         */
24
        const NOTIFICATION_ID = 'wpseo-woocommerce-beta-editor-warning';
25

26
        /**
27
         * The short link helper.
28
         *
29
         * @var Short_Link_Helper
30
         */
31
        protected $short_link_helper;
32

33
        /**
34
         * The Yoast notification center.
35
         *
36
         * @var Yoast_Notification_Center
37
         */
38
        protected $notification_center;
39

40
        /**
41
         * The notification helper.
42
         *
43
         * @var Notification_Helper
44
         */
45
        protected $notification_helper;
46

47
        /**
48
         * The Woocommerce beta editor presenter.
49
         *
50
         * @var Woocommerce_Beta_Editor_Presenter
51
         */
52
        protected $presenter;
53

54
        /**
55
         * Woocommerce_Beta_Editor_Watcher constructor.
56
         *
57
         * @param Yoast_Notification_Center $notification_center The notification center.
58
         * @param Notification_Helper       $notification_helper The notification helper.
59
         * @param Short_Link_Helper         $short_link_helper The short link helper.
60
         */
61
        public function __construct(
62
                Yoast_Notification_Center $notification_center,
63
                Notification_Helper $notification_helper,
64
                Short_Link_Helper $short_link_helper
65
        ) {
1✔
66
                $this->notification_center = $notification_center;
2✔
67
                $this->notification_helper = $notification_helper;
2✔
68
                $this->short_link_helper   = $short_link_helper;
2✔
69
                $this->presenter           = new Woocommerce_Beta_Editor_Presenter( $this->short_link_helper );
2✔
70
        }
1✔
71

72
        /**
73
         * Returns the conditionals based on which this loadable should be active.
74
         *
75
         * @return string[] The conditionals.
76
         */
77
        public static function get_conditionals() {
78
                return [ Admin_Conditional::class, Not_Admin_Ajax_Conditional::class ];
2✔
79
        }
80

81
        /**
82
         * Initializes the integration.
83
         *
84
         * On admin_init, it is checked whether the notification about Woocommerce product beta editor enabled should be shown.
85
         *
86
         * @return void
87
         */
88
        public function register_hooks() {
89
                \add_action( 'admin_init', [ $this, 'manage_woocommerce_beta_editor_notification' ] );
2✔
90
        }
1✔
91

92
        /**
93
         * Manage the Woocommerce product beta editor notification.
94
         *
95
         * Shows the notification if needed and deletes it if needed.
96
         *
97
         * @return void
98
         */
99
        public function manage_woocommerce_beta_editor_notification() {
100
                if ( \get_option( 'woocommerce_feature_product_block_editor_enabled' ) === 'yes' ) {
6✔
101
                        $this->maybe_add_woocommerce_beta_editor_notification();
4✔
102
                }
103
                else {
104
                        $this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID );
2✔
105
                }
106
        }
3✔
107

108
        /**
109
         * Add the Woocommerce product beta editor enabled notification if it does not exist yet.
110
         *
111
         * @return void
112
         */
113
        public function maybe_add_woocommerce_beta_editor_notification() {
NEW
114
                if ( ! $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID ) ) {
×
NEW
115
                        $notification = $this->notification();
×
NEW
116
                        $this->notification_helper->restore_notification( $notification );
×
NEW
117
                        $this->notification_center->add_notification( $notification );
×
118
                }
119
        }
120

121
        /**
122
         * Returns an instance of the notification.
123
         *
124
         * @return Yoast_Notification The notification to show.
125
         */
126
        protected function notification() {
127
                return new Yoast_Notification(
2✔
128
                        $this->presenter->present(),
2✔
129
                        [
1✔
130
                                'type'         => Yoast_Notification::ERROR,
2✔
131
                                'id'           => self::NOTIFICATION_ID,
2✔
132
                                'capabilities' => 'wpseo_manage_options',
2✔
133
                                'priority'     => 1,
2✔
134
                        ]
1✔
135
                );
1✔
136
        }
137
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc