Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbPress User Profile Manipulation

Viewing 13 replies - 1 through 13 (of 13 total)

  • Robin W
    Moderator

    @robin-w

    I have replies, but my comments gone into moderation as I put three links in !

    I don’t get access to moderation (despite being a moderator), but if it doesn’t pop out in the next coupe of hours, I’ll retype !


    elucidateTX
    Participant

    @elucidatetx

    Thanks! I’m looking forward to reading your reply.


    Robin W
    Moderator

    @robin-w

    ok, it hasn’t come through, so first of three replies to avoid the spam filter !

    WITHOUT CODE – I can do more if you accept coding!

    1. Alter the bbPress user profile page–adding new fields, editing existing fields and removing fields

    Try my plugin https://wordpress.org/plugins/bbp-profile-information/

    Lets you add 4 profile fields for users to update and you can optionally display these under the avatar on topics and replies.

    If you want to remove fields – that’s code, but let me know which ones you want to remove, and I’ll take a look.


    Robin W
    Moderator

    @robin-w

    2. Add a link to the bbPress Login Widget for users to edit their profiles (instead of clicking their names…clicking their names doesn’t seem obvious to me)

    Can’t d0 that without coding, but my plugin
    https://wordpress.org/plugins/bbp-style-pack/

    will let you add this (and optionally register and login/logout) to the menu bar

    Install and then

    go into Dashboard>settings>bbp style pack>login and take a look


    Robin W
    Moderator

    @robin-w

    3. Completely hide any backend/admin type stuff from non-admin users so that they never leave the frontend part of the site

    I agree – I hate that part as well

    use

    https://wordpress.org/plugins/hide-admin-bar-from-non-admins/


    elucidateTX
    Participant

    @elucidatetx

    Thanks so much! I love your plugin. A followup question, I’d like to include your fields in the registration template. It looks like they’re called rpi_label1, etc. Any thoughts on how to do this?


    Robin W
    Moderator

    @robin-w

    Thought you said you hated code?!! 🙂

    Have you a specific registration template in mind, does your theme come with something?


    elucidateTX
    Participant

    @elucidatetx

    Thought you said you hated code?!! 🙂

    Have you a specific registration template in mind, does your theme come with something?

    Ha no I don’t hate code! I’m just not any good at it yet. I’m using the Genesis Enterprise Pro theme.

    Here’s what I tried:
    1. Created a page and dropped the [bbp-register] shortcode into it.
    2. Copied the form-user-register.php file into the bbpress directory in my theme folder
    3. I added this form of code for each of the four rpi_label classes:

    `<div class=”rpi_label1″>
    <label for=”rpi_label1″><?php _e( ‘Class’, ‘bbpress’ ); ?>: </label>
    <input type=”text” name=”rpi_label1″ value=”<?php bbp_sanitize_val( ‘rpi_label1’ ); ?>” size=”20″ id=”rpi_label1″ tabindex=”<?php bbp_tab_index(); ?>” />
    </div>
    …for this one it’s an input field for the Class of my user

    Am I on the right track? The data entered doesn’t seem to be making it into the user database. After filling out the registration form for a test user…then going to edit the user…the data isn’t listed.

    Thanks!


    Robin W
    Moderator

    @robin-w

    good start, but that approach gets very complicated, as whilst you have added the fields, you have not saved them or said where to save them – that requires a whole bunch of other code !

    Easier approach :

    bbpress uses wordpress registration, so it’s easier to hook to that.

    The whole bunch of code below is not my original work (but I do use it on one of my sites, so know it works) but if you have a play with it, you should be able to adapt it.

    `//add code for adding first and last name to registration

    //1. Add a new form element…
    add_action(‘register_form’,’myplugin_register_form’);
    function myplugin_register_form (){
    $first_name = ( isset( $_POST[‘first_name’] ) ) ? $_POST[‘first_name’]: ”;
    $last_name = ( isset( $_POST[‘last_name’] ) ) ? $_POST[‘last_name’]: ”;
    ?>
    <p>
    <label for=”first_name”><?php _e(‘First Name as people call you eg Dave’,’mydomain’) ?><br />
    <input type=”text” name=”first_name” id=”first_name” class=”input” value=”<?php echo esc_attr(stripslashes($first_name)); ?>” size=”25″ /></label>
    </p>
    <p>
    <label for=”last_name”><?php _e(‘Last Name’,’mydomain’) ?><br />
    <input type=”text” name=”last_name” id=”last_name” class=”input” value=”<?php echo esc_attr(stripslashes($last_name)); ?>” size=”25″ /></label>
    </p>
    <?php
    }

    //2. Add validation. In this case, we make sure first_name and last_name is required.
    add_filter(‘registration_errors’, ‘myplugin_registration_errors’, 10, 3);
    function myplugin_registration_errors ($errors, $sanitized_user_login, $user_email) {

    if ( empty( $_POST[‘first_name’] ) )
    $errors->add( ‘first_name_error’, __(‘ERROR: You must include a first name.’,’mydomain’) );
    if ( empty( $_POST[‘last_name’] ) )
    $errors->add( ‘last_name_error’, __(‘ERROR: You must include a last name.’,’mydomain’) );

    return $errors;
    }

    //3. Finally, save our extra registration user meta.
    add_action(‘user_register’, ‘myplugin_user_register’);
    function myplugin_user_register ($user_id) {
    if ( isset( $_POST[‘first_name’] ) )
    update_user_meta($user_id, ‘first_name’, $_POST[‘first_name’]);
    if ( isset( $_POST[‘last_name’] ) )
    update_user_meta($user_id, ‘last_name’, $_POST[‘last_name’]);
    }

    in essence start by looking at the end – 3. save

    and the line

    update_user_meta($user_id, ‘first_name’, $_POST[‘first_name’]);

    this is updating a user_meta field called ‘first_name’ for the user_id $user_id with the information entered in $_POST[‘first_name’]

    So it is saving the first name the user enters in a user_meta field for that user called ‘first_name’

    My plugin stores the data in a user_meta field called ‘rpi_label1’, so a find/replace to change ‘first_name’ to ‘rpi_label1’ is what is needed throughout the code. then some tidying up of things like the prompts and you should have it working.

    Give it a go, and see how you get on. IF you get it working, the deal is you post the result back here, and I can nick it for the plugin (and give you a credit) !

    If you don’t then come back with how you are getting on, and I’ll help – too tied up to do all the work myself !

    This code by the way goes in your functions file see

    Functions files and child themes – explained !


    elucidateTX
    Participant

    @elucidatetx

    Thank you again for your time on this. I’m not a coder, and I don’t really feel like I have any idea what I’m doing here. But I tried to follow your instructions. Here’s what I did:
    1. I downloaded the functions.php file from my theme folder and opened it to edit in Notepad++
    2. I inserted the code you have above and then did a find/replace. I found first_name and replaced it with rpi_label1. I did the same for last_name and rpi_label2
    3. Here is the resulting code:

    //* Code addition for bbP Profile Information Plugin
    add_action(‘register_form’,’myplugin_register_form’);
    function myplugin_register_form (){
    	$rpi_label1 = ( isset( $_POST[‘rpi_label1’] ) ) ? $_POST[‘rpi_label1’]: ”;
    	$rpi_label2 = ( isset( $_POST[‘rpi_label2’] ) ) ? $_POST[‘rpi_label2’]: ”;
    	?>
    	<p>
    	<label for=”rpi_label1”><?php _e(‘First Name as people call you eg Dave’,’mydomain’) ?><br />
    	<input type=”text” name=”rpi_label1” id=”rpi_label1” class=”input” value=”<?php echo esc_attr(stripslashes($rpi_label1)); ?>” size=”25″ /></label>
    	</p>
    	<p>
    	<label for=”rpi_label2”><?php _e(‘Last Name’,’mydomain’) ?><br />
    	<input type=”text” name=”rpi_label2” id=”rpi_label2” class=”input” value=”<?php echo esc_attr(stripslashes($rpi_label2)); ?>” size=”25″ /></label>
    	</p>
    	<?php
    }
    
    add_filter(‘registration_errors’, ‘myplugin_registration_errors’, 10, 3);
    function myplugin_registration_errors ($errors, $sanitized_user_login, $user_email) {
    	if ( empty( $_POST[‘rpi_label1’] ) )
    	$errors->add( ‘rpi_label1_error’, __(‘ERROR: You must include a first name.’,’mydomain’) );
    	if ( empty( $_POST[‘rpi_label2’] ) )
    	$errors->add( ‘rpi_label2_error’, __(‘ERROR: You must include a last name.’,’mydomain’) );
    	return $errors;
    }
    
    add_action(‘user_register’, ‘myplugin_user_register’);
    function myplugin_user_register ($user_id) {
    	if ( isset( $_POST[‘rpi_label1’] ) )
    	update_user_meta($user_id, ‘rpi_label1’, $_POST[‘rpi_label1’]);
    	if ( isset( $_POST[‘rpi_label2’] ) )
    	update_user_meta($user_id, ‘rpi_label2’, $_POST[‘rpi_label2’]);
    }
    

    Unfortunately it doesn’t seem to be working. I got an error code that reads:
    Parse error: syntax error, unexpected ‘Name’ (T_STRING) in functions.php on line 119

    Line 119 reads:
    <label for=”rpi_label1”><?php _e(‘First Name as people call you eg Dave’,’mydomain’) ?><br />

    Any further help you can provide would be really appreciated.


    Robin W
    Moderator

    @robin-w

    sorry I’m not ignoring you or abandoning you, I’d like to get this working as well, but one of my plugins is causing users issues, so have diverted my attention to that.

    Just try pasting this into the line

    <label for="rpi_label1"><?php _e('First Name as people call you eg Dave','mydomain') ?><br />
    

    If I’m right it will fall over on the next line, and I can tell you the issue.

    If not, I’ll load you code into my test site and kick it when I get out from my plugin issue


    Robin W
    Moderator

    @robin-w

    ok, I’ve kicked the code around an adding this to your functions file will fix it.

    I may add it as an option to the profile at some stage, but not likely that soon, so paste this code into your functions file

    //* Code addition for bbP Profile Information Plugin
    add_action('register_form','myplugin_register_form');
    function myplugin_register_form (){
    	$rpi_label1 = ( isset( $_POST['rpi_label1'] ) ) ? $_POST['rpi_label1']: '';
    	$rpi_label2 = ( isset( $_POST['rpi_label2'] ) ) ? $_POST['rpi_label2']: '';
    	?>
    	<p>
    	
    	<p>
    		<label for="rpi_label1"><?php echo $rpi_options['item1_label'] ; ?><br />
    		<input type="text" name="rpi_label1" id="rpi_label1" class="input" value="<?php echo esc_attr(stripslashes($rpi_label1)); ?>" size="25" /></label>
    		</p>
    		<p>
                <label for="rpi_label2"><?php echo $rpi_options['item2_label'] ; ?><br />
            <input type="text" name="rpi_label2" id="rpi_label2" class="input" value="<?php echo esc_attr(stripslashes($rpi_label2)); ?>" size="25" /></label>
            </p>
    	
    	
    	<?php
    }
    
    add_filter('registration_errors', 'myplugin_registration_errors', 10, 3);
    function myplugin_registration_errors ($errors, $sanitized_user_login, $user_email) {
    	if ( empty( $_POST['rpi_label1'] ) )
    	$errors->add( 'rpi_label1_error', __('ERROR: You must include a first name.','mydomain') );
    	if ( empty( $_POST['rpi_label2'] ) )
    	$errors->add( 'rpi_label2_error', __('ERROR: You must include a last name.','mydomain') );
    	return $errors;
    }
    
    add_action('user_register', 'myplugin_user_register');
    function myplugin_user_register ($user_id) {
    	if ( isset( $_POST['rpi_label1'] ) )
    	update_user_meta($user_id, 'rpi_label1', $_POST['rpi_label1']);
    	if ( isset( $_POST['rpi_label2'] ) )
    	update_user_meta($user_id, 'rpi_label2', $_POST['rpi_label2']);
    }
    
    

    angelfire4xx
    Participant

    @angelfire4xx

    I’d like to hide the whole “Account” section from a user’s BBpress Profile Edit interface (Username, Email, password, language fields).
    Can anyone advise the best way to do this?

Viewing 13 replies - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.
Skip to toolbar