自定义注册和待审批

时间:2018-03-21 作者:Marcelo Henriques Cortez

我有一个自定义表单,用户可以在我的网站上注册。

他可以注册为订户或店铺。

我需要“阻止”店铺的所有注册,因此用户注册为店铺,收到一封电子邮件,告诉他注册已暂停,管理员收到一封电子邮件,告诉他新注册的店铺,管理员在管理面板中批准注册。

有什么办法吗?我搜索了一个插件,但其中一些插件强迫我使用自己的注册表,其他插件阻止任何角色注册。

到目前为止,我已经创建了一个常规注册表。一个给商店,一个给订户。它工作得很好。

1 个回复
最合适的回答,由SO网友:Marcelo Henriques Cortez 整理而成

好吧,我找到了一个方法。这不是一个完美的解决方案,但可以让我继续这个项目。

我刚刚创建了另一个名为“shop\\u pending”的角色。

当用户注册为店铺时,他不会得到角色“shop”,而是得到角色“shop\\u pending”。

完成所有过程后,管理员可以转到用户页面,编辑特定用户,并更改其角色。

下面是我正在使用的部分代码:

// Check args and replace if necessary
if (!is_array($fields_shop))     $fields_shop = array();
if (!is_wp_error($errors_shop))  $errors_shop = new WP_Error;
if (isset($_POST[\'submit_shop\'])) {
    // Get fields from submitted form
    $fields_shop = ds_get_fields_shop();  
    // Validate fields and produce errors
    if (ds_validate_shop($fields_shop, $errors_shop)) {      
    // If successful, register user
      $fields_shop[\'role\'] = \'shop_pending\';
      $shop_id = wp_insert_user($fields_shop);
      update_user_meta( $shop_id, \'user_avatar\', $fields_shop[\'user_avatar\'] );
      update_user_meta( $shop_id, \'nome_shop\', $fields_shop[\'nome_shop\'] );
      update_user_meta( $shop_id, \'cont_shop\', $fields_shop[\'cont_shop\'] );
      update_user_meta( $shop_id, \'telefone_shop\', $fields_shop[\'telefone_shop\'] );
      update_user_meta( $shop_id, \'zip\', $fields_shop[\'zip\'] );
      update_user_meta( $shop_id, \'conselho2\', $fields_shop[\'conselho2\'] );

      // Clear field data
      $fields_shop = array(); 
}

结束