WordPress 插件:插件激活后需要立即关闭某个功能

发布于 2024-10-15 22:34:26 字数 216 浏览 2 评论 0原文

我需要我的插件在安装插件后立即运行功能。我需要在安装之后而不是在安装期间运行该函数的原因是,在激活插件“之后”之前,所有挂钩都不起作用,并且我需要与第三方服务器进行一些额外的安装同步,并且我需要这些挂钩。

到目前为止,我还没有发现任何东西可以满足我的要求。据我所知和法典的说法,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

[浮城] 2024-10-22 22:34:26

瑟兰,我也有同样的问题。我一直无法想出一个很好的解决方案,所以我正在做的是在插件激活时设置一个 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

或者您可以使用我的方法。试试这个:

register_activation_hook(__FILE__, 'initialize_my_function');
function initialize_my_function() {
    add_option('run_my_initialization',"1");
}

add_action('admin_init', 'launch_activation_script');

function launch_activation_script() {
    if (get_option('run_my_initialization') == "1") {
        //Do Your Init Stuff Here
        delete_option('run_my_initialization');
    }
}

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(__FILE__, 'initialize_my_function');
function initialize_my_function() {
    add_option('run_my_initialization',"1");
}

add_action('admin_init', 'launch_activation_script');

function launch_activation_script() {
    if (get_option('run_my_initialization') == "1") {
        //Do Your Init Stuff Here
        delete_option('run_my_initialization');
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文