xwp / stream

🗄️ Stream plugin for WordPress
https://wordpress.org/plugins/stream/
GNU General Public License v2.0
414 stars 116 forks source link

VIP issue: Function get_user_attribute is deprecated since version 2.0.0! Use get_user_meta instead #1410

Closed benlk closed 1 year ago

benlk commented 1 year ago

Bug Report

Expected Behavior

The expected behavior is that this plugin operates without excessive error logging.

Actual Behavior

On every admin page load, my error log fills up with messages like this:

[24-Feb-2023 22:44:30 UTC] PHP Deprecated:  Function get_user_attribute is <strong>deprecated</strong> since version 2.0.0! Use get_user_meta instead. in /var/www/html/wp-includes/functions.php on line 5383
[24-Feb-2023 22:44:30 UTC] PHP Stack trace:
[24-Feb-2023 22:44:30 UTC] PHP   1. {main}() /var/www/html/wp-admin/admin-ajax.php:0
[24-Feb-2023 22:44:30 UTC] PHP   2. do_action($hook_name = 'wp_ajax_heartbeat') /var/www/html/wp-admin/admin-ajax.php:188
[24-Feb-2023 22:44:30 UTC] PHP   3. WP_Hook->do_action($args = [0 => '']) /var/www/html/wp-includes/plugin.php:517
[24-Feb-2023 22:44:30 UTC] PHP   4. WP_Hook->apply_filters($value = '', $args = [0 => '']) /var/www/html/wp-includes/class-wp-hook.php:332
[24-Feb-2023 22:44:30 UTC] PHP   5. wp_ajax_heartbeat('') /var/www/html/wp-includes/class-wp-hook.php:308
[24-Feb-2023 22:44:30 UTC] PHP   6. apply_filters($hook_name = 'heartbeat_received', $value = [], ...$args = variadic(['wp-stream-heartbeat' => 'live-update', 'wp-stream-heartbeat-last-time' => '2023-02-24T18:55:48+0000', 'wp-stream-heartbeat-query' => '{"page":"wp_stream"}'], 'toplevel_page_wp_stream')) /var/www/html/wp-admin/includes/ajax-actions.php:3465
[24-Feb-2023 22:44:30 UTC] PHP   7. WP_Hook->apply_filters($value = [], $args = [0 => [], 1 => ['wp-stream-heartbeat' => 'live-update', 'wp-stream-heartbeat-last-time' => '2023-02-24T18:55:48+0000', 'wp-stream-heartbeat-query' => '{"page":"wp_stream"}'], 2 => 'toplevel_page_wp_stream']) /var/www/html/wp-includes/plugin.php:205
[24-Feb-2023 22:44:30 UTC] PHP   8. WP_Stream\Live_Update->heartbeat_received($response = [], $data = ['wp-stream-heartbeat' => 'live-update', 'wp-stream-heartbeat-last-time' => '2023-02-24T18:55:48+0000', 'wp-stream-heartbeat-query' => '{"page":"wp_stream"}']) /var/www/html/wp-includes/class-wp-hook.php:310
[24-Feb-2023 22:44:30 UTC] PHP   9. WP_Stream\Admin->get_user_meta($user_id = 138785674, $meta_key = 'stream_live_update_records', $single = *uninitialized*) /var/www/html/wp-content/plugins/stream/classes/class-live-update.php:186
[24-Feb-2023 22:44:30 UTC] PHP  10. get_user_attribute($user_id = 138785674, $meta_key = 'stream_live_update_records') /var/www/html/wp-content/plugins/stream/classes/class-admin.php:1090
[24-Feb-2023 22:44:30 UTC] PHP  11. _deprecated_function($function = 'get_user_attribute', $version = '2.0.0', $replacement = 'get_user_meta') /var/www/html/wp-content/mu-plugins/vip-helpers/vip-deprecated.php:472
[24-Feb-2023 22:44:30 UTC] PHP  12. trigger_error($message = 'Function get_user_attribute is <strong>deprecated</strong> since version 2.0.0! Use get_user_meta instead.', $error_level = 16384) /var/www/html/wp-includes/functions.php:5383

https://github.com/xwp/stream/blob/305583d70e8a7667d1f99df85196024a7334ed50/classes/class-admin.php#L1090

https://github.com/Automattic/vip-go-mu-plugins-built/blob/3b3927f64df1741db90f701c7d89b926ac11d7bd/vip-helpers/vip-deprecated.php#L458-L484

Steps to Reproduce the Problem

With the following:

Do the following

  1. Visit any admin page
  2. View the error log

System Information

benlk commented 1 year ago

This looks like it could be fixed by replacing get_user_attributes( $user_id, $meta_key ) with get_user_meta( $user_id, $meta_key, true ) to ensure a single return object.

benlk commented 1 year ago

Or by removing the entire VIP check: https://github.com/xwp/stream/blob/305583d70e8a7667d1f99df85196024a7334ed50/classes/class-admin.php#L1079-L1094

dougaxe1 commented 1 year ago

Thanks, @benlk!