/**
 * Check to see if a high five is being given, and if so, save it.
 *
 * Hooked to bp_actions, this function will fire before the screen function. We use our function
 * bp_is_example_component(), along with the bp_is_current_action() and bp_is_action_variable()
 * functions, to detect (based on the requested URL) whether the user has clicked on "send high
 * five". If so, we do a bit of simple logic to see what should happen next.
 *
 * @package BuddyPress_Skeleton_Component
 * @since 1.6
 */
function bp_example_high_five_save()
{
    if (bp_is_example_component() && bp_is_current_action('screen-one') && bp_is_action_variable('send-h5', 0)) {
        // The logged in user has clicked on the 'send high five' link
        if (bp_is_my_profile()) {
            // Don't let users high five themselves
            bp_core_add_message(__('No self-fives! :)', 'bp-example'), 'error');
        } else {
            if (bp_example_send_highfive(bp_displayed_user_id(), bp_loggedin_user_id())) {
                bp_core_add_message(__('High-five sent!', 'bp-example'));
            } else {
                bp_core_add_message(__('High-five could not be sent.', 'bp-example'), 'error');
            }
        }
        bp_core_redirect(bp_displayed_user_domain() . bp_get_example_slug() . '/screen-one');
    }
}
 /**
  * Set up your component's navigation.
  *
  * The navigation elements created here are responsible for the main site navigation (eg
  * Profile > Activity > Mentions), as well as the navigation in the BuddyBar. WP Admin Bar
  * navigation is broken out into a separate method; see
  * BP_Example_Component::setup_admin_bar().
  *
  * @global obj $bp
  */
 public function setup_nav($main_nav = array(), $sub_nav = array())
 {
     // Add 'Example' to the main navigation
     $main_nav = array('name' => __('Example', 'bp-example'), 'slug' => bp_get_example_slug(), 'position' => 80, 'screen_function' => 'bp_example_screen_one', 'default_subnav_slug' => 'screen-one');
     $example_link = trailingslashit(bp_loggedin_user_domain() . bp_get_example_slug());
     // Add a few subnav items under the main Example tab
     $sub_nav[] = array('name' => __('Screen One', 'bp-example'), 'slug' => 'screen-one', 'parent_url' => $example_link, 'parent_slug' => bp_get_example_slug(), 'screen_function' => 'bp_example_screen_one', 'position' => 10);
     // Add the subnav items to the friends nav item
     $sub_nav[] = array('name' => __('Screen Two', 'bp-example'), 'slug' => 'screen-two', 'parent_url' => $example_link, 'parent_slug' => bp_get_example_slug(), 'screen_function' => 'bp_example_screen_two', 'position' => 20);
     parent::setup_nav($main_nav, $sub_nav);
     // If your component needs additional navigation menus that are not handled by
     // BP_Component::setup_nav(), you can register them manually here. For example,
     // if your component needs a subsection under a user's Settings menu, add
     // it like this. See bp_example_screen_settings_menu() for more info
     bp_core_new_subnav_item(array('name' => __('Example', 'bp-example'), 'slug' => 'example-admin', 'parent_slug' => bp_get_settings_slug(), 'parent_url' => trailingslashit(bp_loggedin_user_domain() . bp_get_settings_slug()), 'screen_function' => 'bp_example_screen_settings_menu', 'position' => 40, 'user_has_access' => bp_is_my_profile()));
 }
/**
 * bp_example_screen_two()
 *
 * Sets up and displays the screen output for the sub nav item "example/screen-two"
 */
function bp_example_screen_two()
{
    global $bp;
    /**
     * On the output for this second screen, as an example, there are terms and conditions with an
     * "Accept" link (directs to http://example.org/members/andy/example/screen-two/accept)
     * and a "Reject" link (directs to http://example.org/members/andy/example/screen-two/reject)
     */
    if (bp_is_example_component() && bp_is_current_action('screen-two') && bp_is_action_variable('accept', 0)) {
        if (bp_example_accept_terms()) {
            /* Add a success message, that will be displayed in the template on the next page load */
            bp_core_add_message(__('Terms were accepted!', 'bp-example'));
        } else {
            /* Add a failure message if there was a problem */
            bp_core_add_message(__('Terms could not be accepted.', 'bp-example'), 'error');
        }
        /**
         * Now redirect back to the page without any actions set, so the user can't carry out actions multiple times
         * just by refreshing the browser.
         */
        bp_core_redirect(bp_loggedin_user_domain() . bp_get_example_slug());
    }
    if (bp_is_example_component() && bp_is_current_action('screen-two') && bp_is_action_variable('reject', 0)) {
        if (bp_example_reject_terms()) {
            /* Add a success message, that will be displayed in the template on the next page load */
            bp_core_add_message(__('Terms were rejected!', 'bp-example'));
        } else {
            /* Add a failure message if there was a problem */
            bp_core_add_message(__('Terms could not be rejected.', 'bp-example'), 'error');
        }
        /**
         * Now redirect back to the page without any actions set, so the user can't carry out actions multiple times
         * just by refreshing the browser.
         */
        bp_core_redirect(bp_loggedin_user_domain() . bp_get_example_slug());
    }
    /**
     * If the user has not Accepted or Rejected anything, then the code above will not run,
     * we can continue and load the template.
     */
    do_action('bp_example_screen_two');
    add_action('bp_template_title', 'bp_example_screen_two_title');
    add_action('bp_template_content', 'bp_example_screen_two_content');
    /* Finally load the plugin template file. */
    bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
}
/**
 * Echo the component's slug
 *
 * @package BuddyPress_Skeleton_Component
 * @since 1.6
 */
function bp_example_slug()
{
    echo bp_get_example_slug();
}