php - 如何在订阅者注册到 wordpress 时自动创建 wordpress 页面
问题描述
此外,我需要仅由相应订阅者编辑自动创建的页面,并且在发布时它应该对所有访问该网站的用户可见
解决方案
也许您需要使用user_register钩子并执行创建帖子的函数,而要创建帖子,您需要使用wp_insert_post函数
add_action('user_register','my_function');
function my_function($user_id){
// Create post object
$my_post = array(
'post_title' => 'Title of page',
'post_type' => 'post', // Set type of your post
'post_content' => $_POST['post_content'],
'post_status' => 'publish', // Page published
'post_author' => $user_id // Assign page author
);
// Insert the post into the database
wp_insert_post( $my_post );
}
您还可以管理帖子类型的角色和能力
例子:
https://wordpress.stackexchange.com/a/208739/193674 https://wordpress.stackexchange.com/a/108375/193674
推荐阅读
- r - 如何比较来自不同数据集的变量并在 RStudio 中相应地改变变量?
- powershell - Powershell 最有效的组合自定义对象的方法
- python - 为原材料采购构建 Open AI RL 环境的奖励功能
- react-native - 如何强制模态中的内容为模态高度的 100%?
- python - 在 Python 中以快速更新的参数显示
- heroku - Heroku Bot 在 24 小时后停止
- python - Python Selenium 和 Chromedriver CentOS8
- mysql - 尝试使用 MySQL Connector for .NET 时,我的 Web.config 文件中的错误在哪里?
- python - 从用户输入将数据插入mysql
- r - 在 R 中,如何浏览 ssh 和 awk