WPSEO_Upgrade::upgrade_49()
Removes the 'wpseo-dismiss-about' notice for every user that still has it.
Метод класса: WPSEO_Upgrade{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->upgrade_49();
Код WPSEO_Upgrade::upgrade_49() WPSEO Upgrade::upgrade 49 Yoast 24.9
protected function upgrade_49() { global $wpdb; /* * Using a filter to remove the notification for the current logged in user. The notification center is * initializing the notifications before the upgrade routine has been executedd and is saving the stored * notifications on shutdown. This causes the returning notification. By adding this filter the shutdown * routine on the notification center will remove the notification. */ add_filter( 'yoast_notifications_before_storage', [ $this, 'remove_about_notice' ] ); $meta_key = $wpdb->get_blog_prefix() . Yoast_Notification_Center::STORAGE_KEY; // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches. // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way. $usermetas = $wpdb->get_results( $wpdb->prepare( ' SELECT %i, %i FROM %i WHERE %i = %s AND %i LIKE %s ', [ 'user_id', 'meta_value', $wpdb->usermeta, 'meta_key', $meta_key, 'meta_value', '%wpseo-dismiss-about%' ] ), ARRAY_A ); if ( empty( $usermetas ) ) { return; } foreach ( $usermetas as $usermeta ) { $notifications = maybe_unserialize( $usermeta['meta_value'] ); foreach ( $notifications as $notification_key => $notification ) { if ( ! empty( $notification['options']['id'] ) && $notification['options']['id'] === 'wpseo-dismiss-about' ) { unset( $notifications[ $notification_key ] ); } } update_user_option( $usermeta['user_id'], Yoast_Notification_Center::STORAGE_KEY, array_values( $notifications ) ); } }