gocodebox / lifterlms-helper

Update, install, and beta test LifterLMS and LifterLMS add-ons
0 stars 2 forks source link

Plugin object without a `plugin` property #36

Closed pondermatic closed 2 years ago

pondermatic commented 2 years ago

Reproduction Steps

  1. DELETE FROM wp_options WHERE option_name = '_site_transient_update_plugins';
  2. In the WordPress navigation menu, go to Plugins -> Add New

WP_Plugin_Install_List_Table::prepare_items() gets $installed_plugins from WP_Plugin_Install_List_Table::get_installed_plugins() and then tries to pluck the plugin property from $installed_plugins. Surprisingly, WP_List_Util::pluck() does not check if the property exists, which causes a PHP warning to be logged.

WP_Plugin_Install_List_Table::get_installed_plugins() gets plugin info from the update_plugins transient.

When the update_plugins transient is set, LLMS_Helper_Upgrader::pre_set_site_transient_update_things() gets LifterLMS add on information from https://lifterlms.com/wp-json/llms/v3/products, then calls LLMS_Helper_Upgrader::set_plugins_api() to get a plugin item object. This object does not have a plugin property and is eventually saved to the update_plugins site transient.

This code has not changed in a long time, so I can't figure out why I haven't noticed this before. Surely, this issue only exists on my system? Can anyone else reproduce this?

Expected Behavior

Actual Behavior

Error Messages / Logs

[31-Mar-2022 22:17:36 UTC] PHP Warning:  Undefined property: stdClass::$plugin in C:\wordpress-develop\src\wp-includes\class-wp-list-util.php on line 167
[31-Mar-2022 22:17:36 UTC] PHP Stack trace:
[31-Mar-2022 22:17:36 UTC] PHP   1. {main}() C:\wordpress-develop\src\wp-admin\plugin-install.php:0
[31-Mar-2022 22:17:36 UTC] PHP   2. WP_Plugin_Install_List_Table->prepare_items() C:\wordpress-develop\src\wp-admin\plugin-install.php:41
[31-Mar-2022 22:17:36 UTC] PHP   3. wp_list_pluck( <Edited for brevity.> ) C:\wordpress-develop\src\wp-admin\includes\class-wp-plugin-install-list-table.php:271
[31-Mar-2022 22:17:36 UTC] PHP   4. WP_List_Util->pluck($field = 'plugin', $index_key = NULL) C:\wordpress-develop\src\wp-includes\functions.php:5129

System and Environment Information

WordPress 5.9.1-src LifterLMS 6.2.0 PHP 8.0 Windows 10

This issue has been recreated:

eri-trabiccolo commented 2 years ago

Surprisingly, WP_List_Util::pluck() does not check if the property exists, which causes a PHP warning to be logged.

Yeah I actually found this rather annoying :/

This code has not changed in a long time, so I can't figure out why I haven't noticed this before.

Maybe what changed is the rest api response, maybe it included the plugin property before? I'm not confident with that part of code, but I guess that we can just include the plugin field in the response's object?|

Surely, this issue only exists on my system? Can anyone else reproduce this?

I remember I saw that warning a bunch of times and said to myself "gonna check what's this all about", I also remember that I rapidly checked it also happened disabling LifterLMS so I wrongly decided we were not involved. Of course we were, since we put that data in the transient :D. Nice catch.