Membership: Hooks and Vars

Hello,

I'm building a membership site with your membership-plugin and need some explanations:

1. I need to create a post automatically for every user upon registration. If someone signs up via membership registration page, does this use the standart wordpress functions? Can I still use the wp action-hooks and filters like 'user_register'?
I'd like to add this function without editing the code of the membership plugin directly. Because I want to be able to update it without any further work.

2. Is there a way to add a formfield to the registration form? It would be great to request the prename and name of the user to create the post.

3. Is there an Array or Object containing the user level / subscription informations, if a user ist logged in?

Membership 1.0.5 on single blog WP 3.0.2

Thanks,
Jan

  • Mason

    Hiya Jabre,

    First off, welcome to WPMU DEV! :smiley:

    I'll ask a couple of the developers to respond as to the best way to add fields to the registration form.

    As for #1, you could do this (and a whole heap more) through our New Blog Templates plugin. It allows you to create a lot of things with each new site by default. Check it out here:
    https://premium.wpmudev.org/project/new-blog-template

    Hope this helps!

    Thanks!

  • jabre

    @uakami:
    I have a custom post type template as extendet user profile and need to decide for each customfield on user-level-base if a user can see it, edit it (via front-end-editor) or see it but can't edit it.
    Therefore I've written the following function:

    /* builds an array that can contain
    ** author = 1 if user is post author
    ** level = array of levels the user belongs to ('level_id' > 'level name'
    ** type = type of user based on the level (e.g. Customer or Vendor)
    */
    function jbr_get_user( $user_id, $author_id = '' ) {
    // if user is not logged in
    if( empty( $user_id ) ) { return false; }
    $user_raw = array();
    // if we are on a custom-post-type-single 'profile' and there is a post author id
    if( is_singular('profile') && !empty( $author_id ) ) {
    // is the user the post-author? Then set author to 1
    if ( $user_id == $author_id) { $user_raw['author'] = 1; }
    // if the current user is not a member return.
    if ( !current_user_is_member() ) { return $user_raw; }
    // get an array of the levels the user belongs to
    $user_levels = jbr_get_user_level( $user_id );
    // set user type (there are two different types on my site)
    if ( count( $user_levels ) > 0 ) {
    $user_raw['level'] = $user_levels;
    $user_raw['type'] = 'Customer';
    foreach ($user_levels as $key => $value) {
    $pos = strripos( $value, 'Vendor');
    if ( $pos !== false ) { $user_raw['type'] = 'Vendor'; }
    }
    }
    }
    // if there is one or more user levels, return array else return false
    if ( count( $user_raw ) > 0 ) {
    return $user_raw;
    } else {
    return false;
    }
    }
    // get levels a user belongs to. I use it to get the userlevel of a post author too.
    function jbr_get_user_level( $user_id = '' ) {
    // get level ids the user belongs to
    $member = new M_Membership( $user_id );
    $saa = $member->get_level_ids();
    // make it an array with 'level_id' => 'level title'
    $levels = array();
    if(!empty($saa)) {
    foreach( (array) $saa as $key => $lev ) {
    $mlv = new M_Level( $lev->level_id, true );
    $levels[$lev->level_id] = $mlv->level_title();
    }
    }
    return $levels;
    }
    // and in the custom post template I call my functions:
    if( is_user_logged_in() ) {
    $jbr_user = jbr_get_user( $current_user->ID, $post->post_author);
    } else {
    ...
    }

    `

    Hope that helps.

  • jabre

    I've got it! :slight_smile:

    The WP-action 'user_register' is working. That was my fault. Little example:
    add_action('user_register', 'mySaveMyFields',10,1);
    function mySaveMyFields( $user_id ) {
    $userdata = array();
    $userdata['ID'] = $user_id;
    $userdata['first_name'] = $_POST['jbr_user_firstname'];
    $userdata['last_name'] = $_POST['jbr_user_name'];
    wp_update_user($userdata);
    }

    The following action/filter just work on the normal registration form. For buddypress-registration they have other names!

    To add a field to the registration-form you can use the action: "membership_subscription_form_registration_presubmit_content"
    add_action('membership_subscription_form_registration_presubmit_content','myFunctionEchoingFields',10,0);
    To validate the input you can use the filter "membership_subscription_form_before_registration_process"
    add_filter('membership_subscription_form_before_registration_process',myValidatingFunction',10,1);
    function myValidatingFunction( $error ) {
    if ( empty( $_POST['xyz'] ) ) {
    $error[] = 'Please add xyz.';
    }
    return $error;
    }

  • Barry

    If you have look in the simple.invites.php file with the membershipincludes/plugins directory then you can see how those hooks work.

    Also, there are a few hooks in the membership class and in the main registration side of things apart from the standard wp hooks, which are also still called. I don't have the code in front of me at the moment but the class.members.php file (I think) and the main membershippublic.php file (function called do_subscriptionshortcode I think, has most of them in.