This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 4 replies, has 2 voices.

Last updated by carstenD-7 4 months, 3 weeks ago.

Assigned support staff: Bruno.

Author Posts
May 24, 2019 at 2:00 pm #3885437

carstenD-7

I am trying to:
Using manual coding, on admin dashboard, we need to make a feature to restrict a user of certain role (based on locale) from modifying media translation belonging to another locale.

Link to a page where the issue can be seen:
hidden link
hidden link

I expected to see:
So I wanted to know which API hooks or filters we can utilize to achieve the feature described above.

Instead, I got:

We have done a custom user roles feature for language restrictions on pages, posts and cpts on admin dashboard. However, for Media Translation, it looks like we need some special hooks or filters specific to Media Translation.

On a sidenote:

Is there a way for us to limit the countries columns to only show the countries we want? Do you have something on the entirety of API that gives us ability to control that?

hidden link

May 24, 2019 at 9:30 pm #3887693

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for contacting us. I do not think we have a hook specifically to do that.

In this case, you will need to look at the WPML Media code to see how you could do this.

We have a list of WPML hooks that can help you develop such feature, which can be seen in the links below:

- https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference

If you prefer, you can contact one of our certified partners who can develop small to large features for your site: http://wpml.org/documentation/support/wpml-contractors/

Thank you.

May 27, 2019 at 1:25 pm #3897559

carstenD-7

I am not sure where to find that certain part in the source code of WPML Media that I can utilize. It seems its hard to find something in there when you have so many files to look at.

But I did an alternative solution, I am taking a chance at doing it via javascript, by giving it a variable about the user's role and the role's supposed language.

This way I was able to do this when the admin gets loaded:

hidden link

The German and English are there, but the other language have "opacity:0.5" and pointer-events:none" on their styling.

I did that via Jquery by getting all the elements of certain class (specific to languages) and apply styling to them, but do you think its a good solution in the long run?

May 28, 2019 at 2:00 am #3901851

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Yes, it seems to be a good solution. Since the WPML Media popup itself is via JavaScript, there is no way for the user to open that in another tab.

Since you have added your custom coding to some other plugin or child theme, I do not see any problems in the code. Even updating WPML you should not lose this custom code.

Please, let me know if I can help with any other questions you may have about it. I'll be happy to help.

Thank you.

May 30, 2019 at 7:40 am #3920997

carstenD-7

Yes I need to be careful not messing with the cores.

Using the same approach with Javascript I was able to hide specific languages from the admin bar language selector. So yes I guess I have a working custom solution now.

Only issue I can see if someday WPML changed the specific wpml css classes I was querying, but I guess I just need to update my own code then.

Anyway thanks for the help Bruno.