Skip to:
Content
Pages
Categories
Search
Top
Bottom

adding new user sub page with custom profile design


  • nushara
    Participant

    @nushara

    Hey there,

    I am in need to create a new subpage of a users profile but having its own template being completely different to the normal one. I have written a plugin for this which kind of works but it looks like I have some mistake in it. Hopefully you can tell me what the issue is.

    I need the URL to be: xxx/username/links which I archived with:

    add_action( 'bp_setup_nav', 'add_linksite_nav', 100 );
    function add_linksite_nav() {
    	global $bp;
    	bp_core_new_nav_item( array(
    		'name' => 'Links',
    		'slug' => 'links',
    		'screen_function' => 'linksite_display_function',
    		'position' => 99
    		)
    	);
    }

    after that I have added the custom template like so:

    function linksite_display_function() {
    	load_template(plugin_dir_path(__FILE__) . 'template.php');
    }

    While the template is having this code:

    <?php
    $user_id = bp_displayed_user_id();
    $is_my_profile = bp_is_my_profile();
    $username = bp_core_get_username( bp_displayed_user_id() );
    $logged = is_user_logged_in();
    get_header();
    ?>
    <article id="content" class="index-page-frame position-relative">
    	<div class="content-limiter pt-3">
    		<div id="post-<?php the_ID(); ?>" class="position-relative" style="z-index: 10">
    			<div class="container text-center mt-8">
    				<div class="row">
    					<div class="col"><?php echo($username); ?></div>
    				</div>
    			</div>
    		</div>
    	</div>
    </article>

    Issue is that my page is showing the username but also shows a 404 page not found error. Not only the content, also for the tab name and so on. So the page really seems to be a 404 but with my added content.

    Do you have any idea how I can archive this custom template having this page slug but working fine?

    Thank you,
    Mike

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

  • shanebp
    Moderator

    @shanebp

    Here is an example of adding a profile tab.
    Instead of a template, put your markup in a function.


    nushara
    Participant

    @nushara

    Thank you @shanebp but that’s not what I need. I got this working already, but I need a completely new page design at all.

    This will only let me add content to a new tab but keep the base design of Buddypress user profiles. I need a new page with the slug but a completely blank page design.

    But thanks for your suggestion.


    nushara
    Participant

    @nushara

    The page should kind of be like the settings page. Where it has its own design and settings etc but still be related to the profile and user.

    Hope this helps to understand what I try to archive. I know it’s a pretty hard / uncommon request.


    shanebp
    Moderator

    @shanebp

    You cannot change the parent template within BP for a single profile tab.
    Put a redirect or $_POST submit in the screen function and send it to a WP page that uses the template you want.
    But it will no longer be a BP profile page and you will not be able to use BP functions like bp_displayed_user_id() and will need to pass that data some other way.


    nushara
    Participant

    @nushara

    And would it be possible to use also a custom parent template? So I create a separate profile template which is only getting loaded visiting the new page?

    Like if I had created a completely new profile template which only gets loaded under certain circumstances?

    I hope you understand what I mean. If not, please let me know.


    shanebp
    Moderator

    @shanebp

    No, it would not be possible.


    nushara
    Participant

    @nushara

    Ok, another quick question then. Am I able to create the slug of a profile subpage like:

    	bp_core_new_nav_item( array(
    		'name' => 'Links',
    		'slug' => 'links',
    		'screen_function' => 'linksite_display_function',
    		'position' => 99
    		)
    	);

    but make it not appear in the nav? So the links and everything is working but it is not getting displayed in the navbar?


    nushara
    Participant

    @nushara

    Since I am not able to edit my post, I got this solved doing:

    
    global $bp;	
    bp_core_new_nav_item( array(
    		'name' 				=> 'Links',
    		'slug' 				=> 'links',
    		'parent_url'   		=> $bp->displayed_user->domain,
    		'parent_slug'  		=> $bp->profile->slug,
    		'screen_function' 	=> 'linksite_display_function',
    		'position' 			=> 99,
    		)
    	);
    	unset( $bp->bp_nav['links'] );
Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar