Theme Functions - YourMembers/yourmembers GitHub Wiki
These functions can be used right inside your theme to protect content not inside a widget or the loop. Keep in mind these are php functions and so need to be wrapped inside php tags.
This tag protects content and controls access.
Basic use:
if(ym_user_has_access()){
thing to protect
}
Outside the loop, however, it won’t know what post you’re on, so you’ll need to call the post_ID first, like this:
global $wp_query;
if(ym_user_has_access($wp_query->post->ID)){
thing to protect
}
Note: You’ll only need to call global $wp_query once within the theme. Unless its help in a function, you can specify any post_ID to go in there. So, for example, if we want people to have access to the protected area, only if they have access to post 12
if(ym_user_has_access(12)){
thing to protect
}
You can also specify a user_id Just be aware that doing so will override the current user, so use it wisely.
if(ym_user_has_access(false,1)){
thing to protect
}
Would, for example, use the permissions of user 1 when looking to see if user should access
To determine a user’s account type, use:
$account_type = ym_get_user_account_type();
So, for example, if we wanted to protect content so that only basic account members could see it, we would use:
$account_type = ym_get_user_account_type();
if($account_type == 'basic'){
content here
}
Like the user_has_access code, you can specify an ID, if you want to check the access level of a third party.
Doing something special and need to know if a post is protected? Use:
if(ym_is_post_protected()){
post is protected do something
}
Like the ym user_has_access code, you will need to give either a post_ID, or if used outside the loop, $wp_query->post->ID
This is handy for calling javascript files inside the head on load for protected posts, for example.
To call a user’s custom fields you can use:
ym_custom_fields = ym_get_custom_field_array($user->ID);
This returns an array of all their fields. To check against say name, you can then:
ym_custom_fields = ym_get_custom_field_array($user->ID);
if($ym_custom_fields['fname'] == 'tim'){
hello tim
}
Of course, you can always just use:
ym_custom_fields = ym_get_custom_field_array($user->ID); echo 'hello '.$ym_custom_fields['fname'];
-
Place Everything Into a Function File
Try to keep Your Members logic in the function file, away from the templates themselves. This makes them easier to find, but it also means you’re keeping them inside the function when calling global variables.
-
Check If Your Members Is Installed
A best practice method for checking if Your Members is installed is:
function is_ym_installed(){ global $ym_sys; if(!$ym_sys){ return false; } return true;