Support » Plugin: Strong Testimonials » Auto-populate Fields

  • Resolved fuji9

    (@fuji9)


    Is there a way to auto-populate fields in the testimonial form with data from logged in user? for example, email, first name, last name, etc.

Viewing 1 replies (of 1 total)
  • Plugin Contributor Chris Dillon

    (@cdillon27)

    Here’s a generic example. Add this to your theme’s functions.php or create an mu-plugin.

    /**
     * Insert name and email of currently logged-in user into testimonial submission form.
     * For Strong Testimonials plugin.
     *
     * @param $value
     * @param $field
     * @param $form_values
     *
     * @return mixed
     */
    function my_strong_field_value( $value, $field, $form_values ) {
    	// Don't overwrite existing entry. Only possible if a default value is set
    	// on the form field or JavaScript and HTML validation is disabled.
    	if ( ! $value ) {
    
    		// Get current user
    		$current_user = wp_get_current_user();
    
    		// 'client_name' and 'email' are the default field names.
    		// Change these if yours are different.
    		if ( 'client_name' == $field['name'] ) {
    			$value = $current_user->data->display_name;
    		} elseif( 'email' == $field['name'] ) {
    			$value = $current_user->data->user_email;
    		}
    
    	}
    
    	return $value;
    }
    add_filter( 'wpmtst_field_value', 'my_strong_field_value', 10, 3 );
Viewing 1 replies (of 1 total)
  • The topic ‘Auto-populate Fields’ is closed to new replies.