I'm using the latest beta Amember WordPress plugin. I have my primary content in WordPress Custom Post Type (in several custom fields). I want to protect some of these fields only. It looks like the protection is happening in amember.php: Code: add_filter("the_posts", "amember_filter_posts"); Has anyone successfully modified the plugin to allow protection of certain custom fields?
Not sure I understood how this should work? Do you want to display these fields only for active users? If so this is possible to setup such protection in theme template for that custom post. Can you provide more info about how such protection should work?
Hi alexander; yes, that's exactly what I want to to. I have a custom post type Lesson. Lesson has several custom fields: Module Objective Steps Video ID In my theme (specifically, in single-lesson.php) I have code like this (simplified for this example): Code: <?php /** * Template Name: Single Lesson * * A custom page template for lessons */ $local_lesson_module = get_post_meta($post->ID, 'lesson_module', TRUE); $local_lesson_objective = get_post_meta($post->ID, 'lesson_objective', TRUE); $local_lesson_steps = get_post_meta($post->ID, 'lesson_steps', TRUE); $local_lesson_video_id = get_post_meta($post->ID, 'lesson_video_id', TRUE); get_header(); ?> <div id="container"> <h1 class="entry-title"><?php the_title(); ?></h1> <?php if ($local_lesson_objective != '') echo "<div id='local_lesson_objective'><h2>Objective</h2> $local_lesson_objective </div>"; if ($local_lesson_objective != '') echo "<div id='local_lesson_steps'><h2>Steps</h2> $local_lesson_steps </div>"; if ($local_lesson_module != '') echo "<div id='local_lesson_module'><img src='/module-icons/<?php echo $local_lesson_module; ?>.jpg' alt='<?php echo $local_lesson_module; ?>' /></div>"; if ($local_lesson_video_id != '') { // If we have a video, show it full width ?> <div class="no_overlay" id="player2" style="text-align:center;"> <iframe title="YouTube video" width="960" height="540" src="http://www.youtube.com/embed/<?php echo $local_lesson_video_id;?>?hd=1" frameborder="0" allowfullscreen></iframe> </div><?php } get_footer(); ?> Let's say I want the lesson objective to be hidden from non-active users. Can I change that block of code to something similar to the following? Code: if ($local_lesson_objective != '') echo "[amember_protect user_action='error' user_error='amember_error_default_user' visitor_action='error' visitor_error='amember_error_default_user']<div id='local_lesson_objective'><h2>Objective</h2> $local_lesson_objective </div>[/amember_protect]"; I know this exact code won't work as it doesn't parse the shortcodes. Can you give me some sample code (or links to sample code) for this type of usage?
This is possible another way. aMember store levels info in wordpress user's meta, so you can do this: PHP: if ($local_lesson_objective != '' && in_array('level_name', $current_user->_amember_levels)){ echo "something"} So code will be displayed only if user have level_name
Super, thanks alexander. I'm going to use that to wrap several blocks as follows: Code: if (in_array('active_user', $current_user->_amember_levels)) { // This is a paid up member; show protected content here } else { // This is NOT a paid up member; show guest content here }
I'm trying to do the same thing I have a custom post type with a lot of custom fields. I'm replacing the loop like this function lender_loop(){ if (in_array('lender_directory', $current_user->_amember_levels)){ //my custom loop } else { echo "is this working?"; } } And I am logged in, I have the permissions on my user and I'm seeing "is this working?" instead of my loop. What am I going wrong please?
Try to define global $current_user; at the top of your function. Also print_r($current_user) to check amember levels.