WordPress 页面加载中我可以检测到所请求的帖子的最早点是什么?
最早的 WordPress 操作是什么,可以可靠地检测到最终显示的帖子? (通过使用全局 $post 或检测 wp_query 对象或其他方式)
例如。我的插件需要检测来自不同站点上另一个插件的传入请求,目前它通过使用 add_action('plugins_loaded'
尽早检查 $_POST var,并且回调函数使用 < code>$post = get_page_by_path($_SERVER['REQUEST_URI'],'','post') 获取 $post 对象,然后使用 post 数据获取用于处理响应的任何其他信息在任何标头或其他标准 WP 处理发生之前发送回来,目的是减轻接收请求的博客的负载,
有更好的方法吗?我知道没有更早的方法,因为 'plugins_loaded'。
操作在插件加载后立即被调用,但是有没有比使用 get_page_by_path 更可靠的方法?
what is the earliest wordpress action where the post that will eventually be shown can be detected reliably ? (either by using global $post or detecting the wp_query object or other way)
eg. my plugin needs to detect an incoming request from another plugin on a different site, at the moment it checks for a $_POST var as early as possible by using add_action('plugins_loaded'
and the callback function uses $post = get_page_by_path($_SERVER['REQUEST_URI'],'','post')
to get the $post object and then uses the post data to get any other information that is used to process the response which gets sent back before any headers or other standard WP processing happens with the intention of lessening the load on the blog receiving the request.
is there a better way?, I know there isn't an earlier way because 'plugins_loaded'
action gets called right after the , well, plugins get loaded but is there a more reliable way than using get_page_by_path ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试过滤器
'the_posts'
。您可以在wp-includes/query.php
函数get_posts()
中找到它。它将找到的帖子作为数组通过引用传递,因此您可以像操作一样使用它。这是我用来检查钩子的插件:
减少样本输出:
这应该尽早为您提供所需的所有信息。
哦,我希望在 https://wordpress.stackexchange.com/ 上见到您提出此类问题。 :)
I’d try the filter
'the_posts'
. You find it inwp-includes/query.php
functionget_posts()
. It passes the found posts as a array by reference, so you can use it like an action.Here is a plugin I use to inspect hooks:
Reduced sample Output:
This should give you all information you need as early as possible.
Oh, and I hope to see you on https://wordpress.stackexchange.com/ with such questions. :)