[AP documentation] Adding tabs and pages to users profile

Solved5.76K viewsGeneral
1

Hi all!

I’m trying to use AP and AP profiles as a base for a social network going beyond the point of a “simple” Q&A community. In order to do so, I’m trying to customize AP user profile page to show more elements by using previous answers provided on this forum and trying to find my way in all the PHP files of the plugin (I’m no developer and this is my first serious attempt at getting a working customized code). I know some other users are trying to achieve similar results. So, with this new thread, I would like to:

  1. summarize what have been already said
  2. share what I have been able to achieve
  3. get some help in going a bit further
  4. add relevant information and pieces of code gathered to AP documentation

[Solved] Add/remove link from user menu

Easy to add links with this and remove some menu items with this. For a “Logout” link, it’s pretty useful and straightforward. But what if I want to display some content like the Following tab or the About tab?

[Solved…?] Add a tab with corresponding content in user menu

I’ve been trying among other things to display badges earned through the BadgeOS plugin. By reading this message, I have been able to understand (?) that I should: register a new “Badges” page, setup the output for the “Badges” page and, of course, create the corresponding badges.php. Is that correct?

Here is how I achieved it:

  1. Register page in /includes/class-user.php :
    ap_register_user_page( 'badges', __( 'Badges', 'anspress-question-answer' ), array( __CLASS__, 'badges_page' ) );

     

  2. Setup output for page in /includes/class-user.php :
    public static function badges_page() {
    include ap_get_theme_location( 'user/badges.php' );
    }

     

  3. Create corresponding page in /theme/default/user/ : badges.php

 

By doing like that and using the proper code in badges.php, I have been able to achieve adding a tab with corresponding content and everything seems to be fine. So for now, I would like to know:

  • is it the right way to do it?
  • since I don’t know my way around php, I directly edited AP files (in a staging environment of course) so that I could learn from and copy/paste relevant pieces of code. Is there a way to achieve the same thing (register page + setup output) directly from my theme’s functions.php?
  • As an alternative to editing functions.php, is it possible to create a folder called anspress inside active parent theme folder and copy the modified class-user.php file to override original one?

 

Ok, that’s it for now. Let’s go step by step. 😀

Thanks in advance!

Fred

selected answer
1

Hello Fred,

You are doing it right but but you should not edit core files. Instead add this filters to you theme’s function.php

https://gist.github.com/rahularyan/347bb9a2c9cc11a788d739cabf8d5376

You can also wrap above code inside a class but if you are not much familiar with PHP leave it as it is else it will confuse you.

commented on answer

Thanks a lot Rahul! This is truly useful. I’m gonna try this and play around with it. 😉

Hi Rahul! I tried it out and everything worked like a charm, thanks! I have 2 related questions.
Question 1 : by looking at some other piece of code you provided, I guess that the last 2 values “true” and “false” in the ap_register_user_page array are about “show in menu” and “public”, correct? Is there a list fo all possible array values for registering a page in AnsPress? Or maybe the example you just gave me list them all already? I think it would be nice to add that to the documentation. 😉

Last two parameters in ap_register_user_page are
$show_in_menu = true, $public = true

Like if you want to hide a page link from menu then pass false, for example “logout”.
And $public for if you want a use page to be accessible by public user like ” about page”.

Thank you very much for the follow up Rahul! Ok, it’s what I guessed then. 😉

Is there any other parameters for the ap_register_user_page (other than the ones we already used)?

You are viewing 1 out of 2 answers, click here to view all answers.