Version Description
Added support for Image Fields. Thanks to bookwyrm for the contribution.
Download this release
Release Info
Developer | funkjedi |
Plugin | ACF qTranslate |
Version | 1.1 |
Comparing to | |
See all releases |
Version 1.1
- acf-qtranslate.php +46 -0
- assets/main.css +88 -0
- assets/main.js +22 -0
- fields/image.php +132 -0
- fields/text.php +70 -0
- fields/textarea.php +70 -0
- fields/wysiwyg.php +109 -0
- readme.txt +54 -0
acf-qtranslate.php
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Advanced Custom Fields: qTranslate
|
4 |
+
Plugin URI: http://github.com/funkjedi/acf-qtranslate
|
5 |
+
Description: Provides multilingual versions of the text, text area, and wysiwyg fields.
|
6 |
+
Version: 1.1.0
|
7 |
+
Author: funkjedi
|
8 |
+
Author URI: http://funkjedi.com
|
9 |
+
License: GPLv2 or later
|
10 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
+
*/
|
12 |
+
|
13 |
+
// http://support.advancedcustomfields.com/discussion/1181/prease-check-wp3-3-qtranslate-advance-custom-field/p1
|
14 |
+
|
15 |
+
|
16 |
+
function acf_qtranslate_enabled() {
|
17 |
+
return function_exists('qtrans_getSortedLanguages');
|
18 |
+
}
|
19 |
+
|
20 |
+
add_action('acf/register_fields', 'acf_qtranslate_plugin_register_fields');
|
21 |
+
function acf_qtranslate_plugin_register_fields() {
|
22 |
+
|
23 |
+
require_once dirname(__FILE__) . '/fields/text.php';
|
24 |
+
require_once dirname(__FILE__) . '/fields/textarea.php';
|
25 |
+
require_once dirname(__FILE__) . '/fields/wysiwyg.php';
|
26 |
+
require_once dirname(__FILE__) . '/fields/image.php';
|
27 |
+
|
28 |
+
}
|
29 |
+
|
30 |
+
add_action('admin_enqueue_scripts', 'acf_qtranslate_admin_enqueue_scripts');
|
31 |
+
function acf_qtranslate_admin_enqueue_scripts() {
|
32 |
+
wp_enqueue_style('acf_qtranslate_main', plugins_url('/assets/main.css', __FILE__));
|
33 |
+
wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/main.js', __FILE__));
|
34 |
+
}
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
// enable qtranslate quicktags for all string based fields
|
39 |
+
add_filter('acf/format_value_for_api', 'acf_qtranslate_plugin_format_value_for_api');
|
40 |
+
function acf_qtranslate_plugin_format_value_for_api($value) {
|
41 |
+
if (acf_qtranslate_enabled() && is_string($value)) {
|
42 |
+
$value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
|
43 |
+
}
|
44 |
+
|
45 |
+
return $value;
|
46 |
+
}
|
assets/main.css
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
.multi-language-field { margin-top: -32px }
|
3 |
+
.repeater .multi-language-field { margin-top: 0 }
|
4 |
+
|
5 |
+
|
6 |
+
.multi-language-field .wp-switch-editor {
|
7 |
+
border-color: #dfdfdf;
|
8 |
+
position: relative;
|
9 |
+
top: 1px;
|
10 |
+
z-index: 100;
|
11 |
+
}
|
12 |
+
|
13 |
+
.multi-language-field.focused .wp-switch-editor { border-color: #bbb }
|
14 |
+
|
15 |
+
.multi-language-field .wp-switch-editor.current-language {
|
16 |
+
background-color: #fff;
|
17 |
+
border-bottom-color: #fff;
|
18 |
+
color: #333;
|
19 |
+
}
|
20 |
+
|
21 |
+
|
22 |
+
.multi-language-field > input,
|
23 |
+
.multi-language-field > textarea,
|
24 |
+
.multi-language-field > fieldset,
|
25 |
+
.multi-language-field .acf_wysiwyg,
|
26 |
+
.multi-language-field .acf-image-uploader { display: none }
|
27 |
+
|
28 |
+
.multi-language-field .acf_input input,
|
29 |
+
.multi-language-field .acf_input textarea,
|
30 |
+
.multi-language-field .current-language { display: block !important }
|
31 |
+
|
32 |
+
|
33 |
+
.multi-language-widget .wp-switch-editor {
|
34 |
+
height: 18px;
|
35 |
+
font: 13px/18px Arial,Helvetica,sans-serif normal;
|
36 |
+
margin: 5px 5px 0 0;
|
37 |
+
padding: 4px 5px 2px;
|
38 |
+
float: right;
|
39 |
+
cursor: pointer;
|
40 |
+
border-width: 1px;
|
41 |
+
border-style: solid;
|
42 |
+
border-top-right-radius: 3px;
|
43 |
+
border-top-left-radius: 3px;
|
44 |
+
background-color: #f1f1f1;
|
45 |
+
border-color: #dfdfdf;
|
46 |
+
color: #999;
|
47 |
+
}
|
48 |
+
|
49 |
+
.multi-language-widget .wp-switch-editor.current-language {
|
50 |
+
background: #ededed;
|
51 |
+
border-bottom-color: #ededed;
|
52 |
+
}
|
53 |
+
|
54 |
+
.multi-language-widget.button-widget .wp-switch-editor.current-language {
|
55 |
+
background-color: #fff;
|
56 |
+
border-bottom-color: #fff;
|
57 |
+
}
|
58 |
+
|
59 |
+
.multi-language-widget.text-widget fieldset {
|
60 |
+
background: #ededed;
|
61 |
+
border: 1px solid #dfdfdf;
|
62 |
+
border-radius: 5px;
|
63 |
+
margin: 0 0 10px 0;
|
64 |
+
padding: 10px;
|
65 |
+
width: 95%;
|
66 |
+
}
|
67 |
+
|
68 |
+
.multi-language-field-wysiwyg { margin-top: 0 }
|
69 |
+
|
70 |
+
.multi-language-field .acf-image-uploader {
|
71 |
+
padding: 20px 10px 10px;
|
72 |
+
clear: right;
|
73 |
+
border: 1px solid #dfdfdf;
|
74 |
+
}
|
75 |
+
|
76 |
+
.multi-language-field-wysiwyg .wp-switch-editor {
|
77 |
+
background-color: #f1f1f1;
|
78 |
+
border-color: #dfdfdf;
|
79 |
+
border-bottom-color: #ccc;
|
80 |
+
top: 0px;
|
81 |
+
}
|
82 |
+
|
83 |
+
.multi-language-field-wysiwyg .wp-switch-editor.current-language {
|
84 |
+
background-color: #f4f4f4;
|
85 |
+
border-color: #ccc;
|
86 |
+
border-bottom-color: #f4f4f4;
|
87 |
+
}
|
88 |
+
|
assets/main.js
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
jQuery(function($) {
|
3 |
+
|
4 |
+
|
5 |
+
$('body').on('click', '.wp-switch-editor[data-language]', function() {
|
6 |
+
var parent = $(this).parent('.multi-language-field'), language = $(this).data('language');
|
7 |
+
|
8 |
+
parent.find('.current-language').removeClass('current-language');
|
9 |
+
parent.find('[data-language="' + language + '"]').addClass('current-language');
|
10 |
+
parent.find('input[data-language="' + language + '"], textarea[data-language="' + language + '"]').focus();
|
11 |
+
});
|
12 |
+
|
13 |
+
$('body').on('focusin', '.multi-language-field input, .multi-language-field textarea', function() {
|
14 |
+
$(this).parent('.multi-language-field').addClass('focused');
|
15 |
+
});
|
16 |
+
|
17 |
+
$('body').on('focusout', '.multi-language-field input, .multi-language-field textarea', function() {
|
18 |
+
$(this).parent('.multi-language-field').removeClass('focused');
|
19 |
+
});
|
20 |
+
|
21 |
+
|
22 |
+
});
|
fields/image.php
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class acf_field_qtranslate_image extends acf_field_image
|
4 |
+
{
|
5 |
+
|
6 |
+
function __construct()
|
7 |
+
{
|
8 |
+
|
9 |
+
$this->name = 'qtranslate_image';
|
10 |
+
$this->label = __("Image", 'acf');
|
11 |
+
$this->category = __("qTranslate", 'acf');
|
12 |
+
|
13 |
+
$this->defaults = array(
|
14 |
+
'save_format' => 'object',
|
15 |
+
'preview_size' => 'thumbnail',
|
16 |
+
'library' => 'all'
|
17 |
+
);
|
18 |
+
$this->l10n = array(
|
19 |
+
'select' => __("Select Image",'acf'),
|
20 |
+
'edit' => __("Edit Image",'acf'),
|
21 |
+
'uploadedTo' => __("uploaded to this post",'acf'),
|
22 |
+
);
|
23 |
+
|
24 |
+
|
25 |
+
acf_field::__construct();
|
26 |
+
|
27 |
+
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
|
28 |
+
add_action('acf_head-update_attachment-' . $this->name, array($this, 'acf_head_update_attachment'));
|
29 |
+
add_action('admin_head-media-upload-popup', array($this, 'popup_head'));
|
30 |
+
|
31 |
+
add_action('wp_ajax_acf/fields/image/get_images', array($this, 'ajax_get_images'), 10, 1);
|
32 |
+
add_action('wp_ajax_nopriv_acf/fields/image/get_images', array($this, 'ajax_get_images'), 10, 1);
|
33 |
+
add_action('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
|
34 |
+
}
|
35 |
+
|
36 |
+
function create_field($field)
|
37 |
+
{
|
38 |
+
if (!acf_qtranslate_enabled()) {
|
39 |
+
acf_field_image::create_field($field);
|
40 |
+
return;
|
41 |
+
}
|
42 |
+
|
43 |
+
global $q_config;
|
44 |
+
$languages = qtrans_getSortedLanguages(true);
|
45 |
+
$values = qtrans_split($field['value'], $quicktags = true);
|
46 |
+
$currentLanguage = qtrans_getLanguage();
|
47 |
+
|
48 |
+
echo '<div class="multi-language-field multi-language-field-image">';
|
49 |
+
|
50 |
+
foreach ($languages as $language) {
|
51 |
+
$class = 'wp-switch-editor';
|
52 |
+
if ($language === $currentLanguage) {
|
53 |
+
$class .= ' current-language';
|
54 |
+
}
|
55 |
+
echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
|
56 |
+
}
|
57 |
+
|
58 |
+
$base_class = $field['class'];
|
59 |
+
$base_name = $field['name'];
|
60 |
+
foreach ($languages as $language) :
|
61 |
+
$value = $values[$language];
|
62 |
+
$o = array(
|
63 |
+
'class' => '',
|
64 |
+
'url' => '',
|
65 |
+
);
|
66 |
+
|
67 |
+
if ($value && is_numeric($value)) {
|
68 |
+
$url = wp_get_attachment_image_src($value, $field['preview_size']);
|
69 |
+
$o['class'] = 'active';
|
70 |
+
$o['url'] = $url[0];
|
71 |
+
}
|
72 |
+
$field['class'] = $base_class;
|
73 |
+
if ($language === $currentLanguage) {
|
74 |
+
$field['class'] .= ' current-language';
|
75 |
+
$o['class'] .= ' current-language';
|
76 |
+
}
|
77 |
+
|
78 |
+
$field['name'] = $base_name . '[' . $language . ']';
|
79 |
+
|
80 |
+
?>
|
81 |
+
<div class="acf-image-uploader clearfix <?php echo $o['class']; ?>" data-preview_size="<?php echo $field['preview_size']; ?>" data-library="<?php echo $field['library']; ?>" data-language="<?php echo $language; ?>" >
|
82 |
+
<input class="acf-image-value" type="hidden" name="<?php echo $field['name']; ?>" value="<?php echo $value; ?>" />
|
83 |
+
<div class="has-image">
|
84 |
+
<div class="hover">
|
85 |
+
<ul class="bl">
|
86 |
+
<li><a class="acf-button-delete ir" href="#"><?php _e("Remove", 'acf'); ?></a></li>
|
87 |
+
<li><a class="acf-button-edit ir" href="#"><?php _e("Edit", 'acf'); ?></a></li>
|
88 |
+
</ul>
|
89 |
+
</div>
|
90 |
+
<img class="acf-image-image" src="<?php echo $o['url']; ?>" alt="" />
|
91 |
+
</div>
|
92 |
+
<div class="no-image">
|
93 |
+
<p><?php _e('No image selected','acf'); ?> <input type="button" class="button add-image" value="<?php _e('Add Image','acf'); ?>" />
|
94 |
+
</div>
|
95 |
+
</div>
|
96 |
+
|
97 |
+
<?php endforeach;
|
98 |
+
|
99 |
+
echo '</div>';
|
100 |
+
}
|
101 |
+
|
102 |
+
function format_value($value, $post_id, $field)
|
103 |
+
{
|
104 |
+
return $value;
|
105 |
+
}
|
106 |
+
|
107 |
+
function format_value_for_api($value, $post_id, $field)
|
108 |
+
{
|
109 |
+
if (acf_qtranslate_enabled()) {
|
110 |
+
$value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
|
111 |
+
}
|
112 |
+
|
113 |
+
return acf_field_image::format_value_for_api($value, $post_id, $field);
|
114 |
+
}
|
115 |
+
|
116 |
+
function update_value($value, $post_id, $field)
|
117 |
+
{
|
118 |
+
if (acf_qtranslate_enabled()) {
|
119 |
+
$value = qtrans_join($value);
|
120 |
+
}
|
121 |
+
|
122 |
+
return $value;
|
123 |
+
}
|
124 |
+
|
125 |
+
function create_options( $field )
|
126 |
+
{
|
127 |
+
acf_field_image::create_options($field);
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
new acf_field_qtranslate_image();
|
132 |
+
|
fields/text.php
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class acf_field_qtranslate_text extends acf_field_text
|
4 |
+
{
|
5 |
+
|
6 |
+
function __construct()
|
7 |
+
{
|
8 |
+
$this->name = 'qtranslate_text';
|
9 |
+
$this->label = __("Text",'acf');
|
10 |
+
$this->category = __("qTranslate",'acf');
|
11 |
+
|
12 |
+
acf_field::__construct();
|
13 |
+
}
|
14 |
+
|
15 |
+
|
16 |
+
function create_field($field)
|
17 |
+
{
|
18 |
+
if (!acf_qtranslate_enabled()) {
|
19 |
+
acf_field_text::create_field($field);
|
20 |
+
return;
|
21 |
+
}
|
22 |
+
|
23 |
+
global $q_config;
|
24 |
+
$languages = qtrans_getSortedLanguages(true);
|
25 |
+
$values = qtrans_split($field['value'], $quicktags = true);
|
26 |
+
|
27 |
+
echo '<div class="multi-language-field">';
|
28 |
+
|
29 |
+
foreach ($languages as $language) {
|
30 |
+
$class = ($language === end($languages)) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
|
31 |
+
echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
|
32 |
+
}
|
33 |
+
|
34 |
+
foreach ($languages as $language) {
|
35 |
+
$class = ($language === end($languages)) ? $field['class'] . ' current-language' : $field['class'];
|
36 |
+
echo '<input type="text" data-language="' . esc_attr($language) . '" value="' . esc_attr($values[$language]) . '" id="' . esc_attr( $field['id'] ) . '" class="' . esc_attr($class) . '" name="' . esc_attr($field['name'] . "[$language]") . '" />';
|
37 |
+
}
|
38 |
+
|
39 |
+
echo '</div>';
|
40 |
+
}
|
41 |
+
|
42 |
+
|
43 |
+
function format_value($value, $post_id, $field)
|
44 |
+
{
|
45 |
+
return $value;
|
46 |
+
}
|
47 |
+
|
48 |
+
|
49 |
+
function format_value_for_api($value, $post_id, $field) {
|
50 |
+
if (acf_qtranslate_enabled()) {
|
51 |
+
$value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
|
52 |
+
}
|
53 |
+
|
54 |
+
return acf_field_text::format_value_for_api($value, $post_id, $field);
|
55 |
+
}
|
56 |
+
|
57 |
+
|
58 |
+
function update_value($value, $post_id, $field)
|
59 |
+
{
|
60 |
+
if (acf_qtranslate_enabled()) {
|
61 |
+
$value = qtrans_join($value);
|
62 |
+
}
|
63 |
+
|
64 |
+
return $value;
|
65 |
+
}
|
66 |
+
|
67 |
+
}
|
68 |
+
|
69 |
+
|
70 |
+
new acf_field_qtranslate_text;
|
fields/textarea.php
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class acf_field_qtranslate_textarea extends acf_field_textarea
|
4 |
+
{
|
5 |
+
|
6 |
+
function __construct()
|
7 |
+
{
|
8 |
+
$this->name = 'qtranslate_textarea';
|
9 |
+
$this->label = __("Text Area",'acf');
|
10 |
+
$this->category = __("qTranslate",'acf');
|
11 |
+
|
12 |
+
acf_field::__construct();
|
13 |
+
}
|
14 |
+
|
15 |
+
|
16 |
+
function create_field($field)
|
17 |
+
{
|
18 |
+
if (!acf_qtranslate_enabled()) {
|
19 |
+
acf_field_textarea::create_field($field);
|
20 |
+
return;
|
21 |
+
}
|
22 |
+
|
23 |
+
global $q_config;
|
24 |
+
$languages = qtrans_getSortedLanguages(true);
|
25 |
+
$values = qtrans_split($field['value'], $quicktags = true);
|
26 |
+
|
27 |
+
echo '<div class="multi-language-field">';
|
28 |
+
|
29 |
+
foreach ($languages as $language) {
|
30 |
+
$class = ($language === end($languages)) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
|
31 |
+
echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
|
32 |
+
}
|
33 |
+
|
34 |
+
foreach ($languages as $language) {
|
35 |
+
$class = ($language === end($languages)) ? $field['class'] . ' current-language' : $field['class'];
|
36 |
+
echo '<textarea data-language="' . esc_attr($language) . '" id="' . esc_attr( $field['id'] ) . '" rows="4" class="' . esc_attr($class) . '" name="' . esc_attr($field['name'] . "[$language]") . '">' . esc_textarea($values[$language]) . '</textarea>';
|
37 |
+
}
|
38 |
+
|
39 |
+
echo '</div>';
|
40 |
+
}
|
41 |
+
|
42 |
+
|
43 |
+
function format_value($value, $post_id, $field)
|
44 |
+
{
|
45 |
+
return $value;
|
46 |
+
}
|
47 |
+
|
48 |
+
|
49 |
+
function format_value_for_api($value, $post_id, $field) {
|
50 |
+
if (acf_qtranslate_enabled()) {
|
51 |
+
$value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
|
52 |
+
}
|
53 |
+
|
54 |
+
return acf_field_textarea::format_value_for_api($value, $post_id, $field);
|
55 |
+
}
|
56 |
+
|
57 |
+
|
58 |
+
function update_value($value, $post_id, $field)
|
59 |
+
{
|
60 |
+
if (acf_qtranslate_enabled()) {
|
61 |
+
$value = qtrans_join($value);
|
62 |
+
}
|
63 |
+
|
64 |
+
return $value;
|
65 |
+
}
|
66 |
+
|
67 |
+
}
|
68 |
+
|
69 |
+
|
70 |
+
new acf_field_qtranslate_textarea;
|
fields/wysiwyg.php
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class acf_field_qtranslate_wysiwyg extends acf_field_wysiwyg
|
4 |
+
{
|
5 |
+
|
6 |
+
function __construct()
|
7 |
+
{
|
8 |
+
$this->name = 'qtranslate_wysiwyg';
|
9 |
+
$this->label = __("Wysiwyg Editor",'acf');
|
10 |
+
$this->category = __("qTranslate",'acf');
|
11 |
+
|
12 |
+
acf_field::__construct();
|
13 |
+
|
14 |
+
add_filter('acf/fields/wysiwyg/toolbars', array($this, 'toolbars'), 1, 1);
|
15 |
+
}
|
16 |
+
|
17 |
+
|
18 |
+
function toolbars($toolbars)
|
19 |
+
{
|
20 |
+
return acf_field_wysiwyg::toolbars($toolbars);
|
21 |
+
}
|
22 |
+
|
23 |
+
|
24 |
+
function create_field($field)
|
25 |
+
{
|
26 |
+
if (!acf_qtranslate_enabled()) {
|
27 |
+
acf_field_wysiwyg::create_field($field);
|
28 |
+
return;
|
29 |
+
}
|
30 |
+
|
31 |
+
$defaults = array(
|
32 |
+
'toolbar' => 'full',
|
33 |
+
'media_upload' => 'yes',
|
34 |
+
);
|
35 |
+
$field = array_merge($defaults, $field);
|
36 |
+
|
37 |
+
|
38 |
+
global $q_config, $wp_version;
|
39 |
+
$languages = qtrans_getSortedLanguages(true);
|
40 |
+
$values = qtrans_split($field['value'], $quicktags = true);
|
41 |
+
|
42 |
+
echo '<div class="multi-language-field multi-language-field-wysiwyg">';
|
43 |
+
|
44 |
+
foreach ($languages as $language) {
|
45 |
+
$class = ($language === end($languages)) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
|
46 |
+
echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
|
47 |
+
}
|
48 |
+
|
49 |
+
foreach ($languages as $language):
|
50 |
+
$value = $values[$language];
|
51 |
+
$id = 'wysiwyg' . $field['id'] . "[$language]";
|
52 |
+
$name = $field['name'] . "[$language]";
|
53 |
+
$class = ($language === end($languages)) ? 'acf_wysiwyg wp-editor-wrap current-language' : 'acf_wysiwyg wp-editor-wrap';
|
54 |
+
|
55 |
+
?>
|
56 |
+
<div id="wp-<?php echo $id; ?>-wrap" class="<?php echo $class; ?>" data-toolbar="<?php echo $field['toolbar']; ?>" data-upload="<?php echo $field['media_upload']; ?>" data-language="<?php echo $language; ?>">
|
57 |
+
<?php if($field['media_upload'] == 'yes'): ?>
|
58 |
+
<?php if( version_compare($wp_version, '3.3', '<') ): ?>
|
59 |
+
<div id="editor-toolbar">
|
60 |
+
<div id="media-buttons" class="hide-if-no-js">
|
61 |
+
<?php do_action( 'media_buttons' ); ?>
|
62 |
+
</div>
|
63 |
+
</div>
|
64 |
+
<?php else: ?>
|
65 |
+
<div id="wp-<?php echo $id; ?>-editor-tools" class="wp-editor-tools">
|
66 |
+
<div id="wp-<?php echo $id; ?>-media-buttons" class="hide-if-no-js wp-media-buttons">
|
67 |
+
<?php do_action( 'media_buttons' ); ?>
|
68 |
+
</div>
|
69 |
+
</div>
|
70 |
+
<?php endif; ?>
|
71 |
+
<?php endif; ?>
|
72 |
+
<div id="wp-<?php echo $id; ?>-editor-container" class="wp-editor-container">
|
73 |
+
<textarea id="<?php echo $id; ?>" class="wp-editor-area" name="<?php echo $name; ?>" ><?php echo wp_richedit_pre($value); ?></textarea>
|
74 |
+
</div>
|
75 |
+
</div>
|
76 |
+
<?php endforeach;
|
77 |
+
|
78 |
+
echo '</div>';
|
79 |
+
}
|
80 |
+
|
81 |
+
|
82 |
+
function format_value($value, $post_id, $field)
|
83 |
+
{
|
84 |
+
return $value;
|
85 |
+
}
|
86 |
+
|
87 |
+
|
88 |
+
function format_value_for_api($value, $post_id, $field) {
|
89 |
+
if (acf_qtranslate_enabled()) {
|
90 |
+
$value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
|
91 |
+
}
|
92 |
+
|
93 |
+
return acf_field_wysiwyg::format_value_for_api($value, $post_id, $field);
|
94 |
+
}
|
95 |
+
|
96 |
+
|
97 |
+
function update_value($value, $post_id, $field)
|
98 |
+
{
|
99 |
+
if (acf_qtranslate_enabled()) {
|
100 |
+
$value = qtrans_join($value);
|
101 |
+
}
|
102 |
+
|
103 |
+
return $value;
|
104 |
+
}
|
105 |
+
|
106 |
+
}
|
107 |
+
|
108 |
+
|
109 |
+
new acf_field_qtranslate_wysiwyg;
|
readme.txt
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== ACF qTranslate ===
|
2 |
+
Contributors: funkjedi
|
3 |
+
Tags: acf, advanced custom fields, qtranslate, add-on, admin
|
4 |
+
Requires at least: 3.0.0
|
5 |
+
Tested up to: 3.7.1
|
6 |
+
Version: 1.1
|
7 |
+
Stable tag: 1.1
|
8 |
+
License: GPLv2 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
|
11 |
+
Adds qTranslate compatible fields for Text, Text Area, Wysiwyg Editor and Image.
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
**Requires the following plugins**
|
16 |
+
* [Advanced Custom Fields](http://wordpress.org/extend/plugins/advanced-custom-fields/)
|
17 |
+
* [qTranslate](http://wordpress.org/plugins/qtranslate/)
|
18 |
+
|
19 |
+
This plugin adds a new Field Type category called qTranslate. This contains qTranslate compatible fields for Text, Text Area, Wysiwyg Editor and Image.
|
20 |
+
|
21 |
+
Usage:
|
22 |
+
|
23 |
+
* Install the plug-in (standard WordPress installation)
|
24 |
+
* Set up a qTranslate field (standard Advanced Custom Field configuration)
|
25 |
+
* Add or Edit a post and language tabs will show up above the qTranslate field
|
26 |
+
* Click a language tab above the qTranslate field to switch languages
|
27 |
+
|
28 |
+
Issues:
|
29 |
+
|
30 |
+
All bugs reports or feature requests should be made in the [Github repository](https://github.com/funkjedi/acf-qtranslate/issues)
|
31 |
+
|
32 |
+
== Installation ==
|
33 |
+
|
34 |
+
1. Be sure to have **Advanced Custom Fields** installed and activated first
|
35 |
+
2. Upload `acf-qtranslate` directory to the `/wp-content/plugins/` directory
|
36 |
+
3. Activate the plugin through the 'Plugins' menu in WordPress
|
37 |
+
|
38 |
+
== Frequently Asked Questions ==
|
39 |
+
|
40 |
+
= What's the history behind this plugin? =
|
41 |
+
|
42 |
+
The plugin is based on code samples posted to the [ACF support forums](http://old.support.advancedcustomfields.com/discussion/comment/20351#Comment_20351) by taeo.
|
43 |
+
|
44 |
+
== Screenshots ==
|
45 |
+
|
46 |
+
1. Shows the qTranslate Text and Image fields.
|
47 |
+
|
48 |
+
== Changelog ==
|
49 |
+
|
50 |
+
= 1.1 =
|
51 |
+
Added support for Image Fields. Thanks to bookwyrm for the contribution.
|
52 |
+
|
53 |
+
= 1.0 =
|
54 |
+
Initial Release. Thanks to taeo for the code samples this plugin was based on.
|