Hi Chad,
I tried to contact you via the rocketgeek contact form, but I got a message that said my message failed to send and that I should contact the administrator via another method. So I am back here.
Here is the message that I am trying to send via rocketgeek.
Hi Chad,
We had been communicating at the www.remarpro.com forum about this issue.
I have a bit more information concerning the issue. I am using a child theme and in the functions.php file for the child theme, I have this additional code.
add_action( ‘template_redirect’, ‘my_redirect_to_login’ );
function my_redirect_to_login() {
if ( ! is_user_logged_in() && wpmem_current_url() == site_url( ‘/activity/’ ) ) {
wpmem_redirect_to_login();
} elseif
( ! is_user_logged_in() && wpmem_current_url() == site_url( ‘/members/’ ) ) {
wpmem_redirect_to_login();
}
return;
}
/**
* A simple function to create a settings array
* for access levels and information.
*/
function my_post_access_levels() {
return array(
‘levels’ => array(
/**
* Set array values as:
* metavalue => label,
*/
‘renter’ => ‘Renter/Tenant’,
‘owner’ => ‘Owner’,
‘board’ => ‘Board’,
),
‘default’ => ‘renter’,
‘user_field’ => ‘user_level’,
‘post_field’ => ‘post_access’,
‘error_msg’ => ‘Your account does not have access to this page.’
);
}
// No need to change anything after this line.
/**
* Set the user to the default at registration.
*/
add_action( ‘wpmem_post_register_data’, ‘set_default_level’ );
function set_default_level( $fields ){
extract( my_post_access_levels() );
update_user_meta( $fields[‘ID’], $user_field, $default );
}
/**
Allows new user registration to go to an email in addition to the general settings admin email.
*/
add_filter( ‘wpmem_notify_addr’, ‘my_admin_email’ );
function my_admin_email( $email ) {
// take the default and append a second address to it example:
$email = $email . ‘, johnf@moarefims.com’;
// return the result
return $email;
}
/**
* Sets up access restriction by User ID and access level
*/
add_filter( ‘wpmem_securify’, ‘check_user_access’ );
function check_user_access( $content ) {
// Is the content to be blocked and is the user logged in?
if ( is_user_logged_in() && wpmem_block() == true ) {
// Get settings.
extract( my_post_access_levels() );
// We need the user’s ID and the $post object.
global $user_ID, $post;
// Get the user’s access level.
$user_level = get_user_meta( $user_ID, $user_field, true );
// Get the post access level.
$post_access = get_post_meta( $post->ID, $post_field, true );
// Evaluate level hierarchy.
$i = array_search( $post_access, array_keys( $levels ) );
$x = array_search( $user_level, array_keys( $levels ) );
// If the user level is less than post level, return
// error message. otherwise return $content.
return ( $x < $i ) ? $error_msg : $content;
}
// Return unfiltered content for all other cases.
return $content;
}
/** Admin panel elements */
/**
* Add dropdown to post and page meta box for marking level.
*/
add_action( ‘wpmem_admin_after_block_meta’, ‘my_add_post_level’, 10, 2 );
function my_add_post_level( $post, $block ) {
// Get the settings.
extract( my_post_access_levels() );
// Get the current access setting, if any.
$post_access = get_post_meta( $post->ID, $post_field, true );
// Create dropdown selector of users for access.
echo ‘<label>Limit access to: </label>
<select name=”post_access”>
<option value=””>Select User Level</option>’;
foreach ( $levels as $meta => $label ) {
$selected = ( $meta == $post_access ) ? ‘selected’ : ”;
echo “<option value=\”$meta\” $selected>$label</option>;”;
}
echo ‘</select>’;
}
/**
* Save custom post meta for user ID access.
*/
add_action(‘wpmem_admin_block_meta_save’,’my_add_post_level_save’,10,3);
function my_add_post_level_save( $post, $block, $unblock ) {
extract( my_post_access_levels() );
if ( isset( $_POST[$post_field] ) ) {
// If a user ID is passed to limit access, save it.
update_post_meta( $post->ID, $post_field, $_POST[$post_field] );
} else {
// If no user ID is passed to limit access, delete any meta.
delete_post_meta( $post->ID, $post_field );
}
}
/*———– remove menu items based on user level ——————*/
add_filter( ‘wp_get_nav_menu_items’, ‘my_remove_menu_item_by_level’, null, 3 );
function my_remove_menu_item_by_level( $items, $menu, $args ) {
// Get post level settings.
extract( my_post_access_levels() );
// Iterate through menu items and evaluate.
foreach ( $items as $key => $item ) {
// Get the post access level.
$post_access = get_post_meta( $item->object_id, $post_field, true );
// If the user is logged in, check user level.
if ( is_user_logged_in() ) {
// Get the user’s access level.
$user_level = get_user_meta( get_current_user_id(), $user_field, true );
// Evaluate level hierarchy.
$i = array_search( $post_access, array_keys( $levels ) );
$x = array_search( $user_level, array_keys( $levels ) );
// If user level is too low, remove the item.
if ( $x < $i ) {
unset( $items[ $key ] );
}
} else {
// User is not logged in, if the post has a level, remove it.
if ( $post_access ) {
unset( $items[ $key ] );
}
}
}
return $items;
}
add_action( ‘pre_get_posts’, ‘my_query_exclusions’ );
function my_query_exclusions( $query ) {
if( $query->is_search && ! is_user_logged_in() ) {
$meta_query = array(
array(
‘key’=>’_wpmem_block’,
‘value’=>’0’,
‘compare’=>’=’,
),
);
$query->set(‘meta_query’,$meta_query);
}
return $query;
}
?>
I am having to disable this because now my website will not even load. It just presents a blank white page. So, in order to get the site functional again (without the membership stuff), I need to remove this section of code from the child theme.
Please advise how I should proceed. This site has been functioning without any problems for well over a year until the latest WordPress update.
Thanks in advance for your help. By the way, I am going to be needing to create another site in the next few weeks that will also need the Membership plugins so I am really worried about getting this fixed and then properly set up on the new site as well.
Debbie