Open BoweFrankema opened 9 years ago
I've managed to get this working very easily, although I hardcoded some things we'd probably need to make dynamic!
if ( function_exists( 'bp_is_member' ) ) {
/**
* Add Give Donations Page
*
*/
function give_bp_setup_donations(){
global $bp;
$profile_link = bp_loggedin_user_domain() . $bp->profile->slug . '/';
$args = array(
'name' => __('My Donations','cfctranslation'),
'slug' => 'my-donations',
'parent_url' => $profile_link,
'parent_slug' => $bp->profile->slug,
'screen_function' => 'screen_give_donations',
'user_has_access' => ( bp_is_my_profile() || is_super_admin() ),
'position' => 40
);
bp_core_new_subnav_item($args);
}
add_action( 'bp_setup_nav', 'give_bp_setup_donations' );
function screen_give_donations(){
global $bp;
add_action( 'bp_template_title', 'give_bp_page_title');
add_action( 'bp_template_content', 'give_bp_page_content');
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function give_bp_page_title(){
echo __('Your Donations','cfctranslation');
}
function give_bp_page_content(){?>
<div id="give-my-donations">
<?php
echo do_shortcode('[donation_history]');
?>
</div>
<div>
Make a donation
<?php
echo do_shortcode('[give_form id="688"]');
?>
</div>
<?php
}
function setup_give_donations () {
if ( !is_admin() ) {
add_action( 'bp_xprofile_setup_nav', 'give_bp_setup_donations' );
}
}
add_action('wp', 'setup_give_donations');
}
function bp_give_redirect()
//Redirect logged in users from give page to BuddyPress page
{
if( is_user_logged_in() && is_page('donations') )
{
global $bp;
wp_redirect( bp_loggedin_user_domain() . $bp->profile->slug . '/my-donations/', 301 );
exit();
}
}
add_action('wp','bp_give_redirect');
Should I integrate this into the plugin?
Yep! Let's do this :dancer:
This has now been incorporated. With reference to the hard-coded things, there's currently some outstanding tasks:
Show a Donation Form on the User Dashboard? Please fill in the donation ID below: [input]
This is now done. If you go to Donations > BuddyPress you can specify a form ID (see Label 4), which will result in that particular form appearing under the list of donations on "/members/username/my-donations".
Testing it highlighted some minor bugs so I've fixed those too.
If you have any trouble when testing, just delete the old bpg-options meta key from the options table so we can start afresh (but I doubt you will need to).
We should integrate the dashboard into a users profile if they have an account. I've done this before for EDD and I did the following
Output the shortcode for the dashboard directly into the new member screen template like this:
Full snippet can be seen here;
https://gist.github.com/BoweFrankema/685d5a52ef98a29cdc6a#file-edd-buddypress-purchase-php
This worked for me, but I'm sure it can be improved. Especially retrieving the "Donation Dashboard" page without hardcoding the slug!