Skip Navigation

[Resuelto] Struggle to display edit user form via php

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
Struggle to display edit user form via php - grant edit user form access rights when not using Toolset Access plugin

Solution:
To grant the access of edit user form when not using the access plugin, you can use the filter: toolset_forms_current_user_can_use_user_form

You can fine proposed solution in this case with the following reply:
https://toolset.com/forums/topic/struggle-to-display-edit-user-form-via-php/#post-2066167

Relevant Documentation:

This support ticket is created hace 3 años, 6 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Este tema contiene 9 respuestas, tiene 2 mensajes.

Última actualización por Valeriia hace 3 años, 6 meses.

Asistido por: Minesh.

Autor
Mensajes
#2063365

Hi,

I'm trying to display an edit user form via a php shortcode but it does not show up.

Here is my function:

function usr_sn_edit_employee() {
    $user_id = (isset($_GET['userid'])) ? $_GET['userid'] : '';
    return do_shortcode("[cred_user_form form='edit-user' user='".$user_id."']");
}
add_shortcode('usr_sn_edit_employee', 'usr_sn_edit_employee');

In case you wonder, the URL parameter is specified: "/edit-user/?userid=4".

The same code with an edit post form works fine, but the user form does not want to display anything in this configuration.

I tried it on two different sites, one is almost empty, so I think you will be able to replicate it.

I have only Toolset Types and Forms, neither Views, nor Access modules are installed.

Please check.

Thank you

#2063375

Actually, nothing is displayed even if I don't use php and use your shortcode:

[cred_user_form form='edit-user' user='4']

It seems it only wants to display the form if I choose to edit my own profile, not somebody's else.

Thank you for looking into it.

#2063797

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

What if you try to use the Toolset form's PHP function to render the form:

echo cred_user_form($form_id,$user_id);

More info:
=> https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_user_form

#2063817

Hi Minesh,

It's good to know I can do that, however, as I said, the form is only displayed if I choose my own ID. It does not allow to edit other users.

Please try to replicate, I'm sure you'll see the same.

#2063819

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Does the user has rights to edit other users information?

Can I review your setup please? Can you please share admin access details for admin user as well as the user currently you are using.

I have set the next reply to private which means only you and I have access to it.

#2064063

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

I just installed and activated the Toolset Access plugin as to edit other users with a Toolset Form you must use it in combination with Access.

I can see it working as expected. Can you please confirm it works at your end as well.

#2064103

I don't want to use Access. I don't need it and don't want to install it for this only purpose.

The form should be available without it, it's not so complicated. I consider it a bug. Can you please contact your developers about it?

Thank you

#2064107

Installing Access only adds me the hussle to go in the settings for every form I create to enable it for different user roles. I have more than 20 forms on some sites. It's super annoying.

Please contact your developers.

Thank you

#2066167

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

I checked with our Devs and fortunately there is a workaround.

You can use the following filter to grant access to the administrator users:

function func_grant_access_to_edit_user_form($bool ,$form_id,$user_data) {
     if ( current_user_can( 'manage_options' ) ){
        $bool = true;
    }

    return $bool;
}
add_filter('toolset_forms_current_user_can_use_user_form', 'func_grant_access_to_edit_user_form',11,3);

You should try to add the above code to "Custom Code" section offered by Toolset or to the functions.php file of your theme.
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

#2066379

It worked. Thank you.