class-schema-person-upgrade-notification.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Notifies the user to update the Person on the publish entity in the Configuration Wizard.
  9. */
  10. class WPSEO_Schema_Person_Upgrade_Notification implements WPSEO_WordPress_Integration {
  11. /**
  12. * Registers all hooks to WordPress
  13. *
  14. * @return void
  15. */
  16. public function register_hooks() {
  17. add_action( 'admin_init', [ $this, 'handle_notification' ] );
  18. }
  19. /**
  20. * Handles if the notification should be added or removed.
  21. */
  22. public function handle_notification() {
  23. $company_or_person_user_id = WPSEO_Options::get( 'company_or_person_user_id', false );
  24. if ( WPSEO_Options::get( 'company_or_person' ) === 'person' && empty( $company_or_person_user_id ) ) {
  25. $this->add_notification();
  26. return;
  27. }
  28. $this->remove_notification();
  29. }
  30. /**
  31. * Adds a notification to the notification center.
  32. */
  33. protected function add_notification() {
  34. $notification_center = Yoast_Notification_Center::get();
  35. $notification_center->add_notification( $this->get_notification() );
  36. }
  37. /**
  38. * Removes a notification to the notification center.
  39. */
  40. protected function remove_notification() {
  41. $notification_center = Yoast_Notification_Center::get();
  42. $notification_center->remove_notification( $this->get_notification() );
  43. }
  44. /**
  45. * Gets the notification object.
  46. *
  47. * @return Yoast_Notification
  48. */
  49. protected function get_notification() {
  50. $message = sprintf(
  51. /* translators: %1$s is a link start tag to the Configuration Wizard, %2$s is the link closing tag. */
  52. __( 'You have previously set your site to represent a person. We’ve improved our functionality around Schema and the Knowledge Graph, so you should go in and %1$scomplete those settings%2$s.', 'wordpress-seo' ),
  53. '<a href="' . esc_url( admin_url( 'admin.php?page=wpseo_titles' ) ) . '">',
  54. '</a>'
  55. );
  56. $notification = new Yoast_Notification(
  57. $message,
  58. [
  59. 'type' => Yoast_Notification::WARNING,
  60. 'id' => 'wpseo-schema-person-upgrade',
  61. 'capabilities' => 'wpseo_manage_options',
  62. 'priority' => 0.8,
  63. ]
  64. );
  65. return $notification;
  66. }
  67. }