cmb-field-gallery icon indicating copy to clipboard operation
cmb-field-gallery copied to clipboard

Add a clear gallery button

Open friiiick opened this issue 10 years ago • 4 comments

Hi mustardBees

Where I need to add a clear gallery button?

Thanks! Chris

friiiick avatar Apr 09 '14 11:04 friiiick

That's the one to-do item in the read me file!

A workaround for now would be to clear the hidden text field manually. It'd be possible to add another button to do this. However, before I go down this route I'm going to take a look and see if there is a smarter way to work with the media manager.

mustardBees avatar Apr 09 '14 13:04 mustardBees

Hi, when the gallery screen opens up, by default all of the images in the media library are automatically selected for the gallery. Then I have to go through and remove the images I dont want in the gallery. Is it supposed to work like this? thanks

jajouka79 avatar Jul 15 '14 21:07 jajouka79

Having the same problem as @jajouka79

JvanderHeide avatar Apr 18 '15 13:04 JvanderHeide

I was able to work around this issue by editing the following line in cmb-field-gallery.php:

echo '  <input type="hidden" id="' . $field->args( 'id' ) . '" name="' . $field->args( 'id' ) . '" value="' . $meta . '" />';

to:

// get the gallery images for the current post
$gallery_images = get_post_meta( get_the_ID(), 'WHATEVER_KEY_YOU_SETUP', true ); ?>
<?php if ( ! empty( $gallery_images )) { 
// if a gallery already exists for this post, then pass the image id's via hidden input
 echo ' <input type="hidden" id="' . $field->args( 'id' ) . '" name="' . $field->args( 'id' ) . '" value="' . $meta . '" />';
} else {
// if the gallery is empty, set the hidden input value to "0"
 echo ' <input type="hidden" id="' . $field->args( 'id' ) . '" name="' . $field->args( 'id' ) . '" value="0" />';
} 

Not necessarily the correct way to do it... but it works for me and will hopefully help someone else.

I'm still trying to find a way to make the gallery editor open directly to either the library or upload tab if the gallery is empty. If anyone has any input on how to accomplish that, please chime in.

Thank you @mustardBees for the great addition to CMB!

rmbaumer avatar Apr 30 '15 23:04 rmbaumer