Skip to content

Commit fdd3129

Browse files
committed
Avoid re-running full plugin init during activation
install() called get_plugin_instance()->init() unconditionally, which re-ran the bootstrap out of sequence during plugin activation and could destabilise plugin load order for the request (e.g. triggering ACF to initialise too early). Only run init() when the plugin version has not already been populated; the DB routines only need the version.
1 parent 4090dd8 commit fdd3129

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎php/class-utils.php‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,17 @@ protected static function table_installed() {
334334
* Install our custom table.
335335
*/
336336
public static function install() {
337-
// Ensure that the plugin bootstrap is loaded.
338-
get_plugin_instance()->init();
337+
$plugin = get_plugin_instance();
338+
339+
// Ensure the plugin metadata (version, paths) is available for the DB
340+
// routines below, but avoid re-running init during activation when it has
341+
// already run on the `init` hook. Re-running the full bootstrap out of
342+
// sequence during activation can destabilise plugin load order for the
343+
// request (e.g. triggering other plugins such as ACF to initialise too
344+
// early). We only need the plugin version here, not the component graph.
345+
if ( empty( $plugin->version ) ) {
346+
$plugin->init();
347+
}
339348

340349
$sql = self::get_table_sql();
341350

0 commit comments

Comments
 (0)