Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Last active December 17, 2018 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/60fdc20490effadf80cd45ca0b841253 to your computer and use it in GitHub Desktop.
Save joshfeck/60fdc20490effadf80cd45ca0b841253 to your computer and use it in GitHub Desktop.
Use the Restrict Content plugin to restrict Event Espresso event content. You can add this code to a site specific plugin.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
function my_ee_rcAddMetaBoxes() {
if(function_exists('rc_get_metabox') && post_type_exists('espresso_events')){
$metabox = rc_get_metabox();
$post_type = get_post_type_object('espresso_events');
add_meta_box(
$metabox['id'],
$metabox['title'],
'rcShowMetaBox',
$post_type->name,
$metabox['context'],
$metabox['priority']
);
}
}
add_action('admin_menu', 'my_ee_rcAddMetaBoxes', 11);
function my_ee_rcCheckUser($content) {
if (
function_exists('rcCheckUser') &&
'espresso_events' == get_post_type()
) {
global $post;
if (
get_post_meta($post->ID, 'rcUserLevel', true) &&
has_filter('the_content', 'rcMetaDisplayNone')
) {
remove_filter(
'the_content',
array('EED_Event_Single', 'event_details'),
EED_Event_Single::EVENT_DETAILS_PRIORITY
);
remove_filter(
'the_content',
array('EED_Events_Archive', 'event_details'),
EED_Events_Archive::EVENT_DETAILS_PRIORITY
);
add_filter(
'the_content',
function(){
global $post;
$html = $post->post_content;
$html .= '<br>You need to <a href="' . wp_login_url( get_permalink() ) . '">log in</a> to register for this event. ';
$html .= 'You can <a href="' . wp_registration_url() . '">sign up for an account here</a>.';
echo $html;
},
999
);
}
}
return($content);
}
add_filter('the_content', 'my_ee_rcCheckUser', 11);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment