Fix WPML compatibility

This commit is contained in:
champsupertramp
2016-03-20 20:02:06 +08:00
parent 4a96c60149
commit 432c0fa01a
6 changed files with 88 additions and 40 deletions
+42
View File
@@ -0,0 +1,42 @@
<?php
add_filter("um_localize_permalink_filter","um_localize_permalink_filter",10,3);
function um_localize_permalink_filter( $core_pages, $page_id, $profile_url ){
global $ultimatemember;
get_post( $page_id );
if ( function_exists('icl_get_current_language') && icl_get_current_language() != icl_get_default_language() ) {
if ( get_the_ID() > 0 && get_post_meta( get_the_ID(), '_um_wpml_user', true ) == 1 ) {
$profile_url = get_permalink( get_the_ID() );
}
}
// 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_code );
}
}
return $profile_url;
}
add_filter('um_core_page_id_filter','um_core_page_id_filter');
function um_core_page_id_filter( $page_id ){
/* if( ! empty( $_GET['lang'] ) && isset( $_GET['lang'] ) ){
$page_id = $page_id.'_'.$_GET['lang'];
}
*/
return $page_id;
}
+1 -19
View File
@@ -191,28 +191,10 @@ class UM_Permalinks {
$page_id = $this->core['user'];
$profile_url = get_permalink( $page_id );
if ( function_exists('icl_get_current_language') && icl_get_current_language() != icl_get_default_language() ) {
if ( get_the_ID() > 0 && get_post_meta( get_the_ID(), '_um_wpml_user', true ) == 1 ) {
$profile_url = get_permalink( get_the_ID() );
}
}
// WPML compatibility
if ( function_exists('icl_object_id') ) {
$profile_url = apply_filters('um_localize_permalink_filter', $this->core, $page_id, $profile_url );
$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');
+10 -6
View File
@@ -12,16 +12,20 @@ class UM_Query {
*** @get wp pages
***/
function wp_pages() {
$count_pages = wp_count_posts('page');
global $wpdb;
$pages = $wpdb->get_results('SELECT * FROM '.$wpdb->posts.' WHERE post_type = "page" AND post_status = "publish" ', OBJECT);
$count_pages = $wpdb->num_rows;
if ( $count_pages->publish > 300 )
return;
if ( $count_pages > 300 )
return 'reached_maximum_limit';
$pages = get_pages();
$array = '';
foreach ($pages as $page_data) {
$array[ $page_data->ID ] = $page_data->post_title;
if( $wpdb->num_rows > 0 ){
foreach ($pages as $page_data) {
$array[ $page_data->ID ] = $page_data->post_title;
}
}
return $array;
}
+15
View File
@@ -1567,3 +1567,18 @@ function um_fetch_user( $user_id ) {
function um_search_form() {
echo um_get_search_form();
}
/**
* Get localization
* @return string
*/
function um_get_locale(){
$lang_code = get_locale();
if( strpos( $lang_code , 'en_' ) > -1 || empty( $lang_code ) || $lang_code == 0 ){
return 'en';
}
return $lang_code;
}
+19 -15
View File
@@ -23,27 +23,31 @@ foreach( $core_pages as $page_s => $page ) {
$have_pages = $ultimatemember->query->wp_pages();
if( ! empty( $have_pages ) ){
$page_setup[] = array(
'id' => 'core_' . $page_s,
'type' => 'select',
'select2' => array( 'allowClear' => 0, 'minimumResultsForSearch' => -1 ),
'title' => $page,
'default' => ( isset( $ultimatemember->permalinks->core[ $page_s ] ) ) ? $ultimatemember->permalinks->core[ $page_s ] : '' ,
'options' => $ultimatemember->query->wp_pages(),
'placeholder' => __('Choose a page...','ultimatemember'),
'compiler' => true,
);
}else{
$page_setup[] = array(
'id' => 'core_' . $page_s,
$page_id = 'core_' . $page_s;
$page_id = apply_filters('um_core_page_id_filter', $page_id );
if( 'reached_maximum_limit' == $have_pages ){
$page_setup[] = array(
'id' => $page_id,
'type' => 'text',
'title' => $page,
'placeholder' => __('Add page ID','ultimatemember'),
'default' => ( isset( $ultimatemember->permalinks->core[ $page_s ] ) ) ? $ultimatemember->permalinks->core[ $page_s ] : '',
'default' => ( isset( $ultimatemember->permalinks->core[ $page_id ] ) ) ? $ultimatemember->permalinks->core[ $page_id ] : '',
'compiler' => true,
);
}else{
$page_setup[] = array(
'id' => $page_id,
'type' => 'select',
'select2' => array( 'allowClear' => 0, 'minimumResultsForSearch' => -1 ),
'title' => $page,
'default' => ( isset( $ultimatemember->permalinks->core[ $page_id ] ) ) ? $ultimatemember->permalinks->core[ $page_id ] : '' ,
'options' => $ultimatemember->query->wp_pages(),
'placeholder' => __('Choose a page...','ultimatemember'),
'compiler' => true,
);
}
}
$this->sections[] = array(
+1
View File
@@ -142,6 +142,7 @@ class UM_API {
require_once um_path . 'core/um-actions-modal.php';
require_once um_path . 'core/um-actions-misc.php';
require_once um_path . 'core/um-filters-language.php';
require_once um_path . 'core/um-filters-login.php';
require_once um_path . 'core/um-filters-fields.php';
require_once um_path . 'core/um-filters-files.php';