We recently had to patch you plugin due to a warning that only happens on the wp-admin screen yet it was creating a fatal error. We are running the most recent version of the plugins. You failed to checking settings is an array.
//php warnings from logs
Warning: Invalid argument supplied for foreach() in /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-wp-installer.php on line 773
Warning: Invalid argument supplied for foreach() in /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/repository/class-otgs-installer-repositories.php on line 29
Fatal error: Uncaught TypeError: Argument 2 passed to OTGS_Installer_Plugin_Finder::__construct() must be of the type array, null given, called in /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-factory.php on line 235 and defined in /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-plugin-finder.php:17
Stack trace:
#0 /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-factory.php(235): OTGS_Installer_Plugin_Finder->__construct(Object(OTGS_Installer_Plugin_Factory), NULL)
#1 /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-factory.php(247): OTGS_Installer_Factory->get_plugin_finder()
#2 /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-factory.php(258): OTGS_Installer_Factory->create_upgrade_response()
#3 /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-loader.php(25): OTGS_Installer_Factory->load_upg in /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-plugin-finder.php on line 17
Error: There has been a critical error on this website.Learn more about troubleshooting WordPress. There has been a critical error on this website.
///More info
The error indicates that the OTGS_Installer_Plugin_Finder class is being instantiated with a null value for the second argument, which is expected to be an array. This issue likely from the get_plugin_finder() method in the OTGS_Installer_Factory class, where $settings['repositories'] is being passed but is null.
We fix this by checking to ensure $settings['repositories'] is an array before passing it to the OTGS_Installer_Plugin_Finder constructor. If it's not an array, we can default it to an empty array.
Recommended fix - which we patched on our envs, but would love to have this updated into the plugin. Please review
File: class-otgs-installer-factory.php line 231-239
public function get_plugin_finder() {
if ( ! $this->plugin_finder ) {
- $settings = $this->get_installer()->get_settings();
- $this->plugin_finder = new OTGS_Installer_Plugin_Finder( $this->get_plugin_factory(), $settings['repositories'] );
+ $settings = $this->get_installer()->get_settings();
+ $repositories = isset($settings['repositories']) && is_array($settings['repositories']) ? $settings['repositories'] : [];
+ $this->plugin_finder = new OTGS_Installer_Plugin_Finder( $this->get_plugin_factory(), $repositories );
}
It's best practice to set $settings['repositories'] is an array before passing it to the OTGS_Installer_Plugin_Finder constructor. I think you all were having server issues last week so we were getting errors since your server was having issues and unable to check. Please pass on to your engineers to review the code suggestion.