• Resolved tequenikality

    (@tequenikality)


    Hey everyone;

    I have a fairly niche application for CF7, and I’d like to enquire if there’s any way to default a form’s message to the Biographic info on the user’s profile? I have a site-specific plugin that I can add code to if that’s needed, but to be frank I wouldn’t know where to start – I’ve not been developing WordPress sites for very long and I’ve barely even scratched the surface of developing plugins.

    Any help you can offer would be appreciated.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter tequenikality

    (@tequenikality)

    After over 8 hours of research and trial-and-error, I’ve devised a pseudo-way of achieving this:

    add_filter( 'shortcode_atts_wpcf7', 'custom_shortcode_atts_wpcf7_filter', 10, 3 );
    function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
            $my_attr = 'your-message';
            $user_id = get_current_user_id();
            if ( isset( $atts[$my_attr] ) and $user_id != 0 ) {
                    $description = get_user_meta( $user_id , 'description', true );
                    $out[$my_attr] = $description;
            } 
            return $out;
    }

    This filter allows me to set the default from the user’s bio (description), as long as I add the attribute to the shortcode and set the form’s field to default to it.

    In this snippet, it doesn’t matter what the attr ‘your-message’ is set to in the shortcode – in the form, it will default to the user’s description regardless of the attribute’s content, as long as the attribute is set.

    If you want to adapt this code to your own form, change $my_attr to the name of the field you want to default, add default:shortcode_attr to the field in the form editor and add whatever you set $my_attr to into the end of the shortcode on your page.

    Hope someone else finds this useful to justify my 8+ hours of suffering ??

Viewing 1 replies (of 1 total)
  • The topic ‘New Default’ is closed to new replies.