Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the donation dashboard to the user profile #7

Open
BoweFrankema opened this issue Apr 10, 2015 · 6 comments
Open

Add the donation dashboard to the user profile #7

BoweFrankema opened this issue Apr 10, 2015 · 6 comments
Assignees
Milestone

Comments

@BoweFrankema
Copy link
Member

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

  1. Create a new BP profile screen + BP nav item

  2. Output the shortcode for the dashboard directly into the new member screen template like this:

            <?php
                echo do_shortcode('[purchase_history]');
        ?>
    
  3. Do a template redirect on the page that is used for the shortcode like shown here:
    https://gist.github.com/BoweFrankema/9f9b34235a1f43e3df88

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!

@BoweFrankema BoweFrankema added this to the 1.0 milestone Apr 10, 2015
@BoweFrankema
Copy link
Member Author

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');

screenshot 2015-04-13 16 58 06

@henrywright
Copy link
Contributor

Should I integrate this into the plugin?

@BoweFrankema
Copy link
Member Author

Yep! Let's do this 💃

@henrywright
Copy link
Contributor

This has now been incorporated. With reference to the hard-coded things, there's currently some outstanding tasks:

  • The "my-donations" slug: Subnav slugs are hard coded throughout BuddyPress, so at least we're currently being consistently bad. But I'm sure we can think of something better?
  • The donation form ID: We need to think of a way around hard coding the donation form ID

@BoweFrankema
Copy link
Member Author

  1. Maybe we could check in the options table.. I see there is an a serialized array saved in the options table as: give_settings and an value of success_page. I think that is saved as a page ID which you could then user for the wp_redirect.
  2. Maybe we would use a hook and add a option to our BuddyPress settings:

Show a Donation Form on the User Dashboard? Please fill in the donation ID below:
[input]

@henrywright
Copy link
Contributor

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants