Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

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

  • barodscheff
    Participant

    @barodscheff

    Ok, I solved it with page templates.
    Thank you for your help!


    barodscheff
    Participant

    @barodscheff

    Thank you @henrywright. Maybe my question wasn’t clear enough.

    I’ve already copied the code in a custom template. But how do I call the template? What should be the link target? What do I have to write instead of # to call the template with the filtering (e.g. male members with poodles)
    <a href="#">All male members who have poodles</a>


    barodscheff
    Participant

    @barodscheff

    Thank you but your solution is outdated. I’ve found it also while searching.
    And thats the big problem with buddypress. There was an update about one year ago and everything changed. So nearly all common customizations do not work any more.

    Thats the reason why the plugin ‘buddypress custom profile menu’ also doesn’t function anymore.

    Fortunately I found the solution. It looks like this:

    function profile_new_nav_item() {
    
    		global $bp;
    
    		bp_core_new_nav_item(
    			array(
    				'name'                => 'Contact Athlete',
    				'slug'                => 'contact_athlete',
    				'default_subnav_slug' => 'extra_sub_tab',
    				'position'            => 160,
    				'screen_function'     => 'view_manage_tab_main'
    			)
    		);
    	}
    
    	add_action( 'bp_setup_nav', 'profile_new_nav_item', 10 );
    	
    	// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    
    	function view_manage_tab_main() {
    		add_action( 'bp_template_content', 'bp_template_content_main_function' );
    		bp_core_load_template( 'template_content' );
    	}
    
    	function bp_template_content_main_function() {
    		if ( ! is_user_logged_in() ) {
    			wp_login_form( array( 'echo' => true ) );
    		}
    	}
    	
    	// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    
    	function profile_new_subnav_item() {
    		
    		global $bp;
    
    		bp_core_new_subnav_item( 
    			array(
    				'name'            => 'Extra Sub Tab',
    				'slug'            => 'extra_sub_tab',
    				'parent_url'      => $bp->loggedin_user->domain . $bp->bp_nav[ 'contact_athlete' ][ 'slug' ] . '/',
    				'parent_slug'     => $bp->bp_nav[ 'contact_athlete' ][ 'slug' ],
    				'position'        => 10,
    				'screen_function' => 'view_manage_sub_tab_main'
    			) 
    		);
    	}
    	
    	// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    
    	add_action( 'bp_setup_nav', 'profile_new_subnav_item', 10 );
    
    	function view_manage_sub_tab_main() {
    		add_action( 'bp_template_content', 'bp_template_content_sub_function' );
    		bp_core_load_template( 'template_content' );
    	}
    
    	function bp_template_content_sub_function() {
    		if ( is_user_logged_in() ) {
    			bp_get_template_part('my-contact-form');
    		} else {
    			wp_login_form( array( 'echo' => true ) );
    		}
    	}

    I hope it helps anyone.

    Finally I’d like to say that I have never seen such a bad documentation in development as in buddypress. I know buddypress is free but WordPress is free too and they have a great doc.


    barodscheff
    Participant

    @barodscheff

    Thank you for the answer but my problem is the url. I have no idea how to generate the custom url.

    If I use the build in function (xprofile_links) in members area and click e.g. on ‘Soccer’ I will get a new page with all members who also have soccer as their sport. The url is like ‘my-url/members/?s=Soccer’. But I need two filters. One for ‘sport’ and one for ‘gender. Something like ‘my-url/members/?s=Soccer&s=male’ is not working.

    Maybe you know the right url structure?

    Anyway I think this in not the best solution. Is there a way to use the xprofile_link function which is build in? I removed it in the members area with

    function remove_xprofile_links() {
       remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
    }
    add_action( 'bp_init', 'remove_xprofile_links' );	

    But I would like to apply it on my landing page. Is that possible?


    barodscheff
    Participant

    @barodscheff

    Yes, of course.
    I would like to link the sports which are profile fields. For instance if you click on male/Basketball you should get an overview of all members who are also male and do the sport Basketball.
    This is automatically possible in members loop but I would like to have it on my landing page.

    I hope it’s clear now.


    barodscheff
    Participant

    @barodscheff

    No one?


    barodscheff
    Participant

    @barodscheff

    Maybe I should explan more in detail what I’m trying to achieve.

    After the members loop I have added a custom template (my-contact-form.php). This template just calls the Plugin Contact Form 7:
    echo do_shortcode( '[contact-form-7 id="1235" title="Contact form 1"]' );

    So a contact form is displayed after a members profile.
    Now I would like to make it possible to write an email to the member in the contact form. The advantage is that the visitor doesn’t need to be logged in.

    So in bp-custom.php I have now the following:

    function mycf7_before_send_mail($WPCF7_ContactForm) {
    	
    	$new_recipient = xprofile_get_field_data('Email for contact', bp_displayed_user_id(), $multi_format = 'comma');
    	$mail = $WPCF7_ContactForm->prop('mail');
    	$mail['recipient'] = $new_recipient;
    	$WPCF7_ContactForm->set_properties( array( 'mail' => $mail ) );
    	
    }  
    add_action( "wpcf7_before_send_mail", "mycf7_before_send_mail" );

    It does not work. But when I change the xprofile_get… to a concrete email it does work. For instance:

    // Custom Recipient
    function mycf7_before_send_mail($WPCF7_ContactForm) {
    	
    	$new_recipient = "recipient@email.de";
    	$mail = $WPCF7_ContactForm->prop('mail');
    	$mail['recipient'] = $new_recipient;
    	$WPCF7_ContactForm->set_properties( array( 'mail' => $mail ) );
    	
    }  
    add_action( "wpcf7_before_send_mail", "mycf7_before_send_mail" );

    At the same time the email of the member is displayed if I echo it with echo xprofile_get_field_data('Email for contact', bp_displayed_user_id(), $multi_format = 'comma'); in the my-contact-form.php.

    So the problem is that the function xprofile_get… is just working in themy-contact-form.php. Any suggestions?


    barodscheff
    Participant

    @barodscheff

    Still the same problem 🙁


    barodscheff
    Participant

    @barodscheff

    No unfortunately not.
    If I echo the code directly in the page template it works. My code did it too. But both do not work in the funtions.php.


    barodscheff
    Participant

    @barodscheff

    I just forgot one question.
    Is there a way to call this query in the backend editor?
    I’m using the visual composer and would like to call the query / php template in the editor.


    barodscheff
    Participant

    @barodscheff

    Ok, I solved it.
    For those who are interested in the solution: you have to use the prefix

    // Set $wpdb global =  WPrequirement
    global $wpdb;
    
    // Get all male members from DB
    $male = $wpdb->get_var( "SELECT COUNT(user_id) FROM ar_bp_xprofile_data WHERE value = 'male' AND user_id IN (SELECT user_id FROM ar_bp_xprofile_data WHERE value = 'Soccer')" );
    echo 'Male: ' . $male . '<br>';
    
    // Get all female members from DB
    $female = $wpdb->get_var( "SELECT COUNT(user_id) FROM ar_bp_xprofile_data WHERE value = 'female' AND user_id IN (SELECT user_id FROM ar_bp_xprofile_data WHERE value = 'Soccer')" );
    echo 'Female: ' . $female . '<br>';

    Thank you for your help.


    barodscheff
    Participant

    @barodscheff

    Thank you for your answers.

    I’ve tried the example from the wordpress codex:
    $user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );

    It works even when I do not use global $wpdb;.
    First question: Why does it work without global $wpdb?

    Second question: Why do I have to use $wpdb->bp_xprofile_data instead of $wpdb->ar_bp_xprofile_data? Does the prefix do not belong to the name? When I try the query in phpmyadmin I also have to use the prefix.

    Unfortunately my own queries still not work. I simplified my query now:

    global $wpdb;
    $male = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->bp_xprofile_data");
    echo $male;

    barodscheff
    Participant

    @barodscheff

    Ok, I’ve tried the following to display the amount of male and female members first:

    // Get all male members from DB
    $male = $wpdb->get_var( "SELECT COUNT(id) FROM $wpdb->ar_bp_xprofile_data WHERE field_id = 11 AND value LIKE 'male'" );
    // Get all female members from DB
    $female = $wpdb->get_var( "SELECT COUNT(id) FROM $wpdb->ar_bp_xprofile_data WHERE field_id = 11 AND value LIKE 'female'" );
    
    // Print amount of male and female members
    echo $male;
    echo $female;
    

    But it’s not working. Any ideas?


    barodscheff
    Participant

    @barodscheff

    Yes, they have.

    The custom mysql queries look pretty interesting. Thank you.


    barodscheff
    Participant

    @barodscheff

    Thank you very much!

    Can you tell me how I can find this on my own in the future?


    barodscheff
    Participant

    @barodscheff

    Thank you.
    Is there maybe a plugin which adds this feature?

Viewing 16 replies - 1 through 16 (of 16 total)
Skip to toolbar