1

I'm in need of a solution that I need a profile page (accessible to only admin and that user) with custom content (i.e. different content for different users), for each new user I've registered. Many ideas are coming in my mind like making a textarea for each user in the admin's WP dashboard and then displaying the textarea's content to the respective users profile page.

I'm a WordPress programmer, and I'll come up with a solution of this problem in a way or other. However, I would like to listen which is the recommended and most standardized way of doing this.

Any sort of workaround is welcome. However, standardized will be preferred.

2
  • kindly show me your progressive sample code after that we able to help you Commented Sep 18, 2013 at 9:12
  • Currently, there is no code because I'm discussing the problem on an abstract level, before start coding. Thanks.
    – Omar Tariq
    Commented Sep 18, 2013 at 10:22

1 Answer 1

0

I think your idea is good: create a function that hook 'show_user_profile' and 'edit_user_profile' action. In this function use a conditional to show a textarea only for admins and the content of this textarea (saved as user meta) to the owner of the profile.

Something like (very rough and untested):

function custom_profile_content ( $user ) {
  if ( current_user_can('edit_users') ) {
    echo '<table class="form-table">';
    $now = get_user_meta( $user->ID, 'custom_user_content', true ) ? : "";
    printf( '<tr><th><label for="custom_user_content">%s</label></th>', esc_html__('Custom User Content', 'yourtextdomain') );
    printf('<td><textarea name="custom_user_content" id="custom_user_content" rows="4" class="large-text" />%s</textarea></td></tr>', esc_textarea($now) );
    echo '</table>';
  } elseif( $user->ID == wp_get_current_user()->ID ) {
    echo '<h3>' . __('Hi, there', 'yourtextdomain') . '</h3>';
    echo '<p>' . $now . '</p>';
  }
}

function custom_profile_content_save ( $user_id ) {
  if ( isset($_POST['custom_user_content']) ) update_user_meta( $user_id, 'custom_user_content', $_POST['custom_user_content'] );
}


add_action( 'show_user_profile', 'custom_profile_content' );
add_action( 'edit_user_profile', 'custom_profile_content' );
add_action( 'personal_options_update', 'custom_profile_content_save' );
add_action( 'edit_user_profile_update', 'custom_profile_content_save' );
1
  • thank you @gmazzap for the answer, it fixed my problem, I have only one issue, the extra fields appear below Password filed in the user profile, page how can I control this, so I can arrange new it in profile page ? Commented Feb 3, 2015 at 17:59

Your Answer

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

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