Forum Replies Created
-
Ok I’ve continued to work on this but I’ve run into abit of a snag. It seems that the standard status code from WP for a screen function is 404 unless a template is loaded. This is fine in most cases but in some cases you might not want to return anything and when it comes to AJAX you might want to return a JSON response. Setting the header yourself and putting die() at the end works but that’s pretty ugly and I’d like to “follow the rules” so to speak.
Does anyone know the best practice or convention for this? Very thankful for any ideas/help. I’ve updated the plugin in the repository to the latest version.
Ok guys I’ve put it up on SVN on Beanstalk. There’s the router here: http://smurkas.svn.beanstalkapp.com/minpt/trunk/buddypress-screen-router and there’s a minimal root component to get you going here: http://smurkas.svn.beanstalkapp.com/minpt/trunk/buddypress-minimal-root-component
The router assumes that the root component is registered via the action bp_setup_globals since it uses the global data to figure out what to route to. The root component works out of the box even though it doesn’t actually do anything, it just sets up all the globals and slug. In this case I’ve put in a screen function for the index action. If you don’t actually need to do any business logic I would recommend removing it and adding a folder in your theme corresponding to the component id (in this case bp_min_root) and putting an index.php file in there instead.
Let me know if it works for you and what you think. I’d love to discuss what conventions to use for this kind of thing.
Ok so I think I figured this out. I used the Skeleton component to do this and you need to change a couple of things in order for it to work. First of all, the component registers itself too late so bp_core_add_root_component() won’t work.
Change line 45 of loader.php to
add_action( ‘bp_include’, ‘bp_example_init’ );This will register the component before Buddypress sets up the URI:s and thus giving you a chance of adding your own root component.
Then for registering my own root component I did this:
function bp_example_setup_root_component() {
/* Register ‘example’ as a root component */
bp_core_add_root_component( BP_EXAMPLE_SLUG );
}
add_action( ‘bp_setup_root_components’, ‘bp_example_setup_root_component’ );Lastly you need to setup your own screen functions. Following BP:s way of doing things I created
function bp_example_screen_example() {
global $bp, $wpdb;
if ( $bp->current_component != BP_EXAMPLE_SLUG )
return false;
die(“Example screen!”);
}
add_action( ‘wp’, ‘bp_example_screen_example’, 3 );Now that last function will catch everything that arrives on the example slug so you probably want to make it more picky so to speak.