Additional tabs on account page

Home Forums User Registration Additional tabs on account page

This topic contains 7 replies, has 4 voices, and was last updated by  rumesh38 3 months, 2 weeks ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #3332

    Rodrigo Montiel
    Participant

    Hello,

    I’m unable to add additional tabs to the account page. I’ve followed the example in the docs trying to “echo” the content of the tab and also calling a template, which is what I would like to do, but I’m not being able to suceed.
    Could you help me with this?

    Also, what is the correct way of adding several tabs in my functions.php file?

    Here’s an screenshot of my theme’s functions file and the template for new-item.php

    https://ibb.co/h3J8fz
    https://ibb.co/ehvofz

    Thank you in advance

    #3338

    sanjeev3
    Member

    Hello Montiel,

    Looks like you have missed the hook for user_registration_new_item_endpoint_content() callback function.

    add_action( 'user_registration_account_new-item_endpoint', 'user_registration_new_item_endpoint_content' );
    function user_registration_new_item_endpoint_content() {
        echo 'Your new content';    // or the template ur_get_template( 'myaccount/new-item.php');
    }

    To add several endpoints, you may simply assign array of new items and merge into items provided by user_registration_account_menu_itemsfilter hook.

    Hope this helps!

    Regards,
    WPEverest Support

    #3352

    Rodrigo Montiel
    Participant

    Hello sanjeev3, thank you for the answer.

    The problems seems to be with the endpoints configuration (WP admin panel). I was leaving one of the endpoints (“log-out”) blank so it didn’t show up on my account. I restored the endpoint, so now all of them are active, and the new additional tab is working.

    Could you please provide a code example for adding several tabs, each with their own template? I’m having a little trouble with this.
    And also how can I make the url to the new endpoint to be a translatable string?

    Thank you.

    #3383

    sanjeev3
    Member

    Glad to know your issue is solved.

    As said already, to add several endpoints, you may simply assign array of new items and merge into items.

    add_filter( 'user_registration_account_menu_items', 'ur_custom_menu_items', 10, 1 );
    function ur_custom_menu_items( $items ) {
        $new_items = array(
            'new-item-1' => __( 'New Item 1', 'user-registration' ),
            'new-item-2' => __( 'New Item 2', 'user-registration' ),
            'new-item-3' => __( 'New Item 3', 'user-registration' ),
             ...  
        );
    
        return array_merge( $items, $new_items );
    }

    Hope this helps! We can’t provide you full code.

    #3445

    Rodrigo Montiel
    Participant

    Hello,
    Thank you for the answer.

    I was able to add additional items to the array before but I couldn’t make the new items point correctly to their respective template/content. That is why I was asking for an example of that.

    However, after trying different options, I realized that the changes are not seen (I was getting a 404 error all the time for new items) until I go to the User Registration settings page in WordPress and fill in or delete one or more of the default endpoints and then hit Save changes.
    If I don’t do this I get “Page not found” for the new endpoints.

    I hope you can add an example of adding several endpoint to the general documentation of the plugin. I think that would be very helpful.

    #3457

    sanjeev3
    Member

    Hello,

    Thank you for the suggestion. For rendering the contents for newly created items, it is same way as single item addition. For every new_item_x you need to add content or template file with user_registration_account_new-item-x_endpoint hook.

    function user_registration_new_item_x_endpoint_content() {
        ur_get_template( 'myaccount/new-item-x.php');
    }
    add_action( 'user_registration_account_new-item-x_endpoint', 'user_registration_new_item_x_endpoint_content' )

    And no, you don’t need to fill in or delete one or more of the default endpoints and then hit Save changes after every endpoint addition. Any time you have 404s, It’s a safe bet to re-save your permalinks. It can’t hurt and solves a lot of problems. Navigate to Dashboard->Settings->Permalinks do nothing and Save Changes.

    Hope this helps!

    #20216

    jfuentes3002
    Participant

    I can not make an example work to add more than one endpoint. In the example above it is shown how to make it appear in the menu, but the example is not finished for the creation of the pages, according to how I interpret this example I get errors of type 404.

    What will I be doing wrong?
    What will be missing?

    Oops!
    It looks like nothing was found at this location. Maybe try one of the links below or a search?

    Error 404

    Example:

    
    add_filter( 'user_registration_account_menu_items', 'ur_custom_menu_items', 10, 1 );
    function ur_custom_menu_items( $items ) {
    	$new_items = array(
    		'new-item-1'	=> __( 'Test1', 'user-registration' ),
    		'new-item-2'	=> __( 'Test2', 'user-registration' ),
    		'new-item-3'	=> __( 'Test3', 'user-registration' ),
    	);
    
    	return array_merge( $items, $new_items );
    }
    
    add_action( 'init', 'user_registration_add_new_my_account_endpoint' );
    function user_registration_add_new_my_account_endpoint() {
        add_rewrite_endpoint( 'new-item-1', EP_PAGES );
        add_rewrite_endpoint( 'new-item-2', EP_PAGES );
        add_rewrite_endpoint( 'new-item-3', EP_PAGES );
    }
    
    add_action( 'user_registration_account_new-item-1_endpoint', 'user_registration_new_item_1_endpoint_content' );
    function user_registration_new_item_1_endpoint_content() {
        //echo 'Your new content';
        ur_get_template( 'myaccount/new-item-1.php');
    }
    
    add_action( 'user_registration_account_new-item-2_endpoint', 'user_registration_new_item_2_endpoint_content' );
    function user_registration_new_item_2_endpoint_content() {
        //echo 'Your new content';
        ur_get_template( 'myaccount/new-item-2.php');
    }
    
    add_action( 'user_registration_account_new-item-3_endpoint', 'user_registration_new_item_3_endpoint_content' );
    function user_registration_new_item_3_endpoint_content() {
        //echo 'Your new content';
        ur_get_template( 'myaccount/new-item-3.php');
    }
    

    please help!

    From already thank you very much.

    PS: I hope my English has been understood.

    #20252

    rumesh38
    Moderator

    Hi there,

    It’s possible that your permalink needs to be updated. Please go to Dashboard > Settings > Permalinks and just Save Changes without changing anything.

    Hope this helps!

    Thanks & Regards,
    WPEverest Support Team.

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

You must be logged in to reply to this topic.