Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing $item properties within auto_update_plugin filter #7086

Closed
DaWolfey opened this issue May 25, 2023 · 2 comments
Closed

Missing $item properties within auto_update_plugin filter #7086

DaWolfey opened this issue May 25, 2023 · 2 comments
Labels
P1 Medium priority PHP Type: Bug Something isn't working

Comments

@DaWolfey
Copy link

DaWolfey commented May 25, 2023

Bug Description

This is related to #6624 where I have identified that a plugin called wp fail2ban (https://wordpress.org/plugins/wp-fail2ban/) throws errors when this plugin is enabled. It appears related to issue 6624 in that it is related to the object that is passed into the hook.

It appears that the object that is passed in is missing the "slug" parameter.

Steps to reproduce

Install both google sitekit and wp-fail2ban in Wordpress. In wp-admin, errors appear at the top of the page which are:

Warning: Undefined property: stdClass::$slug in /wp-content/plugins/wp-fail2ban/lib/update.php on line 28

The line of code referenced there is a comparison with $item->slug

Additional Context

  • PHP Version: 8.1
  • Wordpress: 6.2.2

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • The plugin data ($item) passed to wp_is_auto_update_forced_for_item should be an object including all of the keys that are expected to be present in core. See examples: plugins page, site health
    • Essentially, this is plugin data (from headers) combined with update data from API, but all keys should be present
Example object from plugins page
stdClass Object
(
    [id] => w.org/plugins/google-site-kit
    [slug] => google-site-kit
    [plugin] => google-site-kit/google-site-kit.php
    [new_version] => 1.101.0
    [url] => https://wordpress.org/plugins/google-site-kit/
    [package] => https://downloads.wordpress.org/plugin/google-site-kit.1.101.0.zip
    [icons] => Array
        (
            [2x] => https://ps.w.org/google-site-kit/assets/icon-256x256.png?rev=2181376
            [1x] => https://ps.w.org/google-site-kit/assets/icon-128x128.png?rev=2181376
        )

    [banners] => Array
        (
            [2x] => https://ps.w.org/google-site-kit/assets/banner-1544x500.png?rev=2513620
            [1x] => https://ps.w.org/google-site-kit/assets/banner-772x250.png?rev=2513620
        )

    [banners_rtl] => Array
        (
        )

    [tested] => 
    [requires_php] => 
    [compatibility] => stdClass Object
        (
        )

    [requires] => 5.2
    [update-supported] => 1
    [Name] => Site Kit by Google
    [PluginURI] => https://sitekit.withgoogle.com
    [Version] => 1.101.0
    [Description] => Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
    [Author] => Google
    [AuthorURI] => https://opensource.google.com
    [TextDomain] => google-site-kit
    [DomainPath] => 
    [Network] => 
    [RequiresWP] => 5.2
    [RequiresPHP] => 5.6
    [UpdateURI] => 
    [Title] => Site Kit by Google
    [AuthorName] => Google
)

Implementation Brief

  • To provide comprehensive data, merge plugin API data with the existing header data in includes/Core/Util/Auto_Updates.php
  • Implement a new method, get_sitekit_update_data, to fetch data from site transient or resort to fallback data when transient data is unavailable:
    • Set a default data fallback by initializing a variable, say $sitekit_update_data
      • You can get the list of defaults from here
      • For the slug and plugin keys utilize dirname( GOOGLESITEKIT_PLUGIN_BASENAME )
      • Use 'w.org/plugins/' . $slug for the id key
    • Retrieve transient data with $plugin_updates = get_site_transient('update_plugins');
    • Identify the location of plugin data within transient data:
      • Check $plugin_updates->response[GOOGLESITEKIT_PLUGIN_BASENAME] and $plugin_updates->no_update[GOOGLESITEKIT_PLUGIN_BASENAME] for data.
      • If plugin data is located, return it (ensure it's cast to an array). Otherwise, use the fallback data from $sitekit_update_data
  • Within the sitekit_forced_autoupdates_status method
    • Obtain the plugin update details using the get_sitekit_update_data method
    • Merge this data with $sitekit_plugin_data prior to it being included as param in the wp_is_auto_update_forced_for_item function

Test Coverage

  • No test updates needed

QA Brief

  • Follow the Steps to reproduce and ensure that the error messages no longer appear.
  • Additionally, follow the QAB for Encourage users to enable auto-updates for Site Kit #5853 for any regressions as these code changes could affect this functionality.
  • Finally, install an older version of the Site Kit plugin from the bottom of the page using this link. Refresh the WP Admin Dashboard and ensure that there are no errors and the Site Kit plugin shows that it has an update available.
    • Update the plugin manually and verify everything works without any errors.
    • Repeat the above step, ie. install an older version of the plugin. Now enable plugin auto-updates for Site Kit on your site and verify that the plugin is auto updated. This will take up to half a day to trigger. Alternatively, try manually triggering the WP cron job which triggers the auto update script. Append /wp-cron.php?doing_wp_cron to the end of your test site URL in the address bar of the browser. E.g. http://sitekit.10uplabs.com/wp-cron.php?doing_wp_cron

Changelog entry

  • Fix a potential PHP warning due to missing properties in plugin update data.
@aaemnnosttv aaemnnosttv self-assigned this May 25, 2023
@aaemnnosttv aaemnnosttv added Type: Bug Something isn't working P1 Medium priority labels May 25, 2023
@aaemnnosttv aaemnnosttv removed their assignment May 25, 2023
@aaemnnosttv aaemnnosttv changed the title Missing slug parameter on auto_update_plugin filter Missing $item properties within auto_update_plugin filter May 25, 2023
@zutigrm zutigrm assigned zutigrm and unassigned zutigrm Oct 13, 2023
@eugene-manuilov eugene-manuilov self-assigned this Oct 13, 2023
@eugene-manuilov
Copy link
Collaborator

IB ✔️

@eugene-manuilov eugene-manuilov removed their assignment Oct 13, 2023
@jimmymadon jimmymadon self-assigned this Oct 16, 2023
@jimmymadon jimmymadon removed their assignment Oct 18, 2023
@kuasha420 kuasha420 assigned kuasha420 and unassigned kuasha420 Oct 18, 2023
@wpdarren wpdarren self-assigned this Oct 27, 2023
@wpdarren
Copy link
Collaborator

QA Update: ✅

Verified:

  • The error messages appear using the fail2ban plugin on latest release.
  • Error messages no longer appear on the develop branch. Issue fixed.
  • Went through the QAB on the ticket identified. Can confirm that the Keep Site Kit up-to-date banner appears. Went through all the scenarios as a smoke test and found no issues.
  • Went through the QAB steps using an older version of the plugin. Made sure that the notification appears in the plugins informing of an update. Ran cron job and Site Kit was automatically updated.
Screenshots

image
image

@wpdarren wpdarren removed their assignment Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 Medium priority PHP Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants