admin管理员组文章数量:1287970
Is there a network equivalent to 'admin_init', or what do I have to do to add an action to network admin screens? I use 'admin_init' for an action on admin network screens, but the respective function is not executed. Thank you!
Edit: Here's what I want to do. The respective plugin writes custom database tables and should therefore only by activated on a per-site basis in a network.
function no_network_activation() {
// echo 'test1 ';
if ( is_network_admin() && isset($_GET['no-network-activation']) ) {
// echo 'test2';
add_action( 'network_admin_notices', 'no_network_activation_notice' );
deactivate_plugins( plugin_basename( __FILE__ ) );
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
}
}
add_action( 'admin_init', 'no_network_activation' );
function no_network_activation_notice(){
// Echo an admin notice: no network activation possible
}
function myplugin_database_adder($networkwide) {
// Redirect to network plugin url and add param to show the attempt of network-wide plugin activation
if (is_multisite() && $networkwide) {
header( 'Location: ' . network_admin_url( 'plugins.php?no-network-activation=true' ) );
exit;
}
else {
// Add the plugin database tables
// [...]
}
}
register_activation_hook( __FILE__, 'myplugin_database_adder' );
Is there a network equivalent to 'admin_init', or what do I have to do to add an action to network admin screens? I use 'admin_init' for an action on admin network screens, but the respective function is not executed. Thank you!
Edit: Here's what I want to do. The respective plugin writes custom database tables and should therefore only by activated on a per-site basis in a network.
function no_network_activation() {
// echo 'test1 ';
if ( is_network_admin() && isset($_GET['no-network-activation']) ) {
// echo 'test2';
add_action( 'network_admin_notices', 'no_network_activation_notice' );
deactivate_plugins( plugin_basename( __FILE__ ) );
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
}
}
add_action( 'admin_init', 'no_network_activation' );
function no_network_activation_notice(){
// Echo an admin notice: no network activation possible
}
function myplugin_database_adder($networkwide) {
// Redirect to network plugin url and add param to show the attempt of network-wide plugin activation
if (is_multisite() && $networkwide) {
header( 'Location: ' . network_admin_url( 'plugins.php?no-network-activation=true' ) );
exit;
}
else {
// Add the plugin database tables
// [...]
}
}
register_activation_hook( __FILE__, 'myplugin_database_adder' );
Share
Improve this question
edited Sep 13, 2021 at 4:47
winnewoerp
asked Sep 9, 2021 at 10:18
winnewoerpwinnewoerp
1715 bronze badges
6
|
Show 1 more comment
1 Answer
Reset to default 1You could restrict your admin_init
callback with e.g. a is_network_admin()
check.
本文标签: actionsIs there a filter called 39networkadmininit39
版权声明:本文标题:actions - Is there a filter called 'network_admin_init'? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741324286a2372383.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
admin_init
that's not working? – Jacob Peattie Commented Sep 9, 2021 at 11:06