From 30af5aac356815ae341b492c00ca151e798e5732 Mon Sep 17 00:00:00 2001 From: champsupertramp Date: Sun, 10 Jan 2016 22:30:57 +0800 Subject: [PATCH] WPML compatibility --- core/um-permalinks.php | 18 ++++++++++++++++++ core/um-rewrite.php | 41 +++++++++++++++++++++++++++++++++-------- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/core/um-permalinks.php b/core/um-permalinks.php index e8a4fc99..9e564fb0 100644 --- a/core/um-permalinks.php +++ b/core/um-permalinks.php @@ -151,6 +151,24 @@ class UM_Permalinks { } } + // WPML compatibility + if ( function_exists('icl_object_id') ) { + + + $language_code = ICL_LANGUAGE_CODE; + $lang_post_id = icl_object_id( $page_id , 'page', true, $language_code ); + + if($lang_post_id != 0) { + $profile_url = get_permalink( $lang_post_id ); + }else { + // No page found, it's most likely the homepage + global $sitepress; + $profile_url = $sitepress->language_url( $language ); + } + + + } + if ( um_get_option('permalink_base') == 'user_login' ) { $user_in_url = um_user('user_login'); diff --git a/core/um-rewrite.php b/core/um-rewrite.php index 4f42ea56..383e3495 100644 --- a/core/um-rewrite.php +++ b/core/um-rewrite.php @@ -43,18 +43,43 @@ class UM_Rewrite { $user_slug = $user->post_name; $account = get_post($account_page_id); $account_slug = $account->post_name; - + + add_rewrite_rule( - '^'.$user_slug.'/([^/]*)$', - 'index.php?page_id='.$user_page_id.'&um_user=$matches[1]', - 'top' + '^'.$user_slug.'/([^/]*)$', + 'index.php?page_id='.$user_page_id.'&um_user=$matches[1]', + 'top' ); - + add_rewrite_rule( - '^'.$account_slug.'/([^/]*)$', - 'index.php?page_id='.$account_page_id.'&um_tab=$matches[1]', - 'top' + '^'.$account_slug.'/([^/]*)$', + 'index.php?page_id='.$account_page_id.'&um_tab=$matches[1]', + 'top' ); + + if ( function_exists('icl_object_id') || function_exists('icl_get_current_language') && icl_get_current_language() != icl_get_default_language() ) { + + if( function_exists('icl_get_current_language') ){ + $language_code = icl_get_current_language(); + }else if( function_exists('icl_object_id') ){ + $language_code = ICL_LANGUAGE_CODE; + } + + add_rewrite_rule( + '^'.$language_code.'/'.$user_slug.'/([^/]*)$', + 'index.php?page_id='.$user_page_id.'&um_user=$matches[1]', + 'bottom' + ); + + add_rewrite_rule( + '^'.$language_code.'/'.$account_slug.'/([^/]*)$', + 'index.php?page_id='.$account_page_id.'&um_tab=$matches[1]', + 'bottom' + ); + + }else{ + + } flush_rewrite_rules( true );