Skip to:
Content
Pages
Categories
Search
Top
Bottom

Make your own custom BuddyPress page

  • @johnjamesjacoby

    Keymaster

    The title of this post makes it a little hard to grasp what I’m talking about, but in short this is a really quick and easy way to make your own hard coded BuddyPress page without going into the WordPress page admin.

    In this example we’re going to make a page called “fun” that you can visit at domain.com/fun.

    Put the following In your home theme’s functions.php file…

    define('BP_EXAMPLE_SLUG', 'fun');
    function bp_show_example_page() {
    global $bp, $current_blog;

    if ( $bp->current_component == BP_EXAMPLE_SLUG && $bp->current_action == '' ) {
    // The first variable here must match the name of your template file below
    bp_core_load_template( 'fun', true );
    }
    }
    add_action( 'wp', 'bp_show_example_page', 2 );

    Now you need to create a fun.php file (mentioned above) in your home theme directory, and inside that file put…

    <?php get_header(); ?>
    <h3>Hello</h3>
    <p>I am an example page.</p>
    <?php get_footer(); ?>

    This could be used to make custom a custom login page, or whatever you’d like…

    All we did here was swipe the exact code BP already uses for the /register and /activate pages, and simplify it for our own use.

    Have fun!

Viewing 17 replies - 26 through 42 (of 42 total)
  • @anonymized-96400

    Inactive

    Try adding this function as well as the original from JJJ.

    function example_page_setup_root_component()
    {
    bp_core_add_root_component( BP_EXAMPLE_SLUG );
    }
    add_action( 'plugins_loaded', 'example_page_setup_root_component', 2 );

    @bpisimone

    Participant

    I’m almost sure I’ve tried this in every possible way, but could not get it to work. Going to report Travel-Junkie’s method as well.

    If you are making this a plugin, can you make sure it does work for child themes as well?

    @21cdb

    Participant

    Thanks to Travel-Junkie it is now working for me.

    Here is what i put in my bp-custom.php (not tested in the themes functions.php)

    define('BP_EXAMPLE_SLUG', 'features');

    function example_page_setup_root_component()
    {
    bp_core_add_root_component( BP_EXAMPLE_SLUG );
    }
    add_action( 'plugins_loaded', 'example_page_setup_root_component', 2 );

    function bp_show_example_page() {
    global $bp, $current_blog;

    if ( $bp->current_component == BP_EXAMPLE_SLUG && $bp->current_action == '' ) {
    // The first variable here must match the name of your template file below
    bp_core_load_template( 'features', true );
    }
    }
    add_action( 'wp', 'bp_show_example_page', 2 );

    It is for a features.php page which is in the root directory of the child theme.

    @bpisimone

    Participant

    What 21cdb described (Travel Junkie’s method) works. Not in the functions.php but at least in bp-custom.

    @lriggle

    Participant

    21CDB’s code works fine with my theme. I’d like my custom page to be in a sub-folder instead of in my root directory, though.

    define('CS_INTUITION_SLUG', 'intuition');

    function show_intuition_page()
    {
    bp_core_add_root_component(CS_INTUITION_SLUG);
    }
    add_action( 'plugins_loaded', 'show_intuition_page', 2 );

    function bp_show_intuition_page() {
    global $bp, $current_blog;

    if ( $bp->current_component == CS_INTUITION_SLUG && $bp->current_action == '' )
    {
    // The first variable here must match the name of your template file below
    bp_core_load_template( 'intuition', true );
    }
    }
    add_action( 'wp', 'bp_show_intuition_page', 2 );

    When I remove the intuition.php file from my root directory, and make an intuition directory with an index.php in it, it doesn’t seem to work (I get 404’s). If I try and change what the value of the slug and the template are as well, I still get 404’s.

    Ideas?

    @xevo

    Participant

    Is it possible to use this for making an extra profile page? For example, “…/members/admin/profile/newpage/”.

    @xevo

    Participant

    Bump, does anyone know (earlier question)?

    @anonymized-96400

    Inactive

    Nope. For an xtra profile page you’ll need to use something like this:

    /**
    * Setup update location nav item
    * @since 1.0
    */
    function sv_xprofile_xtra_nav()
    {
    global $bp;

    $profile_link = $bp->loggedin_user->domain . $bp->profile->slug . '/';

    bp_core_new_subnav_item( array( 'name' => __( 'Update Location', 'scuba' ), 'slug' => 'update-location', 'parent_url' => $profile_link, 'parent_slug' => $bp->profile->slug, 'screen_function' => 'sv_screen_update_location', 'position' => 15 ) );
    }
    add_action( 'xprofile_setup_nav', 'sv_xprofile_xtra_nav' );

    /**
    * Display location update screen
    * @since 1.0
    */
    function sv_screen_update_location()
    {
    if ( !bp_is_home() && !is_site_admin() )
    return false;

    /* Check to see if any new information has been submitted */
    if( isset( $_POST['save'] ) )
    {
    /* Check the nonce */
    check_admin_referer( 'sv_profile_update_location' );

    if( $_POST['user_lat'] && ! $_POST['user_long'] || ! $_POST['user_lat'] && $_POST['user_long'] )
    {
    bp_core_add_message( __( 'You need to provide both a latitude and a longitude.', 'scuba' ), 'error' );
    $error = true;
    }

    if( ! $error )
    {
    $lat = apply_filters( 'sv_sanitize_user_input', $_POST['user_lat'] );
    $long = apply_filters( 'sv_sanitize_user_input', $_POST['user_long'] );
    $id = apply_filters( 'sv_sanitize_user_input', $_POST['user_id'] );

    $loc = array(
    'user_lat' => $lat,
    'user_long' => $long
    );

    update_usermeta( $id, 'user_location', $loc );
    bp_core_add_message( __( 'Your location has been updated!', 'buddypress' ) );

    do_action( 'sv_successful_location_update' );
    }
    }

    bp_core_load_template( apply_filters( 'sv_xprofile_template_update_location', 'profile/location' ) );
    }

    Then you obviously need a template file as well in your theme in the profiles folder. I use the above code to let the user pick his geo position on a google map and then I display the users on a flash map on the members directory page.

    @balbert

    Participant

    @Travel-Junkie – thanks for the code.

    That works for a sub item of profile. What if I want to have it be under the member name slug. So to use your example, what if I wanted to load my custom template with /members/[username]/update-location instead of /members/[username]/profile/update-location?

    @sweller

    Participant

    I’d like to open this one back up. The project is for a local recycling program and I’m having trouble with a form for members to schedule pickups on the profile/index page. It calls XProfile address fields and tomorrow’s date for the default values, and should insert them into a custom table. The plugin creates a table and pulls the xprofile data fine, but nothing is reaching the database. I’ve tried every possible variation based on the bp-core and Travel-Junkie’s example above, but nothing is working.

    Here’s the plugin:

    <?php
    /*
    Plugin Name: Collection Records
    Plugin URI: -
    Description: Adds a table and page for listing and editing Recylable Collections.
    Version: 1.0
    */

    function collect_install_table() {
    global $wpdb;
    global $bp;

    if ( !empty($wpdb->charset) )
    $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";

    $table_name = $wpdb->prefix . 'collections';
    if($wpdb->get_var("show tables like '$table_name'") != $table_name) {

    $sql = "CREATE TABLE " . $table_name . " (
    id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    sched_date datetime NOT NULL,
    post_date datetime NOT NULL,
    user_id bigint(20) UNSIGNED NOT NULL,
    address_line_1 varchar(150) NOT NULL,
    address_line_2 varchar(150) NOT NULL,
    town varchar(150) NOT NULL,
    state varchar(150) NOT NULL,
    zip_code varchar(150) NOT NULL,
    amount bigint(20) DEFAULT '0' NOT NULL,
    verified tinyint(1) DEFAULT '1' NOT NULL,
    paid tinyint(1) DEFAULT '1' NOT NULL,
    KEY user_id (user_id)
    ) {$charset_collate};";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta($sql);
    }
    }

    /*Launch database*/
    register_activation_hook(__FILE__,'collect_install_table');

    function bp_collections() {
    global $wpdb;
    global $bp;

    /* bp_is_home() Checks to make sure the current user being viewed equals the logged in user */

    if ( !bp_is_home() && !is_site_admin() )
    return false;

    /* Check for new information*/
    if( isset($_POST['go'] ))
    {
    /* Check the nonce */

    check_admin_referer( 'schedule_collect' );

    if( $_POST['sched_date'] && ! $_POST['address_line_1'] || ! $_POST['sched_date'] && $_POST['address_line_1'] )
    {
    bp_core_add_message( __( 'We need a time and a place!', 'buddypress' ), 'error' );
    $error = true;
    }

    if( ! $error )
    {
    $user_id = $bp->loggedin_user->id;

    if( isset( $_POST['address_line_2'] ) ) {
    $address_line_2 = $_POST['address_line_2'];
    }

    $result = $wpdb->query( $wpdb->prepare("
    INSERT INTO $wpdb->1_collections
    ( sched_date, post_date, user_id, address_line_1, address_line_2, town, state, zip_code )
    VALUES ( %s, %s, %d, %s, %s, %s, %s, %s )",
    $_POST['sched_date'], $_POST['post_date'], $user_id, $_POST['address_line_1'], $address_line_2, $_POST['town'], $_POST['state'], $_POST['zip_code'] ) );

    /* Set the feedback messages */
    if ( $errors )
    bp_core_add_message( __( 'There was a problem calling your pickup, please try again.', 'buddypress' ), 'error' );
    else
    bp_core_add_message( __( 'Thanks for calling a recycling pickup.', 'buddypress' ) );

    }

    bp_core_load_template( apply_filters( 'xprofile_template_display_profile', 'profile/index' ) );
    }
    }
    /* Function to call xprofile Address label */

    function collections_xprofile( $field ) {
    echo bp_collections_get_member_list_xprofile_data( $field );
    }
    function bp_collections_get_member_list_xprofile_data( $field ) {
    global $bp, $site_members_template;
    return xprofile_get_field_data( $field, $site_members_template->member->id );
    }

    ?>

    And the form:

    <?php if ( bp_has_profile( 'profile_group_id=' . bp_get_current_profile_group_id() ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>

    <form action="" method="post" id="oncall" class="oncall">

    <label for="address">At</label>
    <input type="text" name="address_line_1" id="address_line_1" value="<?php echo bp_collections_get_member_list_xprofile_data('Address Line 1') ?>" />
    <input type="text" name="address_line_2" id="address_line_2" value="<?php echo bp_collections_get_member_list_xprofile_data('Address Line 2') ?>" />
    <input type="text" name="town" id="town" value="<?php echo bp_collections_get_member_list_xprofile_data('Town') ?>" />
    <input type="hidden" name="state" id="state" value="MS" />
    <input type="" name="zip_code" id="zip_code" value="<?php echo bp_collections_get_member_list_xprofile_data('Zip Code') ?>" />
    <br />
    <label for="date">On</label>
    <input type="text" name="sched_date" id="sched_date" value="<?php $tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y")); echo date("Y/m/d", $tomorrow); ?>" />

    <input type="submit" name="go" id="go" value="go"/>
    <input type="hidden" name="post_date" id="post_date" value="<?php $my_t=getdate(date("U")); print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]"); ?> " />

    <?php wp_nonce_field( 'schedule_collect' ) ?>
    </form>
    <?php endwhile; endif; ?>

    It has to be something simple but I’m lost. I’d really appreciate it if someone could take a minute and tell me what’s wrong with the code.

    @shaisimchi

    Participant

    hey,

    I was able to get this to work but one question:

    when i go to my new page $bp is empty.

    any ideas why? this is quite urgent for me.

    Thanks for the help.

    Shai

    @shaisimchi

    Participant

    My issue was resolved.

    @modemlooper

    Moderator

    You should post how you fixed it in case others have same issues.

    @johnyred

    Member

    Hey @Travel-Junkie (or anyone who knows the answer to this) where should I paste your code, inside my functions.php (..plugins/buddypress/bp-themes/bp-default/functions.php)file?

    If my template file is named bp-gamers.php (in my theme in the profiles folder), what should I rename from your code?
    I really just want a blank profile page so that I may hardcode a few fields.

    Thanks

    ps: That functionality you described on your site sounds really cool.. do you have a link?

    @iamsincere

    Participant

    i want to add on to this one as well, how can you get the page to show regardless of which component your currently viewing?

    like

    `www.website.com/mypage/` or `www.website.com/members/mypage` ?

    @username_

    Member

    Hey everyone, this is a very old thread but I thought I would discuss my findings when trying to create my own custom page in buddypress.

    I am using the latest version 1.5.1 and i noticed the code only works if I navigate to mywebsite.com/(user)/example_page instead of mywebsite.com/example_page
    (user) being the logged in usersname.

    Any ideas as to why this may be happening? I am using the code the OP (jjj) posted.

    @hnla

    Participant

    The code is really really old! BuddyPress has been moving on apace through major revisions since JJJ made this post two years ago – old code examples are very unlikely to to be relevent to latest BP releases due to so much core code changing.

    Your best bet is to read the codex and perhaps have a look at the BP skeleton component.

Viewing 17 replies - 26 through 42 (of 42 total)
  • The topic ‘Make your own custom BuddyPress page’ is closed to new replies.
Skip to toolbar