WordPress 评论者身份的秘密:wp_get_current_commenter() 源码剖析 各位观众,老司机开车了!今天咱们来扒一扒 WordPress 里一个看似不起眼,但实则关系到评论区用户体验的重要函数:wp_get_current_commenter()。 顾名思义,这个函数的作用就是获取当前评论者的信息。但它到底是怎么知道“当前”是哪个评论者的呢? 答案藏在 Cookie 里! 准备好了吗?系好安全带,咱们直接上代码,边跑边聊! 一、wp_get_current_commenter() 函数概览 首先,我们来看一下 wp-includes/comment.php 文件中 wp_get_current_commenter() 函数的庐山真面目: function wp_get_current_commenter() { static $commenter = null; if ( null !== $commenter ) { return $commenter; } $commenter = array( ‘comment_author’ => ”, ‘co …
继续阅读“阐述 WordPress `wp_get_current_commenter()` 函数的源码:如何从 `Cookie` 中获取评论者信息。”