Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
Fixed issue with saving File and Image fields
Browse files Browse the repository at this point in the history
  • Loading branch information
funkjedi committed Jan 29, 2017
1 parent cd08b31 commit 67f4dec
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 19 deletions.
2 changes: 1 addition & 1 deletion acf-qtranslate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Advanced Custom Fields: qTranslate
Plugin URI: http://github.com/funkjedi/acf-qtranslate
Description: Provides multilingual versions of the text, text area, and wysiwyg fields.
Version: 1.7.18
Version: 1.7.19
Author: funkjedi
Author URI: http://funkjedi.com
License: GPLv2 or later
Expand Down
1 change: 1 addition & 0 deletions assets/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jQuery(function($) {
parent.find('.current-language').removeClass('current-language');
parent.find('[data-language="' + language + '"]').addClass('current-language');
parent.find('input[data-language="' + language + '"], textarea[data-language="' + language + '"]').focus();
$('.qtranxs-lang-switch[lang="' + language + '"]:first').trigger('click');
});

/**
Expand Down
15 changes: 7 additions & 8 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Contributors: funkjedi
Tags: acf, advanced custom fields, qtranslate, add-on, admin
Requires at least: 3.5.0
Tested up to: 4.6.1
Version: 1.7.18
Stable tag: 1.7.18
Tested up to: 4.7.2
Version: 1.7.19
Stable tag: 1.7.19
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -54,6 +54,9 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac

== Changelog ==

= 1.7.19 =
* Bug Fix: Fixed issue with saving File and Image fields after ACF 5.5.5 upgrade

= 1.7.18 =
* Core: Prevent error on older versions of ACF5
* Bug Fix: Updated ACF5 qTranslate File field to match recent ACF update
Expand Down Expand Up @@ -167,8 +170,4 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac

== Upgrade Notice ==

= 1.7.7 =
If using qTranslate-X translation of the standard Text, Text Area and WYSIWYG field types is now disabled by default.

= 1.7.3 =
Removed namespaces to make code compatible with PHP 5.2
Bug Fix: Fixed issue with saving File and Image fields after ACF 5.5.5 upgrade
10 changes: 5 additions & 5 deletions src/acf_5/acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public function include_fields() {
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/textarea.php';
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/wysiwyg.php';

new acf_qtranslate_acf_5_text($this->plugin);
new acf_qtranslate_acf_5_textarea($this->plugin);
new acf_qtranslate_acf_5_wysiwyg($this->plugin);
new acf_qtranslate_acf_5_image($this->plugin);
new acf_qtranslate_acf_5_file($this->plugin);
acf()->fields->register_field_type(new acf_qtranslate_acf_5_text($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_textarea($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_wysiwyg($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_image($this->plugin));
acf()->fields->register_field_type(new acf_qtranslate_acf_5_file($this->plugin));
}

/**
Expand Down
19 changes: 16 additions & 3 deletions src/acf_5/fields/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,22 @@ function render_field($field) {
*
* @return $value - the modified value
*/
function update_value($value, $post_id, $field) {
$value = parent::update_value($value, $post_id, $field);
return qtrans_join($value);
function update_value($values, $post_id, $field) {

// validate
if ( !is_array($values) ) return false;

foreach ($values as $value) {

// bail early if not attachment ID
if( !$value || !is_numeric($value) ) continue;

// maybe connect attacments to post
acf_connect_attachment_to_post( (int) $value, $post_id );

}

return qtrans_join($values);
}

}
19 changes: 17 additions & 2 deletions src/acf_5/fields/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,23 @@ function render_field($field) {
* @return $value - the modified value
*/
function update_value($value, $post_id, $field) {
$value = parent::update_value($value, $post_id, $field);
return qtrans_join($value);
return acf_get_field_type('qtranslate_file')->update_value( $value, $post_id, $field );
}

/*
* validate_value
*
* This function will validate a basic file input
*
* @type function
* @date 11/02/2014
* @since 5.0.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function validate_value( $valid, $value, $field, $input ){
return acf_get_field_type('qtranslate_file')->validate_value( $valid, $value, $field, $input );
}

}

0 comments on commit 67f4dec

Please sign in to comment.