Viewing 4 reply threads
  • Author
    Posts
    • #2964
      drblue
      Member

      Hi guys, tried searching for this issue both now and a while back but haven’t encountered anyone having posted about this problem.

      Thing is, I have a meta box on a custom post type where the user can upload several attachments (see screenshot). But, when I try to remove either one of them (or both), they just re-appear once I press Update.

      Did some debugging and the click on remove only removes the ui-sortable item, it doesn’t clear/remove the hidden input-field which piklist uses then saving and then are using as the base for building the ui-sortable list in the meta box.

      Seems odd that someone else wouldn’t have encountered this before, which makes me questioning if I implemented it wrongly?

      Here’s an extract from my metabox-code (disregard the validation-rule, doesn’t seem to work either):

      piklist('field', array(
      	'type' => 'file'
      	,'field' => 'noas_product_attachments'
      	//,'scope' => 'post_meta'
      	,'label' => 'Attachment'
      	,'options' => array(
      		'modal_title' => __('Add','noas')
      		,'button' => __('Add','noas')
      	)
      	,'validate' => array(
      		array(
      			'type' => 'limit'
      			,'options' => array(
      				'min' => 0
      				,'max' => 2
      			)
      		)
      	)
      ));
      Attachments:
      You must be logged in to view attached files.
    • #2966
      drblue
      Member

      Ok so after some more digging we found that it only affects non-images and that the problem lies within parts/fields/file.php.

      When building up the ui-sortable list the data-attachments attribute gets a two-dimensional array if it’s an image, otherwise a one-dimension array.

      The bug occurs because the same check isn’t done when building up the hidden input field – here piklist_form::get_field_name($field, $scope, $index, $prefix, $multiple) is always called whereas when building the ui-sortable the $multiple variable is only set if the attachments mime-type is jpeg/png/gif.

      Here’s a patch:

      --- parts/fields/file.php	2014-12-05 14:15:23.000000000 +0100
      +++ /Users/jn/src/web/noas/httpdocs/wp-content/plugins/piklist/parts/fields/file.php	2014-12-05 14:16:22.000000000 +0100
      @@ -43,7 +43,7 @@
                 <input 
                   type="hidden" 
                   id="<?php echo piklist_form::get_field_id($field, $scope, $_index, $prefix); ?>" 
      -            name="<?php echo piklist_form::get_field_name($field, $scope, $index, $prefix, $multiple); ?>"
      +            name="<?php echo piklist_form::get_field_name($field, $scope, $index, $prefix, (in_array(get_post_mime_type($value), array('image/jpeg', 'image/png', 'image/gif')) )); ?>"
                   value="<?php echo esc_attr($value[$_index]); ?>" 
                   <?php echo piklist_form::attributes_to_string($attributes); ?>
                 />
    • #2967
      jcrist
      Member

      I and some others were having this issue as well — https://piklist.com/support/topic/cant-remove-file-with-the-file-field/

      Great to see a patch, hope to see it in the next update!

    • #2981
      Steve
      Keymaster

      This is fixed in v0.9.4.23… available now at WordPress.org. Let us know if you still have issues.

    • #2985
      kattagami
      Member

      Very, very cool !
      Thanks all of you 🙂

Viewing 4 reply threads
  • The topic ‘Removing attachment causes it to jump right back after update’ is closed to new replies.