When you’re inside a class, you need to pass a reference to WordPress for WordPress to call the function within the class. See the line that contains $this
.
class My_Users {
public function __construct() {
add_action( 'do_redirect', array( $this, 'redirect' ) );
}
public function redirect() {
$url = get_site_url( null, '/welcome', 'https' );
wp_safe_redirect( $url );
exit;
}
public function some_function() {
do_action( 'do_redirect' );
}
}
$custom_users = new My_Users();
$custom_users->some_function();
That being said, you do not need to use an action here. It would be simpler to just do the following:
class My_Users {
public function redirect() {
$url = get_site_url( null, '/welcome', 'https' );
wp_safe_redirect( $url );
exit;
}
}
$custom_users = new My_Users();
$custom_users->redirect();