Advanced WordPress plugin activation detection

The init and plugins_loaded hooks are already run before a plugin is activated. That’s why your first code doesn’t work but the second does. Regarding your third code: there’s no need to run add_action(‘myplugin_activate’ … inside init. Not everything needs to be hooked to init. Just use add_action(‘myplugin_activate’, function(){ echo ‘myplugin is not allowed.’; die; … Read more

Sub Plugin deactivation when Parent Plugin deactivate

You can use detect_plugin_deactivation, function detect_plugin_deactivation( $plugin, $network_activation ) { if ($plugin==”parentplugin/parentplugin.php”) { deactivate_plugins(plugin_basename(__FILE__)); } } add_action( ‘deactivated_plugin’, ‘detect_plugin_deactivation’, 10, 2 ); Add this snippet in your plugin’s main file.

register_activation_hook() not working as expected

WP needs all the required arguments – you skipped the one that tells it either a PHP file to use for output, or a function to run. From the Developer Site: /** * Register a custom menu page. */ function wpdocs_register_my_custom_menu_page(){ add_menu_page( __( ‘Custom Menu Title’, ‘textdomain’ ), ‘custom menu’, ‘manage_options’, ‘custompage’, ‘my_custom_menu_page’, plugins_url( ‘myplugin/images/icon.png’ … Read more

A question about register_activation hook

The register_activation_hook() is actually just a wrapper for add_action(‘activate_’ . $file, $function); and is only executed when a plugin is activated. This action/function is meant to be used by anything that should only execute once when the plugin is activated, things which would include stuff like adding custom terms to taxonomies create new database tables … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)