ue ); } } /** * Removes the notification from the notification center, if it exists. * * @return void */ protected function maybe_remove_notification() { $this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID ); } /** * Creates the notification if it doesn't exist already. * * @return void */ protected function maybe_create_notification() { if ( ! $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID ) ) { $notification = $this->notification(); $this->notification_helper->restore_notification( $notification ); $this->notification_center->add_notification( $notification ); } } /** * Creates the notification when Yoast SEO auto-updates are enabled, if it hasn't been dismissed in the past. * * @return void */ protected function maybe_create_notification_if_not_dismissed() { $notification_dismissed = \get_user_option( 'wp_' . self::NOTIFICATION_ID . '_dismissed' ) === '1'; $yoast_updates_enabled = $this->yoast_auto_updates_enabled(); if ( $notification_dismissed && ! $yoast_updates_enabled ) { return; } $this->maybe_create_notification(); } /** * Checks whether auto-updates are enabled for Yoast SEO. * * @return bool True if they are enabled, false if not. */ protected function yoast_auto_updates_enabled() { $plugins_to_auto_update = \get_site_option( 'auto_update_plugins' ); // If no plugins are set to be automatically updated, it means that Yoast SEO isn't either. if ( ! $plugins_to_auto_update ) { return false; } // Check if the Yoast SEO plugin file is in the array of plugins for which auto-updates are enabled. return \in_array( 'wordpress-seo/wp-seo.php', $plugins_to_auto_update, true ); } /** * Returns an instance of the notification. * * @return Yoast_Notification The notification to show. */ protected function notification() { $presenter = new Auto_Update_Notification_Presenter(); return new Yoast_Notification( $presenter->present(), [ 'type' => Yoast_Notification::WARNING, 'id' => self::NOTIFICATION_ID, 'capabilities' => 'wpseo_manage_options', 'priority' => 0.8, ] ); } }