1

I am trying to hook into activate_plugin.

I know that activate_plugin has 1 required param and 2 optional ones. I am trying to acquire all 3.

Here's my setup:

// create plugin settings menu
add_action('admin_menu', 'pe_create_menu');


function pe_create_menu() {

  //create new sub-level menu
  add_submenu_page( 'plugins.php', 'Plugin Settings', 'Plugin Enabler', 'administrator', __FILE__, 'pe_settings_page' );

  // Add my hook
  add_action( 'activate_plugin', 'pe_network_activate', 10, 3 );
}

And my function:

function pe_network_activate( $plugin, $redirect = '', $network_wide = false ) {
  $args = var_export( func_get_args(), true);
  _log("Args: " . $args); // write to the WP error_log
}

$args returns only the first parameter. How do I get all 3?

My goal is to be able to tell when a plugin is being network activated, or just normally activated - hence the need for $network_wide.

1

The activate_plugin() function accepts three parameters, but it emits the activate_plugin action with only one parameter. This can be confusing, but hooks sometimes use the same name as the function they come from, without passing the same parameters.

One way to get the difference between a network activation and a regular activation is to monitor the update_site_option and update_option hooks. Only one of them will fire, depending on the $network_wide parameter of activate_plugin().

0

What do you need var_export() for? func_get_args() should give you array of arguments on its own.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.