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

Commit

Permalink
Fixed ACF5 Image/File edit and delete buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
funkjedi committed Oct 26, 2016
1 parent e57fd8f commit 3c24c59
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 63 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.11
Version: 1.7.12
Author: funkjedi
Author URI: http://funkjedi.com
License: GPLv2 or later
Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: funkjedi
Tags: acf, advanced custom fields, qtranslate, add-on, admin
Requires at least: 3.5.0
Tested up to: 4.2.1
Version: 1.7.11
Stable tag: 1.7.11
Version: 1.7.12
Stable tag: 1.7.12
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

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

== Changelog ==

= 1.7.12 =
* Bug Fix: Fixed ACF5 Image/File edit and delete buttons

= 1.7.11 =
* Core: Enable support for ACF included within theme
* Bug Fix: Fixed do_action support when removing repeater rows
Expand Down
65 changes: 31 additions & 34 deletions src/acf_5/fields/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,35 @@ function __construct($plugin) {
*/
function render_field($field) {
global $q_config;

$languages = qtrans_getSortedLanguages(true);
$values = qtrans_split($field['value'], $quicktags = true);
$currentLanguage = $this->plugin->get_active_language();

// vars
$uploader = acf_get_setting('uploader');

// enqueue
acf_enqueue_uploader();
if( $uploader == 'wp' ) {
acf_enqueue_uploader();
}

// vars
$o = array(
'icon' => '',
'title' => '',
'size' => '',
'url' => '',
'name' => '',
'filesize' => '',
'filename' => '',
);

$div = array(
'class' => 'acf-file-uploader acf-cf',
'data-library' => $field['library'],
'data-mime_types' => $field['mime_types']
'data-mime_types' => $field['mime_types'],
'data-uploader' => $uploader
);

$input_atts = array(
'type' => 'hidden',
'name' => $field['name'],
'value' => $field['value'],
'data-name' => 'value-id'
);

$url = '';

echo '<div class="multi-language-field multi-language-field-image">';

foreach ($languages as $language) {
Expand All @@ -103,33 +101,32 @@ function render_field($field) {
echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
}

$field_name = $field['name'];

foreach ($languages as $language):

$input_atts['name'] = $field['name'] . '[' . $language . ']';
$field['name'] = $field_name . '[' . $language . ']';
$field['value'] = $values[$language];
$div['data-language'] = $language;
$div['class'] = 'acf-file-uploader acf-cf';

// has value?
if( $field['value'] && is_numeric($field['value']) ) {
if( $field['value'] ) {
$file = get_post( $field['value'] );
if( $file ) {
$div['class'] .= ' has-value';

$o['icon'] = wp_mime_type_icon( $file->ID );
$o['title'] = $file->post_title;
$o['size'] = @size_format(filesize( get_attached_file( $file->ID ) ));
$o['filesize'] = @size_format(filesize( get_attached_file( $file->ID ) ));
$o['url'] = wp_get_attachment_url( $file->ID );

$explode = explode('/', $o['url']);
$o['name'] = end( $explode );
$o['filename'] = end( $explode );
}
}

// basic?
$basic = !current_user_can('upload_files');
if ($basic) {
$div['class'] .= ' basic';
// url exists
if( $o['url'] ) {
$div['class'] .= ' has-value';
}
}

if ($language === $currentLanguage) {
Expand All @@ -139,7 +136,7 @@ function render_field($field) {
?>
<div <?php acf_esc_attr_e($div); ?>>
<div class="acf-hidden">
<?php acf_hidden_input(array( 'name' => $input_atts['name'], 'value' => $field['value'], 'data-name' => 'id' )); ?>
<?php acf_hidden_input(array( 'name' => $field['name'], 'value' => $field['value'], 'data-name' => 'id' )); ?>
</div>
<div class="show-if-value file-wrap acf-soh">
<div class="file-icon">
Expand All @@ -150,24 +147,24 @@ function render_field($field) {
<strong data-name="title"><?php echo $o['title']; ?></strong>
</p>
<p>
<strong><?php _e('File Name', 'acf'); ?>:</strong>
<a data-name="name" href="<?php echo $o['url']; ?>" target="_blank"><?php echo $o['name']; ?></a>
<strong><?php _e('File name', 'acf'); ?>:</strong>
<a data-name="filename" href="<?php echo $o['url']; ?>" target="_blank"><?php echo $o['filename']; ?></a>
</p>
<p>
<strong><?php _e('File Size', 'acf'); ?>:</strong>
<span data-name="size"><?php echo $o['size']; ?></span>
<strong><?php _e('File size', 'acf'); ?>:</strong>
<span data-name="filesize"><?php echo $o['filesize']; ?></span>
</p>

<ul class="acf-hl acf-soh-target">
<?php if( !$basic ): ?>
<li><a class="acf-icon dark" data-name="edit" href="#"><i class="acf-sprite-edit"></i></a></li>
<?php if( $uploader != 'basic' ): ?>
<li><a class="acf-icon -pencil dark" data-name="edit" href="#"></a></li>
<?php endif; ?>
<li><a class="acf-icon dark" data-name="remove" href="#"><i class="acf-sprite-delete"></i></a></li>
<li><a class="acf-icon -cancel dark" data-name="remove" href="#"></a></li>
</ul>
</div>
</div>
<div class="hide-if-value">
<?php if( $basic ): ?>
<?php if( $uploader == 'basic' ): ?>

<?php if( $field['value'] && !is_numeric($field['value']) ): ?>
<div class="acf-error-message"><p><?php echo $field['value']; ?></p></div>
Expand All @@ -177,7 +174,7 @@ function render_field($field) {

<?php else: ?>

<p style="margin:0;"><?php _e('No File selected','acf'); ?> <a data-name="add" class="acf-button" href="#"><?php _e('Add File','acf'); ?></a></p>
<p style="margin:0;"><?php _e('No file selected','acf'); ?> <a data-name="add" class="acf-button button" href="#"><?php _e('Add File','acf'); ?></a></p>

<?php endif; ?>

Expand Down
65 changes: 39 additions & 26 deletions src/acf_5/fields/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,34 @@ function __construct($plugin) {
*/
function render_field($field) {
global $q_config;

$languages = qtrans_getSortedLanguages(true);
$values = qtrans_split($field['value'], $quicktags = true);
$currentLanguage = $this->plugin->get_active_language();


// vars
$uploader = acf_get_setting('uploader');

// enqueue
acf_enqueue_uploader();
if( $uploader == 'wp' ) {
acf_enqueue_uploader();
}

// vars
$url = '';
$alt = '';
$div = array(
'class' => 'acf-image-uploader acf-cf',
'data-preview_size' => $field['preview_size'],
'data-library' => $field['library'],
'data-mime_types' => $field['mime_types']
'data-mime_types' => $field['mime_types'],
'data-uploader' => $uploader
);

$input_atts = array(
'type' => 'hidden',
'name' => $field['name'],
'value' => $field['value'],
'data-name' => 'value-id'
);
// get size of preview value
$size = acf_get_image_size($field['preview_size']);

$url = '';

echo '<div class="multi-language-field multi-language-field-image">';

Expand All @@ -101,25 +106,28 @@ function render_field($field) {
echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
}

$field_name = $field['name'];

foreach ($languages as $language):

$input_atts['name'] = $field['name'] . '[' . $language . ']';
$field['name'] = $field_name . '[' . $language . ']';
$field['value'] = $values[$language];
$div['data-language'] = $language;
$div['class'] = 'acf-image-uploader acf-cf';

// has value?
if( $field['value'] && is_numeric($field['value']) ) {
if( $field['value'] ) {
// update vars
$url = wp_get_attachment_image_src($field['value'], $field['preview_size']);
$url = $url[0];
$alt = get_post_meta($field['value'], '_wp_attachment_image_alt', true);

$div['class'] .= ' has-value';
}
// url exists
if( $url ) $url = $url[0];

// basic?
$basic = !current_user_can('upload_files');
if ($basic) {
$div['class'] .= ' basic';
// url exists
if( $url ) {
$div['class'] .= ' has-value';
}
}

if ($language === $currentLanguage) {
Expand All @@ -129,25 +137,30 @@ function render_field($field) {
?>
<div <?php acf_esc_attr_e( $div ); ?>>
<div class="acf-hidden">
<?php acf_hidden_input(array( 'name' => $input_atts['name'], 'value' => $field['value'], 'data-name' => 'id' )); ?>
<?php acf_hidden_input(array( 'name' => $field['name'], 'value' => $field['value'] )); ?>
</div>
<div class="view show-if-value acf-soh">
<img data-name="image" src="<?php echo $url; ?>" alt=""/>
<div class="view show-if-value acf-soh" <?php if( $size['width'] ) echo 'style="max-width: '.$size['width'].'px"'; ?>>
<img data-name="image" src="<?php echo $url; ?>" alt="<?php echo $alt; ?>"/>
<ul class="acf-hl acf-soh-target">
<?php if( !$basic ): ?>
<li><a class="acf-icon dark" data-name="edit" href="#"><i class="acf-sprite-edit"></i></a></li>
<?php if( $uploader != 'basic' ): ?>
<li><a class="acf-icon -pencil dark" data-name="edit" href="#" title="<?php _e('Edit', 'acf'); ?>"></a></li>
<?php endif; ?>
<li><a class="acf-icon dark" data-name="remove" href="#"><i class="acf-sprite-delete"></i></a></li>
<li><a class="acf-icon -cancel dark" data-name="remove" href="#" title="<?php _e('Remove', 'acf'); ?>"></a></li>
</ul>
</div>
<div class="view hide-if-value">
<?php if( $basic ): ?>
<?php if( $uploader == 'basic' ): ?>

<?php if( $field['value'] && !is_numeric($field['value']) ): ?>
<div class="acf-error-message"><p><?php echo $field['value']; ?></p></div>
<?php endif; ?>

<input type="file" name="<?php echo $field['name']; ?>" id="<?php echo $field['id']; ?>" />

<?php else: ?>
<p style="margin:0;"><?php _e('No image selected','acf'); ?> <a data-name="add" class="acf-button" href="#"><?php _e('Add Image','acf'); ?></a></p>

<p style="margin:0;"><?php _e('No image selected','acf'); ?> <a data-name="add" class="acf-button button" href="#"><?php _e('Add Image','acf'); ?></a></p>

<?php endif; ?>
</div>
</div>
Expand Down

0 comments on commit 3c24c59

Please sign in to comment.