| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Admin |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Notifies the user to update the Search Appearance settings when the site is set to represent a Person, |
| 10 |
* but no person (name) has been chosen. |
| 11 |
*/ |
| 12 |
class WPSEO_Schema_Person_Upgrade_Notification implements WPSEO_WordPress_Integration { |
| 13 |
|
| 14 |
/** |
| 15 |
* Registers all hooks to WordPress |
| 16 |
* |
| 17 |
* @return void |
| 18 |
*/ |
| 19 |
public function register_hooks() { |
| 20 |
add_action( 'admin_init', [ $this, 'handle_notification' ] ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Handles if the notification should be added or removed. |
| 25 |
* |
| 26 |
* @return void |
| 27 |
*/ |
| 28 |
public function handle_notification() { |
| 29 |
$company_or_person_user_id = WPSEO_Options::get( 'company_or_person_user_id', false ); |
| 30 |
if ( WPSEO_Options::get( 'company_or_person' ) === 'person' && empty( $company_or_person_user_id ) ) { |
| 31 |
$this->add_notification(); |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
$this->remove_notification(); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Adds a notification to the notification center. |
| 40 |
* |
| 41 |
* @return void |
| 42 |
*/ |
| 43 |
protected function add_notification() { |
| 44 |
$notification_center = Yoast_Notification_Center::get(); |
| 45 |
$notification_center->add_notification( $this->get_notification() ); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Removes a notification to the notification center. |
| 50 |
* |
| 51 |
* @return void |
| 52 |
*/ |
| 53 |
protected function remove_notification() { |
| 54 |
$notification_center = Yoast_Notification_Center::get(); |
| 55 |
$notification_center->remove_notification( $this->get_notification() ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Gets the notification object. |
| 60 |
* |
| 61 |
* @return Yoast_Notification |
| 62 |
*/ |
| 63 |
protected function get_notification() { |
| 64 |
$message = sprintf( |
| 65 |
/* translators: %1$s is a link start tag to the Search Appearance settings, %2$s is the link closing tag. */ |
| 66 |
__( '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' ), |
| 67 |
'<a href="' . esc_url( admin_url( 'admin.php?page=wpseo_page_settings#/site-representation' ) ) . '">', |
| 68 |
'</a>', |
| 69 |
); |
| 70 |
|
| 71 |
$notification = new Yoast_Notification( |
| 72 |
$message, |
| 73 |
[ |
| 74 |
'type' => Yoast_Notification::WARNING, |
| 75 |
'id' => 'wpseo-schema-person-upgrade', |
| 76 |
'capabilities' => 'wpseo_manage_options', |
| 77 |
'priority' => 0.8, |
| 78 |
], |
| 79 |
); |
| 80 |
|
| 81 |
return $notification; |
| 82 |
} |
| 83 |
} |
| 84 |
|