analogwp / analogwp-templates

Style Kits for Elementor adds a number of intuitive styling controls in the Elementor editor that allow you to apply styles globally or per page.
https://analogwp.com
27 stars 7 forks source link

Get_plugins() call conflicts with other plugins having similar calls #394

Closed lushkant closed 4 years ago

lushkant commented 4 years ago

Issue

So the problem is actually with this get_plugins() call it works fine when it has a fallback applied like so -

if ( ! function_exists( 'get_plugins' ) ) {
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

But with plugins using get_plugins() call this triggers a conflict, although I tried recreating this same behavior and couldn't which in terms points to a hard to replicate condition sometimes.

The error was last seen in Yoast v14.4.1 and Toolset Types plugin (version unknown).

Stack trace for Yoast

Fatal error: Uncaught Error: Call to undefined function get_plugins() in /home/charles4/public_html/wp-content/plugins/wordpress-seo-premium/inc/class-addon-manager.php:394 Stack trace: #0 /home/charles4/public_html/wp-content/plugins/wordpress-seo-premium/inc/class-addon-manager.php(308): WPSEO_Addon_Manager->get_plugins() #1 /home/charles4/public_html/wp-content/plugins/wordpress-seo-premium/inc/class-addon-manager.php(228): WPSEO_Addon_Manager->get_installed_addons() #2 /home/charles4/public_html/wp-content/plugins/wordpress-seo-premium/inc/class-addon-manager.php(470): WPSEO_Addon_Manager->has_installed_addons() #3 /home/charles4/public_html/wp-content/plugins/wordpress-seo-premium/inc/class-addon-manager.php(100): WPSEO_Addon_Manager->get_site_information() #4 /home/charles4/public_html/wp-content/plugins/wordpress-seo-premium/inc/class-addon-manager.php(111): WPSEO_Addon_Manager->get_subscriptions() #5 /home/charles4/public_html/wp-content/plugins/wordpress-seo-premium/inc/class-addon-manager.php(168): WPSEO_Addon_M in /home/charles4/public_html/wp-content/plugins/wordpress-seo-premium/inc/class-addon-manager.php on line 394

Stack trace for Toolset Types

Typ E_ERROR wurde in der Zeile 2211 der Datei /home/baselmed/public_html/msbau/wp-content/plugins/types/vendor/otgs/installer/includes/class-wp-installer.php verursacht. Fehlermeldung: Uncaught Error: Call to undefined function get_plugins() in /home/baselmed/public_html/msbau/wp-content/plugins/types/vendor/otgs/installer/includes/class-wp-installer.php:2211 Stack trace: #0 /home/baselmed/public_html/msbau/wp-includes/class-wp-hook.php(287): WP_Installer->custom_plugins_api_call(false, 'plugin_informat...', Object(stdClass)) #1 /home/baselmed/public_html/msbau/wp-includes/plugin.php(206): WP_Hook->apply_filters(false, Array) #2 /home/baselmed/public_html/msbau/wp-admin/includes/plugin-install.php(150): apply_filters('plugins_api', false, 'plugin_informat...', Object(stdClass)) #3 /home/baselmed/public_html/msbau/wp-content/plugins/analogwp-templates/inc/Utils.php(424): plugins_api('plugin_informat...', Object(stdClass)) #4 /home/baselmed/public_html/msbau/wp-content/plugins/analogwp-templates/inc/settings/class-settings-version-control.php(94): Analog\Utils::get_rollback_versions() #5 /home/baselmed/public_html/msbau/wp-content/plugins/analogwp-templates/inc/settings/class-settings-version

Fix we know so far & what we want

Having a fallback for get_plugins and re-requiring plugin.php from wp-admin/includes fixes this issue. But it isn't a reliable fix since this issue occurs with every other plugin who is using get_plugins() somewhere in their code without a similar fallback.

So we're better off fixing this in our own code, we need to check if our call is early/late/a possible cause which could explain why this call conflicts with other similar calls.

Let me know @gvgvgvijayan if you need help or a hand in this. Always here to help 😄

gvgvgvijayan commented 4 years ago

The solution in the comment might just work: https://developer.wordpress.org/reference/functions/is_plugin_active/#comment-2427

Snippet: if(in_array('plugin-directory/plugin-file.php', apply_filters('active_plugins', get_option('active_plugins')))){ //plugin is activated }

gvgvgvijayan commented 4 years ago

Once PR merged do the same here too: https://github.com/analogwp/style-kits-pro/blob/develop/style-kits-pro.php#L116