首页 > 解决方案 > 如何在订阅者注册到 wordpress 时自动创建 wordpress 页面

问题描述

此外,我需要仅由相应订阅者编辑自动创建的页面,并且在发布时它应该对所有访问该网站的用户可见

标签: phpwordpress

解决方案


也许您需要使用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


推荐阅读