Tips and Tricks HQ Support Portal › Forums › WP eMember › WP eMember Tweaks › WP eMember and WPML integration proposal.
Tagged: wp membership, wpml
- This topic has 1 reply, 2 voices, and was last updated 10 years, 11 months ago by admin.
-
AuthorPosts
-
December 3, 2013 at 10:54 am #10159ict@lago.itMember
Hello, our environment is:
– WordPress 3.5.1
– WPML 2.6.3
– WP eMembers 8.7.6
We found a problem with the post translation: each language different then the the default one (setted on the WPML dashboard), cause a “Your membership level does not allow you to view the rest of the content.”
This problem is due to a missing integration between the plugins.
In the dashboard, probably due to the WPML, are showed only the posts in default language but, when in function auth_check_post (emember_access_checkers.php file) you check the grants, you use the current id of the post (that is different for each translation).
I resolve this problem modify the function like this
function auth_check_post($content){
global $post;
$id = $post->ID;
if(empty($id)) return $content;
//lago.it start
$id = apply_filters( 'lago_get_wpml_parent_id', $id );
//lago.it end
return check_post_content($id, $content);
}and adding, on the function.php of the theme,
add_filter( 'lago_get_wpml_parent_id', 'lago_get_wpml_parent_id' );
function lago_get_wpml_parent_id( $id ) {
if ( function_exists( 'icl_object_id' ) == true ) {
return icl_object_id( $id, 'post', false, 'it' );
}
return $id;
}The WPML api icl_object_id returns the parent id of the given post (i.e. the post in default language, where the eMember grants are setted). This code working also with the category grant because for the same effect, in the dashboard are showed the category in default language.
Tell me if you can accept this portion of code to implement a simple integration with the one of the best WordPress translation plugin
P.S. Given that you request, the link is [http://business.lago.it/app-lago-i-cataloghi-prendono-vita/] but, this is a production system and I already made the modification
Than you
December 3, 2013 at 11:17 pm #59426adminKeymasterI will add a filter in our auth_check_post function for the next version. So that function will look like the following:
function auth_check_post($content){
global $post;
$id = $post->ID;
if(empty($id)) return $content;
$id = apply_filters( 'emember_auth_check_post_id', $id);
return check_post_content($id, $content);
}You can then add the following code in your functions.php or a custom plugin:
add_filter( 'emember_auth_check_post_id', 'custom_get_wpml_parent_id' );
function custom_get_wpml_parent_id( $id ) {
if ( function_exists( 'icl_object_id' ) == true ) {
return icl_object_id( $id, 'post', false, 'it' );
}
return $id;
} -
AuthorPosts
- You must be logged in to reply to this topic.