Skip Navigation

[Resuelto] Assigning Existing User to CRED Form Submission by Guest User

This support ticket is created hace 1 año, 8 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Waqar hace 1 año, 8 meses.

Asistido por: Waqar.

Autor
Mensajes
#2579373

I have a CRED form on our site that allows guest users (those who are not logged into an account) to submit a form that creates a post. Because I have no intention of letting these users have their own accounts on the site, I'd like to assign the post submission to a specific user, perhaps a dummy account that no real human uses, because otherwise it just assigns the post to the user that appears first alphabetically, and this is simply undesirable behavior.

Any help in this matter would be greatly appreciated. Thanks in advance!

#2579709

Hi,

Thank you for contacting us and I'd be happy to assist.

You can use the 'cred_save_data' hook to execute a custom function that sets the specific (dummy) user as the post author when the form is submitted:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

For example, suppose that the form ID of your target form is '1234' and the dummy user that you'd like all guest posts to assign to has the ID '5678'. The custom function attached to the 'cred_save_data' hook will look like this:


add_action('cred_save_data', 'custom_set_guest_post_author',10,2);
function custom_set_guest_post_author($post_id, $form_data)
{
    // check if a specific form
    if ($form_data['id']==1234)
    {
            $args = array(
                'ID'           => $post_id,
                'post_author'   => 5678, // ID of the guest user
            );
            $res = wp_update_post( $args, true );
    }
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

I hope this helps and please let me know if you need further assistance.

regards,
Waqar