0

Thanks to this tutorial, I learned and was able to create a custom profile that use input text for profile links.

here are the codes used from the tutorial:

/* add custom profile field */
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

function my_show_extra_profile_fields( $user ) { ?>

    <h3>Extra profile information</h3>

    <table class="form-table">

        <tr>
            <th><label for="twitter">Twitter</label></th>

            <td>
                <input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
                <span class="description">Please enter your Twitter username.</span>
            </td>
        </tr>

    </table>
<?php }

/* save custom profile field */
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id ) {

    if ( !current_user_can( 'edit_user', $user_id ) )
        return false;
    update_usermeta( $user_id, 'twitter', $_POST['twitter'] );
}

/* display custom profile field */ 
function my_author_box() { ?>
    <div class="author-profile vcard">

        <?php if ( get_the_author_meta( 'twitter' ) ) { ?>
            <p class="twitter clear">
                <a href="http://twitter.com/<?php the_author_meta( 'twitter' ); ?>" title="Follow <?php the_author_meta( 'display_name' ); ?> on Twitter">Follow <?php the_author_meta( 'display_name' ); ?> on Twitter</a>
            </p>
        <?php } // End check for twitter ?>
    </div><?php
}

I've try changing this part:

<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" />

to:

<textarea type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text"></textarea>

So that it'll use a textarea instead of a textbox. Whenever I hit save profile, nothing is saved in the textarea, so anything on it is deleted.

How do I fix this so, it'll save whatever is in the textarea?

1 Answer 1

5

I think you want something like this:

<textarea type="text" name="twitter" id="twitter" class="regular-text"><?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?></textarea>

Note, the input field has a value attribute while the textarea has it's content between <textarea> and </textarea>

1
  • thanks, it worked. Do you know if there's a way to disable css and js for whatever is entered in the textarea?
    – lee
    Apr 18, 2016 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.