Opened 9 years ago
Closed 8 years ago
#6507 closed enhancement (no action required)
Allow Ajax sub nav tab loading
Reported by: | CodeMonkeyBanana | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Core | Keywords: | |
Cc: | mikeymike81@…, espellcaste@… |
Description
Hi,
With ajax subnav tab loading it needs to work for logged in and logged out users alike so I made function that will work for both and check if user has access to view tab.
function bp_legacy_theme_tab_template_loader() { global $bp; // Bail if not a POST action if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) exit( '1' ); // exit if full path not specified if (empty($_POST['component']) || empty($_POST['page']) || empty($_POST['tab'])) { if ( SCRIPT_DEBUG ) { exit( 'missing path component' ); } else { exit( '1' ); } } // create full path $component = sanitize_title( $_POST['component'] ); $page = sanitize_title( $_POST['page'] ); $tab = sanitize_title( $_POST['tab'] ); $path = $component.'/single/'.$page.'/'.$tab; if ($bp->bp_options_nav[$page][$tab]['user_has_access'] === true) { // they are allowed to view it so return template bp_get_template_part( $path ); exit( '0' ); } else { if(SCRIPT_DEBUG) { exit( 'insufficient access' ); }else { exit( '1' ); } } }
I haven't included javascript as I am working on theme with custom menu that works a bit different but just needs a small bit of code added to when it checks for no-ajax class to work although that would probably be confusing to read. I can post it if needed once I finish this theme.
Change History (8)
This ticket was mentioned in Slack in #buddypress by guerrilla. View the logs.
9 years ago
#5
@
9 years ago
- Milestone changed from Awaiting Review to Under Consideration
There was a bunch of discussion on this on Slack the other day. Did anyone record what the outcome was?
#8
@
8 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
For consideration as a core feature, this report has had no traction so I'm closing it. Future work, involving implementing a REST API, will make this kind of feature easier to build client-side.
Gone round in circles and simplest way I can see to make this work is to add an additional template file into every directory that is named as the initial view. It will work because for instance "View" is called "public". Public cant be loaded by ajax because it will load the menu twice and outer html so you need just the action template so you can get back to original tab. It's backwards compatible but if someone partially copies updated template to existing theme they may have missing reference or end up with two versions of same tab.
So for instance add this file "buddypress/members/single/profile/view.php". Contents of file:
Do that for all folders and then ajax tabs will work fine with no problems and be secure. I looked at using the existing template hierarchy but it means creating a new file for each action or making some modifications that may not be secure and you would still need to add in additional template anyway.
I think best way to integrate it into bp_options_nav is to leave all css and id the way they are but add a data attribute with the action slug and then this can be used as input to function below.
Updated original code: (I need to update it again so it loops over name possibilities. First it will try name, then slug. That should get around naming inconsistencies, will do in a bit)