Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] is it possible to let users set a field only limited times?


  • Masoud
    Participant

    @masoud1111

    hi.
    i was wondering if it is possible to let the users, set their data on some special field only once.
    let’s say email for example.

    1) in the buddypress registration form they set a valid email.
    2) get activation email , and enter to profile
    3) change their email (and activate the second email)
    4) they want to change their email again. but they cannot because they reached edit limitaion
    this is what i meant by that…
    setting a rule somehow (which i dont know how) for users to change a field only a limited times, for exapmle only 2 times! not more than 2 times.

    tnx for answer.

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

  • shanebp
    Moderator

    @shanebp

    You need to track the number of times an email is changed – probably by creating and setting a user_meta field.
    Try using this hook found in: bp-xprofile\bp-xprofile-screens.php
    do_action( 'xprofile_profile_field_data_updated', $field_id, $value );

    Then create a template overload of the profile/edit.php template and add a conditional that checks that user_meta field.


    Masoud
    Participant

    @masoud1111

    @shanebp
    hi, and thanks for your attention.
    i edited my answer! i read your answer more carefully.
    is it still possible to use the hook you mentioned even for custom-user-meta?
    i’ve created a custom meta, and want to get it from users, only for limited times.
    so do_action( ‘xprofile_profile_field_data_updated’, $field_id, $value )
    what can i use for $field_id?
    and for $value?
    sorry again, i have to read more abt hooks cause i know nothing abt them.
    thanks again.


    shanebp
    Moderator

    @shanebp

    $field_id and $value are arguments passed to whatever function you hook into xprofile_profile_field_data_updated. Check the $field_id in your function to see if it matches the id for the email field – if it does, create a user_meta value.

    Read about do_action and update_user_meta


    Masoud
    Participant

    @masoud1111

    @shanebp
    hi. tnx for answer and patience. got 5 more minutes? 🙂
    i read and worked on what you said. and if i want to be honest, i could’t do anything special unfortunately.
    now, i want to ask your opinion about this idea:
    i’ve come up with the idea of hiding that field. (not email field), how?
    with the use of if condition… (if it’s not empty show it. if it has data, hide it)!
    ——-
    i’ve created a custom-meta with this code in theme functions:

    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;
    /* Copy and paste this line for additional fields. */
    add_user_meta( $user_id, ‘person_relation’, 30318 );
    update_usermeta( absint( $user_id ), 'person_relation', wp_kses_post( $_POST['person_relation'] ) );
    update_user_meta( $user_id, 'person_relation', $_POST['person_relation'] );
    }

    and used it in my buddypress signup form, to get data from users. ok?
    after what you said, i went to edit.php (copy to my theme buddypress folder…)
    and added these codes. but it seems that they do not recieve/send data at all.
    it looks like they are empty!! 😐
    after <?php at the start,
    i added :

    global $user, $user_id;
    $person_relation = get_the_author_meta( 'person_relation', $user->ID );
    $user_id = get_current_user_id();

    and in the <form> ,
    i added this piece of code (not working)
    then copied and changed the “save changes button”.
    so there is 2 buttons. one is for my-custom-meta, and the other is for buddypress form.
    buddypress edit page
    if user writes the name and click save. the box/button, all should gone. and i have to see the data in Users admin panel.
    but nothing is getting save… and i dont know where am i doing it wrong

    <?php if( $person_relation == '' ): ?>
    <tr>
    <th><label for="person_relation">Invitor's Name</label></th>
    <td>
    <input type="text" name="person_relation" id="person_relation" value="<?php update_usermeta( $user_id, 'person_relation', $_POST['person_relation'] ); ?>" class="regular-text" /><br />
    <span class="description">Please enter your invitor's name.</span>
    </td>
    </tr>
    <input type="hidden" id="userID" value="<?php echo $user_id ?>"/>
    <div class="submit">
    <input type="submit" name="profile-group-edit-submit" id="profile-group-edit-submit" value="<?php esc_attr_e( 'Save Name', 'buddypress' ); ?> " />
    </div>
    <input type="hidden" name="person_relation" id="person_relation" value="<?php update_usermeta( $user_id, 'person_relation', $_POST['person_relation'] ); ?>" />
    <?php add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); ?>
    <?php add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' ); ?>
    <?php do_action( 'xprofile_profile_field_data_updated'); ?>
    <?php endif; ?>

    so sorry for long description. tnx for help.
    any suggestions do you have?


    shanebp
    Moderator

    @shanebp

    >any suggestions do you have?

    Forget your new idea and go back and try using my suggestion again.


    Masoud
    Participant

    @masoud1111

    @shanebp tnx a lot 😀
    please mark this topic as resolved. i used your suggestion, and sorted it out. it’s ok now.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] is it possible to let users set a field only limited times?’ is closed to new replies.
Skip to toolbar