Home / Admin / How to Build a Profile Page Using Post Submissions
Duplicate Snippet

Embed Snippet on Your Site

How to Build a Profile Page Using Post Submissions

With this snippet and the Post Submissions addon, you can create professional author profiles that automatically display below each guest post.

<10
Code Preview
php
<?php
/**
 * Add a profile form using Post Submissions
 *
 * @link https://wpforms.com/developers/how-to-build-an-profile-form-using-post-submissions/
 */
 
function wpf_post_submission_custom_content( $post_id, $fields, $form_data, $entry_id ) {
 
    // Only do this for form #1089.
    if ( absint( $form_data[ 'id' ] ) !== 1089 ) {
        return;
    }
 
    /*
     * Field IDs, for reference.
     * 15 - Birthday
     * 16 - "My friends would describe me as"
     * 18 - "The most influential person in my life has been..."
     * 19 - "Five things I couldn't live without"
     */
 
    // Below we're going to create our new custom content template,
    // using the field IDs listed above :)
    ob_start();
    ?>
 
    <h2><em><?php echo __('Author Profile', 'text-domain'); ?></em></h2>
 
    <h3><?php echo __('Name', 'text-domain'); ?></h3>
    <?php echo wpautop( esc_html( $fields[2][ 'value' ] ) ); ?>
 
    <h3><?php echo __('Birthday', 'text-domain'); ?></h3>
    <?php echo wpautop( esc_html( $fields[15][ 'value' ] ) ); ?>
 
    <h3><?php echo __('My friends would describe me as', 'text-domain'); ?></h3>
    <?php echo wpautop( esc_html( $fields[16][ 'value' ] ) ); ?>
 
    <h3><?php echo __('The most influential person in my life has been...', 'text-domain'); ?></h3>
    <?php echo wpautop( esc_html( $fields[18][ 'value' ] ) ); ?>
 
    <h3><?php echo __('Five things I couldn\'t live without', 'text-domain'); ?></h3>
    <?php echo wpautop( esc_html( $fields[19][ 'value' ] ) ); ?>
 
    <?php
    $content = ob_get_clean();
 
    remove_filter('content_save_pre', 'wp_filter_post_kses');
    remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
 
    $post = array(
        'ID'           => $post_id,
        'post_content' => $content,
    );
    wp_update_post( $post );
 
    add_filter('content_save_pre', 'wp_filter_post_kses');
    add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
}
add_action( 'wpforms_post_submissions_process', 'wpf_post_submission_custom_content', 10, 4 );

Comments

Add a Comment