[wp-hackers] Dynamic User Pages - How Does BuddyPress do it?

Nikola Nikolov nikolov.tmw at gmail.com
Sat Oct 12 09:16:39 UTC 2013


You can find the sample code that I made here -
https://gist.github.com/nikolov-tmw/8d803ea9b4adfbd7e221

What this does is that it checks for the presence of the "member" query
variable. If it's set and is referencing a valid user, then we overload the
query and tell WordPress to load a specific page(the one taken from the
get_my_page_id() function) and we also hook to a couple of filters in order
to display the correct information.
If on the other hand it's not a valid username(at the moment - you can
change this to user ID for instance) then a 404 page is displayed instead.

There are a couple of things that you can do to improve these functions(and
you probably should):
 - Make the page ID dynamic. Add an option in your plugin's settings where
the user can select which page should be the profile page(right now it's
hard-coded to 2 which is the default "Sample Page" ID).
 - Allow the user to override your plugin's template. You can take a look
at how WooCommerce does it(
http://docs.woothemes.com/wc-apidocs/source-function-woocommerce_get_template.html#596-619
) and
borrow and modify the code to fit your needs. This will basically allow the
user to create a file(for instance) "members-page.php" in their theme
directory and change the template to their liking, instead of having to
edit your plugin's file which would get over-written during an update.

If there's anything else to help with - just post it here.

Nikola


On Fri, Oct 11, 2013 at 11:15 PM, BenderisGreat
<greglancaster71 at gmail.com>wrote:

> Thanks again for your help Nikola - I ended up just pasting a whole
> template
> inside the function before and after the include statement.  It works for
> now, but wont work with any other theme but mine.   I was considering
> something like echo apply_filters( 'my_filter_name, $content );
>
> Then apply it using add_filter( 'my_filter_name',
> 'your_function_for_adjusting_the_content' );  Would something like that
> work?
>
>
>
> --
> View this message in context:
> http://wordpress-hackers.1065353.n5.nabble.com/Dynamic-User-Pages-How-Does-BuddyPress-do-it-tp42492p42522.html
> Sent from the Wordpress Hackers mailing list archive at Nabble.com.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list