How to add typehints to function in functions.php when argument is an object?

I have a function that is defined in functions.php of my theme and it makes use of the WP_User object.My problem is ho

I have a function that is defined in functions.php of my theme and it makes use of the WP_User object. My problem is how do I let the PHP interpreter aware of its use.

This doesn't work

//function declaration breaks
function myFunc(int $userId, WP_User $wpUser) :void { 
    //do stuff
}
add_action("wp_login", myFunc, 10, 2);

But this does

//function declaration works
function myFunc($userId, $wpUser) :void { 
    //do stuff
}

add_action("wp_login", myFunc, 10, 2);

due to coding standards I need the type hinted version to work.

What is the best way of making PHP aware of the WP_User class?

By using require_once? or some other method as I am not sure if requiring files from wp_includes folder is a good idea.

Any help would be appreciated.

Thanks in advance

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745367041a4624630.html

相关推荐

  • How to add typehints to function in functions.php when argument is an object?

    I have a function that is defined in functions.php of my theme and it makes use of the WP_User object.My problem is ho

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信