Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

qtranslate, hide a language for a specific role WordPress

  • SOLVED

i use Qtranslate

My site is in four languages : french, german, english, spanish.

I have created four roles : french_admin, german_admin, english_admin, spanish_admin

each post will be translated in 4 languages but if i am spanish_admin i can see (in the backoffice) only the title+the content in spanish, and the title+the content in french

for example, i used this code for the spanish_admin :

add_action( 'admin_footer', 'hide_language' );
function hide_language() {

global $current_user;
get_currentuserinfo();

if(current_user_can('espanol_admin')) {
?>
<script>
jQuery(document).ready( function($) {

//hide english
$('#qtrans_title_en').parents('div.postarea').remove();
$('#qtrans_select_en').hide();

$('#qtrans_term_en').hide();
$('label[for="qtrans_term_en"]').hide();

//hide german
$('#qtrans_title_de').parents('div.postarea').remove();
$('#qtrans_select_de').hide();

$('#qtrans_term_de').hide();
$('label[for="qtrans_term_de"]').hide();

})
</script>
<?php }
}
?>


the german fields & the spanish fields are removed.
But the content of the title (in french & spanish) and the content of the visual editor (in spanish) are not saved.


How can i hide the anglish fields and the german fields when the user is spanish_admin ?
(i want to hide the fields in the BO of post & in the BO of categories)

Answers (2)

2012-06-14

Rashad Aliyev answers:

Send me your wp credentials for 10 minutes. I want to analyze it live. I hope I can help you.


Sébastien | French WordpressDesigner comments:

i have sent my wp login


Rashad Aliyev comments:

Ok, I'm looking it now.


Rashad Aliyev comments:

I need ftp credentials for fixing your code.


Rashad Aliyev comments:

I've waited for a few minutes fixing it for you. But I think you're away. Please change this codes with yours.
<?php

add_action( 'admin_footer', 'hide_language' );
function hide_language() {
global $current_user;
get_currentuserinfo();
if(current_user_can('espanol_admin')) {
?>
<script>
jQuery(document).ready( function($) {

//hide english
$('#qtrans_title_en').parents('div.postarea').css({"display":"none"});
$('#qtrans_select_en').hide();

$('#qtrans_term_en').hide();
$('label[for="qtrans_term_en"]').hide();

//hide german
$('#qtrans_title_de').parents('div.postarea').css({"display":"none"});
$('#qtrans_select_de').hide();

$('#qtrans_term_de').hide();
$('label[for="qtrans_term_de"]').hide();
})

</script>
<?php }
}
?>


Rashad Aliyev comments:

P.S: I've started with <?php . If your php tag not closed then remove it.


Sébastien | French WordpressDesigner comments:

with your code the fields are removed : ok
the french title & the spanish title are saved : ok

the french content is saved : ok
but the spanish content is not saved

i suppose that when i click on the tab "spanish" i write my content not in the spanish tinymce (is it possible ?)

i send you my ftp access


Sébastien | French WordpressDesigner comments:

have you received my email ?


Rashad Aliyev comments:

Yes. The mission has been completed.


Sébastien | French WordpressDesigner comments:

not really :-)

.css({"display":"none"}); is ok to hide the fields
but the big problem is not resolved : the spanish contant (when you are spansih admin) is not saved


Rashad Aliyev comments:

I'll share you video that's working Sir. Please look at this. [[LINK href="http://tinypic.com/r/d5rnb/6"]]VIDEO[[/LINK]]


Sébastien | French WordpressDesigner comments:

very strange
i deleted my cache but that doesn't work with "post"
with "page" it's ok
but with "post", the spanish content is not saved

in chrome that's ok with page AND post (i suppose you have tried in chrome.)

but in FF and in IE, that doesn't work with post (i have tried with two computers)


Rashad Aliyev comments:

I've detected it's got problem only with FF. I'll look at this. By the way You must update your WP to latest WP Green version (v:3.4 ) But that's not supported by qTranslate yet.


Rashad Aliyev comments:

send me your ftp please
issues problem in qTranslate..i hope i'll help you


Sébastien | French WordpressDesigner comments:

I have sent you my FTP access yesterday


Rashad Aliyev comments:

the browsers(ff and ie) save bug is fixed..You can check..


Sébastien | French WordpressDesigner comments:

sorry rashad but no the problem is not resolved ...

1- when i am administrator, i can use 4 languages. The content of the 4 languages is not saved. If i have a content for the 4 languages, the content of "deutsh" is not saved. If i have only a french content and a spanish content, the spanish content is not saved.

2- have you modify a file in qtranslate ? If you have, could you please telle me where are the modifications ?
If i update the plugin, the bug will come back ?


Rashad Aliyev comments:

Dear my friend it's testing in spanish language..I said that please check it..if its ok..I'll fix other..Now please check spanish admin panel...If it's ok for you tell me


Sébastien | French WordpressDesigner comments:

rashad : before you modify files, it worked :-)
it's cool that the problem is resolved with the Spanish administrator, but it created a bug for administrator normal. So it's not good :-)

We must not only solve the problem for the Spanish administrator.
I wrote <blockquote>"if i am spanish_admin i can see (in the backoffice) only the title+the content in spanish"</blockquote> This is an example. But the problem must be solved for the German administrator, the administrator English etc. ... for each role obviously

Do you think that you know resolved the problem or not ?


Rashad Aliyev comments:

okeeey :-) now wait 10 min i'll solve others...and when you update the plugin, the bug will not come back..please wait


Rashad Aliyev comments:

you can check ...i fixed it


Sébastien | French WordpressDesigner comments:

thank you! it sounds great! I will test it tonight


Sébastien | French WordpressDesigner comments:

no file has been modified in qtranslate? there is just the code in functions.php, is that right?


Sébastien | French WordpressDesigner comments:

Very good job !

there is just a very little problem :
In IE, when you create a new post, the fields of title seems to be disabled
[[LINK href="http://screencast-o-matic.com/watch/cl1DDDHiw"]]http://screencast-o-matic.com/watch/cl1DDDHiw[[/LINK]]

that's the same thing if you are connected as spanish_admin or german_admin etc...


When this bug is resolved, it will be really perfect :-)


Rashad Aliyev comments:

IE bug also fixed for you,friend :-)

2012-06-15

leannekera answers:

Hi Seb try this, I had a similar issue a while back and this worked for me. Instead of going from your users role it first checks to see what language your users browser is set to.

Pop this in your functions.php:


function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

function langlist () {
echo '<ul>';
// If english show the following language options
if (qtrans_getLanguage() == 'en') {
echo '<li><a href="' . qtrans_convertURL(curPageURL(), 'en') . '">English</a></li>';
echo '<li><a href="' . qtrans_convertURL(curPageURL(), 'de') . '">German</a></li>';
// If french show the following language options
} elseif (qtrans_getLanguage() == 'fr') {
echo '<li><a href="' . qtrans_convertURL(curPageURL(), 'en') . '">English</a></li>';
echo '<li><a href="' . qtrans_convertURL(curPageURL(), 'fr') . '">French</a></li>';
// If any other language show the below options
} else {
echo '<li><a href="' . qtrans_convertURL(curPageURL(), 'en') . '">English</a></li>';
echo '<li><a href="' . qtrans_convertURL(curPageURL(), 'de') . '">German</a></li>';
echo '<li><a href="' . qtrans_convertURL(curPageURL(), 'fr') . '">French</a></li>';
}
echo '</ul>'; }


Then add this wherever you wish to show the language options within your template:


<?php langlist(); ?>


Hope this helps!


leannekera comments:

Alternatively if you do wish to decide the language based on the admin role you can do the following in your template:



<?php $user_role = reset( $GLOBALS['current_user']->roles );
// specify user roles that you want to be able to see
if (in_array( $user_role, array('french_admin', 'english_admin') )) {
echo 'For English and French ';
echo '<li><a href="' . qtrans_convertURL(curPageURL(), 'en') . '">English</a></li>';
echo '<li><a href="' . qtrans_convertURL(curPageURL(), 'fr') . '">French</a></li>';
} else {
echo 'Else if you are German or not logged in, you will only see this:';
echo '<li><a href="' . qtrans_convertURL(curPageURL(), 'de') . '">German</a></li>';
} ?>