gpt4 book ai didi

php - 如何仅在 WordPress 中运行主题激活功能?

转载 作者:搜寻专家 更新时间:2023-10-31 20:39:47 24 4
gpt4 key购买 nike

我想为 WordPress 中的默认角色之一添加功能。 add_cap article建议人们在主题激活时做这种事情,因为设置已保存到数据库中:

NB: This setting is saved to the database, so it might be better to run this on theme/plugin activation

我打算使用的功能是:

function add_theme_caps() {
$role = get_role( 'author' );
$role->add_cap( 'edit_others_posts' );
}
add_action( 'admin_init', 'add_theme_caps');

如您所见,我目前正在连接到 admin_init,这会导致每次访问管理区域时运行该函数。如何仅在主题激活时运行该功能?

最佳答案

您可以使用 after_switch_theme 。当然,它只会影响您的主题。

http://codex.wordpress.org/Plugin_API/Action_Reference/after_switch_theme

关于php - 如何仅在 WordPress 中运行主题激活功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25381611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com