Skip to main content
added 7 characters in body
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56

The first argument of register_activation_hook() is the filenameplugin filename including the path, so you need __FILE__ instead of plugin_dir_path( __FILE__ ).

// This should be in main plugin file
register_activation_hook( __FILE__, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

It is common to register the activation hook in the main plugin file, but the callback can be defined in any file you wish.

For example, in test-file.php you can define the callback:

function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

And in the main plugin file you can register the activation hook:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

include_once( plugin_dir_path( __FILE__ ) . 'test-file.php' );
register_activation_hook( __FILE__, 'enable_user_registration' );

You could also store the value of __FILE__ from the main plugin file in a constant, so you don't need to harcode any file name or file path:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

define( 'MY_PLUGIN_FILE_PATH', __FILE__ );
define( 'MY_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) );
include_once( MY_PLUGIN_DIR_PATH . 'test-file.php' );

And then, in test-file.php:

register_activation_hook( MY_PLUGIN_FILE_PATH, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

The first argument of register_activation_hook() is the filename including the path, so you need __FILE__ instead of plugin_dir_path( __FILE__ ).

register_activation_hook( __FILE__, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

It is common to register the activation hook in the main plugin file, but the callback can be defined in any file you wish.

For example, in test-file.php you can define the callback:

function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

And in the main plugin file you can register the activation hook:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

include_once( plugin_dir_path( __FILE__ ) . 'test-file.php' );
register_activation_hook( __FILE__, 'enable_user_registration' );

You could also store the value of __FILE__ from the main plugin file in a constant, so you don't need to harcode any file name or file path:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

define( 'MY_PLUGIN_FILE_PATH', __FILE__ );
define( 'MY_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) );
include_once( MY_PLUGIN_DIR_PATH . 'test-file.php' );

And then, in test-file.php:

register_activation_hook( MY_PLUGIN_FILE_PATH, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

The first argument of register_activation_hook() is the plugin filename including the path, so you need __FILE__ instead of plugin_dir_path( __FILE__ ).

// This should be in main plugin file
register_activation_hook( __FILE__, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

It is common to register the activation hook in the main plugin file, but the callback can be defined in any file you wish.

For example, in test-file.php you can define the callback:

function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

And in the main plugin file you can register the activation hook:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

include_once( plugin_dir_path( __FILE__ ) . 'test-file.php' );
register_activation_hook( __FILE__, 'enable_user_registration' );

You could also store the value of __FILE__ from the main plugin file in a constant, so you don't need to harcode any file name or file path:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

define( 'MY_PLUGIN_FILE_PATH', __FILE__ );
define( 'MY_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) );
include_once( MY_PLUGIN_DIR_PATH . 'test-file.php' );

And then, in test-file.php:

register_activation_hook( MY_PLUGIN_FILE_PATH, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}
added 666 characters in body
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56

The first argument of register_activation_hook() is the filename including the path, so you need __FILE__ instead of plugin_dir_path( __FILE__ ).

register_activation_hook( __FILE__, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

As opposed to the other answer, main plugin filename is NOT required. Anyway, itIt is common to register the activation hook in the main plugin file, but the callback can be defined in any file you wish.

For example, in test-file.php you can define the callback:

function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

And in the main plugin file you can register the activation hook:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

include_once( plugin_dir_path( __FILE__ ) . 'test-file.php' );
register_activation_hook( __FILE__, 'enable_user_registration' );

You could also store the value of __FILE__ from the main plugin file in a constant, so you don't need to harcode any file name or file path:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

define( 'MY_PLUGIN_FILE_PATH', __FILE__ );
define( 'MY_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) );
include_once( MY_PLUGIN_DIR_PATH . 'test-file.php' );

And then, in test-file.php:

register_activation_hook( MY_PLUGIN_FILE_PATH, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

The first argument of register_activation_hook() is the filename including the path, so you need __FILE__ instead of plugin_dir_path( __FILE__ ).

register_activation_hook( __FILE__, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

As opposed to the other answer, main plugin filename is NOT required. Anyway, it is common to register the activation hook in the main plugin file, but the callback can be defined in any file you wish.

For example, in test-file.php you can define the callback:

function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

And in the main plugin file you can register the activation hook:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

include_once( plugin_dir_path( __FILE__ ) . 'test-file.php' );
register_activation_hook( __FILE__, 'enable_user_registration' );

The first argument of register_activation_hook() is the filename including the path, so you need __FILE__ instead of plugin_dir_path( __FILE__ ).

register_activation_hook( __FILE__, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

It is common to register the activation hook in the main plugin file, but the callback can be defined in any file you wish.

For example, in test-file.php you can define the callback:

function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

And in the main plugin file you can register the activation hook:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

include_once( plugin_dir_path( __FILE__ ) . 'test-file.php' );
register_activation_hook( __FILE__, 'enable_user_registration' );

You could also store the value of __FILE__ from the main plugin file in a constant, so you don't need to harcode any file name or file path:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

define( 'MY_PLUGIN_FILE_PATH', __FILE__ );
define( 'MY_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) );
include_once( MY_PLUGIN_DIR_PATH . 'test-file.php' );

And then, in test-file.php:

register_activation_hook( MY_PLUGIN_FILE_PATH, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}
added 666 characters in body
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56

The first argument of register_activation_hook() is the filename including the path, so you need __FILE__ instead of plugin_dir_path( __FILE__ ).

register_activation_hook( __FILE__, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

As opposed to the other answer, main plugin filename is NOT required. Anyway, it is common to register the activation hook in the main plugin file, but the callback can be defined in any file you wish.

For example, in test-file.php you can define the callback:

function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

And in the main plugin file you can register the activation hook:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

include_once( plugin_dir_path( __FILE__ ) . 'test-file.php' );
register_activation_hook( __FILE__, 'enable_user_registration' );

The first argument of register_activation_hook() is the filename including the path, so you need __FILE__ instead of plugin_dir_path( __FILE__ ).

register_activation_hook( __FILE__, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

As opposed to the other answer, main plugin filename is NOT required.

The first argument of register_activation_hook() is the filename including the path, so you need __FILE__ instead of plugin_dir_path( __FILE__ ).

register_activation_hook( __FILE__, 'enable_user_registration' );
function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

As opposed to the other answer, main plugin filename is NOT required. Anyway, it is common to register the activation hook in the main plugin file, but the callback can be defined in any file you wish.

For example, in test-file.php you can define the callback:

function enable_user_registration() {
    if(!get_option('users_can_register')) {
        update_option( 'users_can_register', '1' );
    }
}

And in the main plugin file you can register the activation hook:

/*
Plugin Name: Test Plugin
Description: test
Version: 1.0
*/

include_once( plugin_dir_path( __FILE__ ) . 'test-file.php' );
register_activation_hook( __FILE__, 'enable_user_registration' );
Post Undeleted by cybmeta
Post Deleted by cybmeta
deleted 215 characters in body
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56
Loading
added 505 characters in body
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56
Loading
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56
Loading