• Is it possible to restrict page modification/creation to a specific language for a specific user role?

    I would like to give a user the ability to edit German pages only. How can I do that?

    I’m prepared to buy the pro version if necessary.

    Many thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Chouby

    (@chouby)

    Hi!

    This feature does not exist yet. I take note of your request to include it in our roadmap (We develop features based on the user requests).

    Is there something changed in this issue? Polylang is very useful and friendly for users but without possible to restrict page modification/creation to a specific language for a specific user role, it’s seems uncompleted…

    Thread Starter from-scratch

    (@from-scratch)

    I don’t think there is any update on this matter yet.

    I ended up coding it myself by adding hooks on save post. It’s not really clean but it makes the job for now…!

    Can you explain how to do that? – I don’t know much about hooks…

    Thread Starter from-scratch

    (@from-scratch)

    Here is an example of code to add in your functions.php file.
    It’s definetly not the cleanest code, as it exit the page a bit quick and without any good design, but at least it works..

    function limitTraducteur( $post_id, $post, $update ) {
    	$usermeta = wp_get_current_user();
    	if (in_array("translator", $usermeta->roles) && isset($_POST) && count($_POST)>0) {
    		// If it's a menu, block the role to a specific ID menu
    		if (isset($_POST["menu"]) && $_POST["menu"]!=9) {
    			echo "Error: You are not allowed to edit this menu. Please select the German menu.";
    			echo "<br/><br/><a href='javascript:history.go(-1)'>Back</a>";
    			exit;
                    // For the other content than menu
    		} elseif ($_POST["post_lang_choice"]!="de" && $update==true && !isset($_POST["menu"]) && $_POST["menu"]!=9) {
    			echo "Error: You are not allowed to edit a content in a different language than German.";
    			echo "<br/><br/><a href='javascript:history.go(-1)'>Back</a>";
    			exit;
    		}
    	}
    }
    add_action( 'save_post', 'limitTraducteur', 10, 3 );

    I’m doing something wrong but i don’t know what:
    – I’ve created role ‘translator’;
    – I’ve changed menu id and language code in function;
    …and nothing happens… Maybe i missed something? Can you have a look on this code below? Thank you for your help.

    function limitTraducteur( $post_id, $post, $update ) {
    	$usermeta = wp_get_current_user();
    	if (in_array("translator", $usermeta->roles) && isset($_POST) && count($_POST)>0) {
    		// If it's a menu, block the role to a specific ID menu
    		if (isset($_POST["menu"]) && $_POST["menu"]!=20) {
    			echo "Error: You are not allowed to edit this menu. Please select the Polish menu.";
    			echo "<br/><br/><a href='javascript:history.go(-1)'>Back</a>";
    			exit;
                    // For the other content than menu
    		} elseif ($_POST["post_lang_choice"]!="pl" && $update==true && !isset($_POST["menu"]) && $_POST["menu"]!=20) {
    			echo "Error: You are not allowed to edit a content in a different language than Polish.";
    			echo "<br/><br/><a href='javascript:history.go(-1)'>Back</a>";
    			exit;
    		}
    	}
    }
    add_action( 'save_post', 'limitTraducteur', 10, 3 );
    • This reply was modified 8 years, 2 months ago by Kubzon.
    • This reply was modified 8 years, 2 months ago by Kubzon.

    Ok, my mistake durining upload file – but after seeing error message ‘You are not allowed…’, post is sill updated or published.

    • This reply was modified 8 years, 2 months ago by Kubzon.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Translator role’ is closed to new replies.