| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Integrations\Watchers; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Conditionals\No_Conditionals; |
| 6 |
use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 7 |
use Yoast_Notification_Center; |
| 8 |
|
| 9 |
/** |
| 10 |
* Shows a notification for users who have WordPress auto updates enabled but not Yoast SEO auto updates. |
| 11 |
*/ |
| 12 |
class Auto_Update_Watcher implements Integration_Interface { |
| 13 |
|
| 14 |
use No_Conditionals; |
| 15 |
|
| 16 |
/** |
| 17 |
* The notification ID. |
| 18 |
*/ |
| 19 |
public const NOTIFICATION_ID = 'wpseo-auto-update'; |
| 20 |
|
| 21 |
/** |
| 22 |
* The Yoast notification center. |
| 23 |
* |
| 24 |
* @var Yoast_Notification_Center |
| 25 |
*/ |
| 26 |
protected $notification_center; |
| 27 |
|
| 28 |
/** |
| 29 |
* Auto_Update constructor. |
| 30 |
* |
| 31 |
* @param Yoast_Notification_Center $notification_center The notification center. |
| 32 |
*/ |
| 33 |
public function __construct( Yoast_Notification_Center $notification_center ) { |
| 34 |
$this->notification_center = $notification_center; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Initializes the integration. |
| 39 |
* |
| 40 |
* On admin_init, it is checked whether the notification to auto-update Yoast SEO needs to be shown or removed. |
| 41 |
* This is also done when major WP core updates are being enabled or disabled, |
| 42 |
* and when automatic updates for Yoast SEO are being enabled or disabled. |
| 43 |
* |
| 44 |
* @return void |
| 45 |
*/ |
| 46 |
public function register_hooks() { |
| 47 |
\add_action( 'admin_init', [ $this, 'remove_notification' ] ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Removes the notification from the notification center, if it exists. |
| 52 |
* |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
public function remove_notification() { |
| 56 |
$this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID ); |
| 57 |
} |
| 58 |
} |
| 59 |
|