-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtranslate-support-for-gravityforms.php
58 lines (56 loc) · 2.66 KB
/
qtranslate-support-for-gravityforms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
Plugin Name: qTranslate support for GravityForms
Plugin URI: https://github.com/mweimerskirch/wordpress-qtranslate-support-for-gravityforms
Description: Makes qTranslate work with GravityForms
Version: 1.0
Author: Michel Weimerskirch
Author URI: http://michel.weimerskirch.net
License: MIT
*/
add_filter('gform_pre_render', 'qtranslate_gform_pre_render');
add_filter('gform_pre_submission_filter', 'qtranslate_gform_pre_render');
function qtranslate_gform_pre_render($form) {
if(isset($form['button']['text'])) {
$form['button']['text'] = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($form['button']['text']);
}
if(isset($form['title'])) {
$form['title'] = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($form['title']);
}
if(isset($form['description'])) {
$form['description'] = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($form['description']);
}
if(isset($form['confirmation']['message'])) {
$form['confirmation']['message'] = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($form['confirmation']['message']);
}
foreach($form['fields'] as $id => $field) {
$form['fields'][$id]['label'] = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($form['fields'][$id]['label']);
$form['fields'][$id]['content'] = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($form['fields'][$id]['content']);
$form['fields'][$id]['description'] = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($form['fields'][$id]['description']);
$form['fields'][$id]['defaultValue'] = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($form['fields'][$id]['defaultValue']);
$form['fields'][$id]['errorMessage'] = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($form['fields'][$id]['errorMessage']);
$form['fields'][$id]['validation_message'] = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($form['fields'][$id]['validation_message']);
$form['fields'][$id]['choices'] = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($form['fields'][$id]['choices']);
if(isset($form['fields'][$id]['conditionalLogic']['rules'])) {
foreach ($form['fields'][$id]['conditionalLogic']['rules'] as $value => $key) {
foreach($key as $value2 =>$key2){
$form['fields'][$id]['conditionalLogic']['rules'][$value][$value2] = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($key2);
}
}
}
}
return $form;
}
add_filter('gform_form_tag', 'qtranslate_gform_form_tag');
function qtranslate_gform_form_tag($tag) {
global $q_config;
$tag = preg_replace_callback(
"|action='([^']+)'|",
create_function(
'$matches',
'return "action=\'" . qtrans_convertURL($matches[1], '.$q_config['language'].') . "\'";'
),
$tag
);
return $tag;
}