embed code
-
Hello,
In some case AAM do not have any way to manage access to front end. I am using The Events calendar and I want to restrict by example acces to venue and maps only for certains categories of users.
A simple way Is to use :
if ( is_user_logged_in() ) {}else{}
but it’s not manage by AAM of course.
Is there any way to embed some AAM code into my templates to let AAM manege access to those specific parts ?
I can provide parts of the code I want to protect if it make the question more easy to answer.
Thanks !
-
Hi onirgoc,
Actually AAM has very extensive and flexible API. It was developed by developers for developers. In your case I’ll show you the easiest way to accomplish your task so let’s base your solution on WordPress capabilities (you can either utilize existing WordPress capabilities or create your own; both things can be easily done with AAM UI under the Capabilities tab).
So let’s assume that you have few users that belong to your custom role Event Manager. Event Manager role has custom capability Manage Events which means that any user that belongs to this role also has this capability.
Advanced Access Manager during the initialization creates a singleton object AAM that is visible by any other plugin or theme through your WordPress.
So in your code you can do something like this:
if (AAM::getUser()->hasCapability('Manage Events')) { //show somethings on your frontend page } else { //well, show nothing or something different }Hopefully this is understandable and helpful.
Regards,
VasylThanks!
it’s not Events Manager but The Events Calendar from Tribe…
but if I understand you I already find “Read Private Tribe Events”, “Read Private Tribe Venues”, “Read Private Tribe Organizers” in AAM UI under capabilities.
if (AAM::getUser()->hasCapability(Read Private Tribe Organizers’)) {
//show somethings on your frontend page
} else {
//well, show nothing or something different
}and the same for “venues”
so am I in the right direction ?
well after I have to find what to put under “show sometings”For now this is what I was using; As you can see it’s really basic and do not allow to check that user is allowed to see “venue” and “map”
<?php
/**
* Single Event Meta Template
*
* Override this template in your own theme by creating a file at:
* [your-theme]/tribe-events/modules/meta.php
*
* @package TribeEventsCalendar
*/do_action( ‘tribe_events_single_meta_before’ );
// Check for skeleton mode (no outer wrappers per section)
$not_skeleton = ! apply_filters( ‘tribe_events_single_event_the_meta_skeleton’, false, get_the_ID() );// Do we want to group venue meta separately?
$set_venue_apart = apply_filters( ‘tribe_events_single_event_the_meta_group_venue’, false, get_the_ID() );
?><?php if ( $not_skeleton ) : ?>
<div class=”tribe-events-single-section tribe-events-event-meta primary tribe-clearfix”>
<?php endif; ?><?php
// Only for logged in user
if ( is_user_logged_in() ) {
do_action( ‘tribe_events_single_event_meta_primary_section_start’ );// Always include the main event details in this first section
tribe_get_template_part( ‘modules/meta/details’ );// If we have no map to embed and no need to keep the venue separate…
if ( ! $set_venue_apart && ! tribe_embed_google_map() ) {
tribe_get_template_part( ‘modules/meta/venue’ );
} elseif ( ! $set_venue_apart && ! tribe_has_organizer() && tribe_embed_google_map() ) {
// If we have no organizer, no need to separate the venue but we have a map to embed…
tribe_get_template_part( ‘modules/meta/venue’ );
echo ‘<div class=”tribe-events-meta-group tribe-events-meta-group-gmap”>’;
tribe_get_template_part( ‘modules/meta/map’ );
echo ‘</div>’;
} else {
// If the venue meta has not already been displayed then it will be printed separately by default
$set_venue_apart = true;
}// Include organizer meta if appropriate
if ( tribe_has_organizer() ) {
tribe_get_template_part( ‘modules/meta/organizer’ );
}do_action( ‘tribe_events_single_event_meta_primary_section_end’ );
?><?php if ( $not_skeleton ) : ?>
</div>
<?php endif; ?><?php if ( $set_venue_apart ) : ?>
<?php if ( $not_skeleton ) : ?>
<div class=”tribe-events-single-section tribe-events-event-meta secondary tribe-clearfix”>
<?php endif; ?>
<?php
do_action( ‘tribe_events_single_event_meta_secondary_section_start’ );tribe_get_template_part( ‘modules/meta/venue’ );
tribe_get_template_part( ‘modules/meta/map’ );do_action( ‘tribe_events_single_event_meta_secondary_section_end’ );
?>
<?php
if ( $not_skeleton ) : ?>
</div>
<?php endif; ?>
<?php
endif;
do_action( ‘tribe_events_single_meta_after’ );
} else {}
Thanks for your help. Will let you know as soon as I have done tests.
But there is no capabilities for visitor ? How can I forbide access then ?
Thanks.
mmm…stupid question…visitor has no capabilities so no access… 😉
Hi onirgoc,
I was using Event Manager role as an example. It does not refer to any plugin. But you are moving in right direction.
AAM is intelligent enough to recognize if user is logged in or not. That is why the code that I mentioned above will also work for Visitors.
You are absolutely right. Visitors do not have any capabilities or roles, that is why the condition with hasCapability will always return false for Visitors.
Please also notice. List of capabilities in the current AAM version shows only human readable capability name. We already working on the next AAM release that shows also the internal capability id right next to the capability title. You can get the development version of our next release from the GitHub.
So in your case the capability “Read Private Tribe Organizers” internally may be stored as read_private_tribe_organizers. And hasCapability works only with internal capability id.
Regards,
Vasylneed help !!!
I tryed this:
<?php
/**
* Single Event Meta Template
*
* Override this template in your own theme by creating a file at:
* [your-theme]/tribe-events/modules/meta.php
*
* @package TribeEventsCalendar
*/do_action( ‘tribe_events_single_meta_before’ );
// Check for skeleton mode (no outer wrappers per section)
$not_skeleton = ! apply_filters( ‘tribe_events_single_event_the_meta_skeleton’, false, get_the_ID() );// Do we want to group venue meta separately?
$set_venue_apart = apply_filters( ‘tribe_events_single_event_the_meta_group_venue’, false, get_the_ID() );
?><?php if ( $not_skeleton ) : ?>
<div class=”tribe-events-single-section tribe-events-event-meta primary tribe-clearfix”>
<?php endif; ?><?php
// Only for allowed user
if (AAM::getUser()->hasCapability(‘Read Private Tribe Organizers’)) {do_action( ‘tribe_events_single_event_meta_primary_section_start’ );
// Always include the main event details in this first section
tribe_get_template_part( ‘modules/meta/details’ );// If we have no map to embed and no need to keep the venue separate…
if ( ! $set_venue_apart && ! tribe_embed_google_map() ) {
tribe_get_template_part( ‘modules/meta/venue’ );
} elseif ( ! $set_venue_apart && ! tribe_has_organizer() && tribe_embed_google_map() ) {
// If we have no organizer, no need to separate the venue but we have a map to embed…
tribe_get_template_part( ‘modules/meta/venue’ );
echo ‘<div class=”tribe-events-meta-group tribe-events-meta-group-gmap”>’;
tribe_get_template_part( ‘modules/meta/map’ );
echo ‘</div>’;
} else {
// If the venue meta has not already been displayed then it will be printed separately by default
$set_venue_apart = true;
}// Include organizer meta if appropriate
if ( tribe_has_organizer() ) {
tribe_get_template_part( ‘modules/meta/organizer’ );
}do_action( ‘tribe_events_single_event_meta_primary_section_end’ );
?>
<?php if ( $not_skeleton ) : ?>
</div>
<?php endif; ?><?php if ( $set_venue_apart ) : ?>
<?php if ( $not_skeleton ) : ?>
<div class=”tribe-events-single-section tribe-events-event-meta secondary tribe-clearfix”>
<?php endif; ?>
<?php
do_action( ‘tribe_events_single_event_meta_secondary_section_start’ );tribe_get_template_part( ‘modules/meta/venue’ );
tribe_get_template_part( ‘modules/meta/map’ );do_action( ‘tribe_events_single_event_meta_secondary_section_end’ );
?>
<?php
if ( $not_skeleton ) : ?>
</div>
<?php endif; ?>
<?php
endif;
do_action( ‘tribe_events_single_meta_after’ );
} else {
//nothing
}Under admin user I get the page without details, venue, organizer and under guest user a white page…where am I wrong ?
Thanks if you can help !
OKKKK ! I got it…now only the visitor page is blank…probably I put the conditional to high…
Thanks this is really great help !
I will an other request in an other post about something you can add in futur to your great plugin. 🙂
Find this under guest user :
Fatal error: Call to undefined method stdClass::has_cap() in (hide exact adress for security ) \…\…\…\….\wp-content\plugins\advanced-access-manager\Application\Core\Subject.php on line 215
any idea ?
Nice catch onirgoc!
Fix can be found in our development version on the github
Keep me updated!
Regards,
VasylGREAT !!!
WORKING !!!…then just buy the pro version ! Thanks for great support and great plugin !
The topic ‘embed code’ is closed to new replies.