Skip to content

Commit 1be7eab

Browse files
committed
fix: add filters so plugin gets loaded first
1 parent ef23d7c commit 1be7eab

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

stubs/activate-ymir-plugin.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,37 @@ function activate_ymir_plugin() {
2121
}
2222
}
2323
add_action('plugins_loaded', 'activate_ymir_plugin');
24+
25+
/**
26+
* Ensures that the plugin is always the first one to be loaded per site.
27+
*/
28+
function ensure_ymir_plugin_loaded_first(array $active_plugins): array
29+
{
30+
foreach ($active_plugins as $key => $basename) {
31+
if (1 === preg_match('/ymir\.php$/', $basename)) {
32+
array_splice($active_plugins, $key, 1);
33+
array_unshift($active_plugins, $basename);
34+
}
35+
}
36+
37+
return $active_plugins;
38+
}
39+
add_filter('pre_update_option_active_plugins', 'ensure_ymir_plugin_loaded_first', 9999);
40+
41+
/**
42+
* Ensures that the plugin is always the first one to be loaded for the network.
43+
*/
44+
function ensure_ymir_plugin_loaded_first_on_network(array $active_plugins): array
45+
{
46+
$active_plugins = array_keys($active_plugins);
47+
48+
foreach ($active_plugins as $index => $plugin) {
49+
if (1 === preg_match('/ymir\.php$/', $plugin)) {
50+
array_splice($active_plugins, $index, 1);
51+
array_unshift($active_plugins, $plugin);
52+
}
53+
}
54+
55+
return array_fill_keys($active_plugins, time());
56+
}
57+
add_filter('pre_update_site_option_active_sitewide_plugins', 'ensure_ymir_plugin_loaded_first_on_network', 9999);

0 commit comments

Comments
 (0)