/** * Handle indexing the various date/time fields. * * This method also serves as an example of the 'facetwp_cmb2_default_index' filter, although it should be noted * that since it is part of the class, it does not use the $obj class object, but makes method calls directly. * For use outside of this class, be sure to use $obj->index_row() or $obj->index_multiple(). * * @since 1.0.0 * * @param bool $filter Continue with normal indexing. * @param CMB2_Field $field The field object. * @param array $defaults Array of default data. * * @return bool Whether to continue with the normal indexing. */ public function time_date_indexing($filter, $field, $defaults) { $date_format = 'Y-m-d'; $extended_format = "{$date_format} H:i:s"; $index = array('facet_display_value' => $field->args('name')); // Check for special field types if ('text_data' == $field->type()) { $index['facet_value'] = date($date_format, strtotime($field->value())); $this->index_row($index, $defaults); return false; } elseif ('text_date_timestamp' == $field->type()) { $index['facet_value'] = date($date_format, $field->value()); $this->index_row($index, $defaults); return false; } elseif ('text_datetime_timestamp' == $field->type()) { $index['facet_value'] = date($extended_format, $field->value()); $this->index_row($index, $defaults); return false; } elseif ('text_datetime_timestamp_timezone' == $field->type()) { $value = maybe_unserialize($field->value()); if ($value instanceof DateTime) { $index['facet_value'] = $value->format($extended_format); $this->index_row($index, $defaults); return false; } } return $filter; }
/** * Render a repeatable group */ public function render_group($args) { // If field is requesting to be conditionally shown if (isset($args['show_on_cb']) && is_callable($args['show_on_cb']) && !call_user_func($args['show_on_cb'], $this)) { return; } if (!isset($args['id'], $args['fields']) || !is_array($args['fields'])) { return; } $args['count'] = 0; $field_group = new CMB2_Field(array('field_args' => $args, 'object_type' => $this->object_type(), 'object_id' => $this->object_id())); $desc = $field_group->args('description'); $label = $field_group->args('name'); $sortable = $field_group->options('sortable') ? ' sortable' : ''; $group_val = (array) $field_group->value(); $nrows = count($group_val); $remove_disabled = $nrows <= 1 ? 'disabled="disabled" ' : ''; echo '<div class="cmb-row cmb-repeat-group-wrap"><div class="cmb-td"><div id="', $field_group->id(), '_repeat" class="cmb-nested cmb-field-list cmb-repeatable-group', $sortable, '" style="width:100%;">'; if ($desc || $label) { $class = $desc ? ' cmb-group-description' : ''; echo '<div class="cmb-row', $class, '"><div class="cmb-th">'; if ($label) { echo '<h2 class="cmb-group-name">', $label, '</h2>'; } if ($desc) { echo '<p class="cmb2-metabox-description">', $desc, '</p>'; } echo '</div></div>'; } if (!empty($group_val)) { foreach ($group_val as $iterator => $field_id) { $this->render_group_row($field_group, $remove_disabled); } } else { $this->render_group_row($field_group, $remove_disabled); } echo '<div class="cmb-row"><div class="cmb-td"><p class="cmb-add-row"><button data-selector="', $field_group->id(), '_repeat" data-grouptitle="', $field_group->options('group_title'), '" class="cmb-add-group-row button">', $field_group->options('add_button'), '</button></p></div></div>'; echo '</div></div></div>'; }
/** * Render a repeatable group */ public function render_group($args) { if (!isset($args['id'], $args['fields']) || !is_array($args['fields'])) { return; } $args['count'] = 0; $field_group = new CMB2_Field(array('field_args' => $args, 'object_type' => $this->object_type(), 'object_id' => $this->object_id())); $desc = $field_group->args('description'); $label = $field_group->args('name'); $sortable = $field_group->options('sortable') ? ' sortable' : ''; $group_val = (array) $field_group->value(); $nrows = count($group_val); $remove_disabled = $nrows <= 1 ? 'disabled="disabled" ' : ''; echo '<li class="cmb-row cmb-repeat-group-wrap"><div class="cmb-td"><ul id="', $field_group->id(), '_repeat" class="cmb-nested repeatable-group' . $sortable . '" style="width:100%;">'; if ($desc || $label) { $class = $desc ? ' cmb-group-description' : ''; echo '<li class="cmb-row' . $class . '"><div class="cmb-th">'; if ($label) { echo '<h2 class="cmb-group-name">' . $label . '</h2>'; } if ($desc) { echo '<p class="cmb2_metabox_description">' . $desc . '</p>'; } echo '</div></li>'; } if (!empty($group_val)) { foreach ($group_val as $iterator => $field_id) { $this->render_group_row($field_group, $remove_disabled); } } else { $this->render_group_row($field_group, $remove_disabled); } echo '<li class="cmb-row"><div class="cmb-td"><p class="add-row"><button data-selector="', $field_group->id(), '_repeat" data-grouptitle="', $field_group->options('group_title'), '" class="add-group-row button">' . $field_group->options('add_button') . '</button></p></div></li>'; echo '</ul></div></li>'; }