wordpress-sdk
wordpress-sdk copied to clipboard
active_plugins reorder may cause other plugins to be deactivated
🐞 bug report
Behavior: When updating a plugin that uses freemius there are cases where it reorders the active_plugins list for a site incorrectly. This happens in:
- includes/fs-essential-functions.php
- function fs_newest_sdk_plugin_first
If your active_plugins list starts like this:
a:10:{i:0;s:27:"bu-versions/bu-versions.php";i:1;s:33:"cyclone-slider/cyclone-slider.php";i:3;s:33:"formidable-pro/formidable-pro.php";i:4;s:59:"hide-youtube-related-videos/hide-youtube-related-videos.php";i:5;s:31:"page-links-to/page-links-to.php";i:6;s:13:"pods/init.php";i:7;s:27:"redirection/redirection.php";i:8;s:49:"tw-recent-posts-widget/tw-recent-posts-widget.php";i:9;s:29:"umich-alerts/umich-alerts.php";i:10;s:29:"widget-logic/widget_logic.php";}
it will end up like:
a:10:{i:0;s:13:"pods/init.php";i:1;s:27:"bu-versions/bu-versions.php";i:2;s:33:"cyclone-slider/cyclone-slider.php";i:3;s:33:"formidable-pro/formidable-pro.php";i:4;s:59:"hide-youtube-related-videos/hide-youtube-related-videos.php";i:5;s:31:"page-links-to/page-links-to.php";i:6;s:13:"pods/init.php";i:7;s:49:"tw-recent-posts-widget/tw-recent-posts-widget.php";i:8;s:29:"umich-alerts/umich-alerts.php";i:9;s:29:"widget-logic/widget_logic.php";}
As you can see it actually removed key #7 which is the 6th element in the array. This is due to there being no key 2.
The problem occurs when array_splice happens as it doesn't remove elements by key but by position in the array. The end result also cause the plugin it decided needs to be at the beginning of the list to be in the list twice as it removed the wrong plugin from the array.
Versions: (*)
Freemius SDK Version:2.3.2WordPress Version:5.3.2PHP Version:7.2.29
Plugin / Theme: (*)
Name:PodsSlug:pods
Related: https://github.com/Freemius/wordpress-sdk/pull/397
Fixed by #398