From 8019157dfbe73d2d8f3dfb322b49a22f176342c6 Mon Sep 17 00:00:00 2001 From: MatthewKosloski Date: Sun, 25 Jun 2017 22:56:43 -0500 Subject: [PATCH] added is_sortable arg to repeater blocks --- metabox_constructor_class.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/metabox_constructor_class.php b/metabox_constructor_class.php index 7ad2b5d..0d9cb61 100644 --- a/metabox_constructor_class.php +++ b/metabox_constructor_class.php @@ -258,7 +258,11 @@ public function addWysiwyg($args, $repeater = false) { } public function addRepeaterBlock($args) { - $field = array_merge(array('type' => 'repeater', 'single_label' => 'Item'), $args); + $field = array_merge(array( + 'type' => 'repeater', + 'single_label' => 'Item', + 'is_sortable' => true + ), $args); $this->_fields[] = $field; } @@ -385,6 +389,8 @@ public function get_repeated_block($field, $meta, $index, $isTemplate = false) { esc_attr( $this->get_block_element_class('repeated', false) ) ); + echo sprintf('%s %d', $field['single_label'], $index + 1); + foreach($field['fields'] as $child_field) { $old_id = $child_field['id']; @@ -410,13 +416,15 @@ public function get_repeated_block($field, $meta, $index, $isTemplate = false) { ); // "sort" button - echo sprintf( - ' - - ', - esc_attr( $this->get_block_element_class('repeater-button', false) ), - esc_attr( sprintf('js-%s-sort', self::BLOCK_NAMESPACE) ) - ); + if($field['is_sortable']) { + echo sprintf( + ' + + ', + esc_attr( $this->get_block_element_class('repeater-button', false) ), + esc_attr( sprintf('js-%s-sort', self::BLOCK_NAMESPACE) ) + ); + } echo ''; }