Opened 6 years ago
Last modified 6 years ago
#45779 new defect (bug)
probable issue in Plugin activation hook
Reported by: | tazotodua | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Plugins | Keywords: | |
Focuses: | multisite | Cc: |
Description
i.e. if we have a simplest plugin:
<?php /* * Plugin Name: example-1 */ register_activation_hook(__FILE__, "my" ); function my($network_wide) { if($network_wide || is_network_admin()) { die("Activation from Network"); } }
and you try to activate it from Network, you get such empty screen:
Probably the reason, as far as I can understand, is that, as the plugin is activated within the external sandbox call, and if it sees an error, it returns with activation-failure and then in iframe
, it tries to load the activated plugin in order to be able to see the error message. However, as I doubt, in the first call, the $newtork_wide || is_network_admin()
is evaluated to true, causing the die
to be triggered. however, while WP tries to show the iframe
, then there is not seen the error, as i suspect that $newtork_wide || is_network_admin()
is evaluated to false.
that makes some problems to plugin developers if they target activation from Network or Single-Site. Will be good if that will be addressed.
Change History (4)
#2
@
6 years ago
and this is the temporary solution how i handle that problem at this moment:
public function activate($network_wide){ $die= $network_wide || is_network_admin(); $show_die=false; if( get_option("opt1", false) ) { delete_option("opt1"); $show_die=true; } if($die) { update_option("opt1",true); $show_die=true; } if($show_die) { $text= '<h2>Hi, dont activate from NETWORK!!!!!!</h2>'; die($text .'<script>alert("'.strip_tags($text).'");</script>'); } }
that can be confirmed, if we put this code in
my
function: