This topic has 5 replies, 2 voices, and was last updated 10 years by alberhd.

  • Author
  • #25286
     alberhd
    Participant

    I have this fail,when i add the code in sweetdate-child/functions.php

    Fatal error: Cannot redeclare kleo_pmpro_default_level() (previously declared in /homepages/43/d524894821/htdocs/wp-content/themes/sweetdate-child/functions.php:87) in /homepages/43/d524894821/htdocs/wp-content/themes/sweetdate-child/functions.php on line 116

    #25510
     Catalin
    Moderator

    that error appears because probably you already declared it in the functions.php file from your child theme…

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #25512
     alberhd
    Participant

    Do you say that probably is because the code is already entered on /sweetdate-child/functions.php?

    Is the first time that i enter this code,but i will check,thank you for your help.

    Im talking about this code: https://archived.seventhqueen.com/forums/topic/membership-auto-in-registration

    #25513
     alberhd
    Participant

    Ah ok,maybe i know the problem,i enter both codes,confusion! and is just one of them, right?

    COPY CODE
    add_action('user_register', 'kleo_pmpro_default_level');
    function kleo_pmpro_default_level($user_id) {
    	pmpro_changeMembershipLevel(1,$user_id);
    }

    OR

    COPY CODE
    /**
    * When registering, add the member to a specific membership level
    * based on the field value he has selected
    *
    * @global object $wpdb
    * @global object $bp
    * @param integer $user_id
    */
    function kleo_pmpro_default_level($user_id) {
        global $wpdb, $bp;
     
        //Change this with your field name
        $field_name= "I am a";
     
        //Change the field value
        $value_to_match = "Woman";
     
        //Membership level id
        $membership_level = 1;
     
        //Done editing
        $field_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", $field_name ) );
        if ($_POST['field_'.$field_id] == $value_to_match) {
                pmpro_changeMembershipLevel($membership_level, $user_id);
        }
    }
     
    function kleo_mu_pmpro_default_level($user_id, $password, $meta) {
        global $bp, $wpdb;
     
        //Change this with your field name
        $field_name= "I am a";
     
        //Change the field value
        $value_to_match = "Woman";
     
        //Membership level id
        $membership_level = 1;
     
        
        //Done editing
        $field_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", $field_name ) );
        $field_value = $meta['field_'.$field_id];
        if ( $field_value == $value_to_match ) {
            pmpro_changeMembershipLevel($membership_level, $user_id);
        }
    }
     
    if (is_multisite()) {
        add_action( 'wpmu_activate_user', 'kleo_mu_pmpro_default_level', 10, 3);
    } else {
        add_action('user_register', 'kleo_pmpro_default_level');
    }

    If I understand good the first code,if I create a membership free,that on the list of the plugin is the membership number 1,when the user will enter on the page,automatically they will have this membership right?

    #25570
     Catalin
    Moderator

    please tell me what you want to achieve in your site.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #25576
     alberhd
    Participant

    Thank you for your help,this problem Fixed

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

The topic ‘Assign default Membership level at registration (Problem)’ is closed to new replies.

Log in with your credentials

Forgot your details?