WordPress 插件:插件激活后需要立即关闭某个功能
我需要我的插件在安装插件后立即运行功能。我需要在安装之后而不是在安装期间运行该函数的原因是,在激活插件“之后”之前,所有挂钩都不起作用,并且我需要与第三方服务器进行一些额外的安装同步,并且我需要这些挂钩。
到目前为止,我还没有发现任何东西可以满足我的要求。据我所知和法典的说法,crons 功能只有在有人访问该网站后才会触发。这是一个“不”。该插件无法等待一段“随机”时间。这甚至可能是严重的安全风险。
I need my plugin to run a function immediately after the plugin has been installed. The reason I need to run the function after and not during the installation is because none of the hooks work until "after" the plugin is activated and I need to do some additional install synching with a thirdparty server and I need those hooks.
So far I've found nothing that does what I want. The crons functions, from what I can tell and from what the codex says, only fire after someone visits the site. This is a "no no". The plugin cannot wait some "random" period of time. It might even be a serious security risk.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
瑟兰,我也有同样的问题。我一直无法想出一个很好的解决方案,所以我正在做的是在插件激活时设置一个 update_option ,然后一旦访问设置页面,我就会检查 get_option 来检查我的选项-时间设置,如果有的话,我会关闭该函数并删除_选项。现在这并不完全适合您,但是...您也许能够弄清楚如何应用此过滤器:
http://adambrown.info/p/wp_hooks/hook/install_plugin_complete_actions?version=3.0&file=wp- admin/includes/class-wp-upgrader.php
或者您可以使用我的方法。试试这个:
Thirlan, I have the same problem. I haven't been able to come up with a great solution, so what I'm doing is on plugin activate I'm setting a update_option and then once the settings page is visited I'm checking for the get_option to check for my one-time setting and if it's there, I fire off the function and delete_option. Now this won't exactly work for you, but... you might be able to figure out how to apply this filter:
http://adambrown.info/p/wp_hooks/hook/install_plugin_complete_actions?version=3.0&file=wp-admin/includes/class-wp-upgrader.php
or you might be able to sort of use my method. Try this:
您可以使用 register_activation_hook 吗?
Can you use register_activation_hook?