Skip to content

Commit

Permalink
translation of user metadata at front end
Browse files Browse the repository at this point in the history
  • Loading branch information
johnclause committed Jun 5, 2015
1 parent 56d2040 commit dd0dba7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
42 changes: 33 additions & 9 deletions qtranslate_frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,26 +596,27 @@ function qtranxf_trim_words( $text, $num_words, $more, $original_text ) {
* Delete translated post_meta cache for all languages.
* Cache may have a few languages, if it is persistent.
*/
function qtranxf_cache_delete_postmeta($object_id) {
function qtranxf_cache_delete_metadata($meta_type, $object_id){//, $meta_key) {
global $q_config;
//maybe optimized to only replace the meta_key needed ?
foreach($q_config['enabled_languages'] as $lang){
$cache_key_lang = 'post_meta' . $lang;
$cache_key_lang = $meta_type . '_meta' . $lang;
wp_cache_delete($object_id, $cache_key_lang);
}
}

/**
* @since 3.2.3 translation of postmeta
* @since 3.2.3 translation of meta data
*/
function qtranxf_filter_postmeta($original_value, $object_id, $meta_key = '', $single = false){
function qtranxf_translate_metadata($meta_type, $original_value, $object_id, $meta_key = '', $single = false){
global $q_config;
if(!isset($q_config['url_info'])){
//qtranxf_dbg_log('qtranxf_filter_postmeta: too early: $object_id='.$object_id.'; $meta_key',$meta_key,true);
return $original_value;
}
//qtranxf_dbg_log('qtranxf_filter_postmeta: $object_id='.$object_id.'; $meta_key=',$meta_key);

$meta_type = 'post';
//$meta_type = 'post';
$lang = $q_config['language'];
$cache_key = $meta_type . '_meta';
$cache_key_lang = $cache_key . $lang;
Expand All @@ -626,7 +627,7 @@ function qtranxf_filter_postmeta($original_value, $object_id, $meta_key = '', $s
$meta_cache = wp_cache_get( $object_id, $cache_key_lang );
}else{
//reset qtx cache, since it would not be valid in the absence of wp cache
qtranxf_cache_delete_postmeta($object_id);
qtranxf_cache_delete_metadata($meta_type, $object_id);
$meta_cache = null;
}
if( !$meta_cache ){
Expand Down Expand Up @@ -701,6 +702,13 @@ function qtranxf_filter_postmeta($original_value, $object_id, $meta_key = '', $s
else
return array();
}

/**
* @since 3.2.3 translation of postmeta
*/
function qtranxf_filter_postmeta($original_value, $object_id, $meta_key = '', $single = false){
return qtranxf_translate_metadata('post', $original_value, $object_id, $meta_key, $single);
}
add_filter('get_post_metadata', 'qtranxf_filter_postmeta', 5, 4);

/**
Expand All @@ -709,12 +717,28 @@ function qtranxf_filter_postmeta($original_value, $object_id, $meta_key = '', $s
* Cache may have a few languages, if it is persistent.
*/
function qtranxf_updated_postmeta( $meta_id, $object_id, $meta_key, $meta_value ) {
//may be optimized to replace the key needed
qtranxf_cache_delete_postmeta($object_id);
//qtranxf_dbg_log('qtranxf_updated_postmeta(meta_id='.$meta_id.', object_id='.$object_id.', meta_key='.$meta_key.', meta_value='.$meta_value.'): cache_key_lang=',$cache_key_lang);
qtranxf_cache_delete_metadata('post', $object_id);
}
add_action('updated_postmeta', 'qtranxf_updated_postmeta', 5, 4);

/**
* @since 3.4 translation of usermeta
*/
function qtranxf_filter_usermeta($original_value, $object_id, $meta_key = '', $single = false){
return qtranxf_translate_metadata('user', $original_value, $object_id, $meta_key, $single);
}
add_filter('get_user_metadata', 'qtranxf_filter_usermeta', 5, 4);

/**
* @since 3.4
* Delete translated user_meta cache for all languages on cache update.
* Cache may have a few languages, if it is persistent.
*/
function qtranxf_updated_usermeta( $meta_id, $object_id, $meta_key, $meta_value ) {
qtranxf_cache_delete_metadata('user', $object_id);
}
add_action('updated_usermeta', 'qtranxf_updated_usermeta', 5, 4);

function qtranxf_checkCanonical($redirect_url, $requested_url) {
global $q_config;
//if(!qtranxf_can_redirect()) return $redirect_url;// WP already check this
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Developers: please drop new topics here, the text will be moved to [qTranslate-X
* Enhancement: 'plugins' vs 'mu-plugins', links of sub-folders, etc. [Issue #168](https://github.com/qTranslate-Team/qtranslate-x/pull/168).
* Enhancement: gettext filters in raw and single language modes.
* Enhancement: turn on 'Compatibility Functions' on first activation, if a file of one of the former forks is detected.
* Enhancement: translation of user metadata at front end [WP Topic](https://wordpress.org/support/topic/biographical-info-1).
* Fix: handling non-standard language code: [Issue #171](https://github.com/qTranslate-Team/qtranslate-x/issues/171).
* Fix: 'Head inline CSS' update on language list changes.
* Fix: pagination of posts under Query Mode of URL Modification (filter 'qtranxf_convertBlogInfoURL'): [Issue #155](https://github.com/qTranslate-Team/qtranslate-x/issues/155). Filters 'home_url' and 'bloginfo_url' are disabled in Query mode.
Expand Down

0 comments on commit dd0dba7

Please sign in to comment.