提交Pionetforms之后的角色更改

发布于 2025-01-20 04:31:29 字数 833 浏览 3 评论 0原文

我想设置订户提交表格,那么角色将从订户更改为客户。

供您参考,我正在与您分享Pionetforms的动作钩和滤镜: https://piotnetforms.com/docs/com/actions/actions-hook-filter-hook/ < /a>

我已经搜索过并找到了一些代码源,但是我不知道如何使用PionetForms。

    add_action('cred_save_data', 'change_user_role_on_save',10,2);
function change_user_role_on_save($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==573)
    {
     $user = wp_get_current_user();
   
       
if ( in_array( 'subscriber', (array) $user->roles ) ) {
         
// Remove role
$user->remove_role( 'subscriber' );
  
// Add role
$user->set_role('customer');
}
          
    }
}

当前使用成员Press制造的“成员”插件。

如果有人让我知道如何解决它,我会很感激。 谢谢。

I would like to set up if subscribers submit a form then the role is changed from subscriber to customer.

For your reference, I am sharing with you the Pionetforms' action hook and filter hook:
https://piotnetforms.com/docs/actions-hook-filter-hook/

I have googled and found some code sources, but I have no clue how to work with Pionetforms.

    add_action('cred_save_data', 'change_user_role_on_save',10,2);
function change_user_role_on_save($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==573)
    {
     $user = wp_get_current_user();
   
       
if ( in_array( 'subscriber', (array) $user->roles ) ) {
         
// Remove role
$user->remove_role( 'subscriber' );
  
// Add role
$user->set_role('customer');
}
          
    }
}

Currently using "members" plugin which is made by memberpress.

I would be grateful if anyone let me know how to solve it.
Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

清风夜微凉 2025-01-27 04:31:29

这是一个代码:

您可以更改 formname1、formname2、formname3、formname4

  function piotnet_change_role_user($form_submission){
        $form_id = $form_submission['form']['id'];
        if(in_array($form_id, ['form_name1', 'form_name2', 'form_name3', 'form_name4'])){
            $email = $form_submission['fields']['email']['value'];
            $user = get_user_by_email($email);
            if($user){
                if(in_array($form_id, ['form_name1', 'form_name2'])){
                    $user->remove_role( 'subscriber' );
                    $user->add_role( 'customer' );
                }else{
                    $user->remove_role( 'subscriber' );
                    $user->add_role( 'customer' );
                    $user->add_role( 'contributor' );
                }
            }
        }
     }
    
    add_action('piotnetforms/form_builder/new_record_v2', 'piotnet_change_role_user');

Here is a code:

You can chagne formname1, formname2, formname3, formname4

  function piotnet_change_role_user($form_submission){
        $form_id = $form_submission['form']['id'];
        if(in_array($form_id, ['form_name1', 'form_name2', 'form_name3', 'form_name4'])){
            $email = $form_submission['fields']['email']['value'];
            $user = get_user_by_email($email);
            if($user){
                if(in_array($form_id, ['form_name1', 'form_name2'])){
                    $user->remove_role( 'subscriber' );
                    $user->add_role( 'customer' );
                }else{
                    $user->remove_role( 'subscriber' );
                    $user->add_role( 'customer' );
                    $user->add_role( 'contributor' );
                }
            }
        }
     }
    
    add_action('piotnetforms/form_builder/new_record_v2', 'piotnet_change_role_user');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文