/** * Main callback function of add_meta_box * * @param object $post * @param object $data * @return mixed * * @author Gijs Jorissen * @since 0.2 * */ function callback($post, $data) { // Nonce field for validation wp_nonce_field(plugin_basename(__FILE__), 'cuztom_nonce'); // Get all inputs from $data $meta_data = $this->meta_data; // Check the array and loop through it if (!empty($meta_data)) { // Hidden field, so cuztom is always set echo '<input type="hidden" name="cuztom[__activate]" />'; if (isset($meta_data[0]) && !is_array($meta_data[0]) && ($meta_data[0] == 'tabs' || $meta_data[0] == 'accordion')) { $tabs = array_slice($meta_data, 1); // If it's about tabs or accordion echo '<div class="cuztom_helper">'; echo '<div class="' . ($meta_data[0] == 'tabs' ? 'cuztom_tabs' : 'cuztom_accordion') . '">'; // Show tabs if ($meta_data[0] == 'tabs') { echo '<ul>'; foreach ($tabs as $tab => $fields) { $tab_id = Cuztom::uglify($tab); echo '<li><a href="#' . $tab_id . '">' . Cuztom::beautify($tab) . '</a></li>'; } echo '</ul>'; } /* Loop through $meta_data, tabs in this case */ foreach ($tabs as $tab => $fields) { $tab_id = Cuztom::uglify($tab); // Show header if accordion if ($meta_data[0] == 'accordion') { echo '<h3>' . Cuztom::beautify($title) . '</h3>'; } echo '<div id="' . $tab_id . '">'; echo '<table border="0" cellading="0" cellspacing="0" class="cuztom_table cuztom_helper_table">'; foreach ($fields as $field_id_name => $field) { $meta = get_post_meta($post->ID, $field_id_name, true); if ($field['type'] != 'hidden') { echo '<tr>'; echo '<th class="cuztom_th th">'; echo '<label for="' . $field_id_name . '" class="cuztom_label">' . $field['label'] . '</label>'; echo '<div class="cuztom_description description">' . $field['description'] . '</div>'; echo '</th>'; echo '<td class="cuztom_td td">'; if ($field['repeatable'] && Cuztom_Field::_supports_repeatable($field)) { echo '<div class="cuztom_padding_wrap">'; echo '<a class="button-secondary cuztom_add cuztom_button" href="#">'; echo '+ ' . __('Add', CUZTOM_TEXTDOMAIN) . '</a>'; echo '<ul class="cuztom_repeatable_wrap">'; } cuztom_field($field_id_name, $field, $meta); if ($field['repeatable'] && Cuztom_Field::_supports_repeatable($field)) { echo '</ul></div>'; } echo '</td>'; echo '</tr>'; } else { cuztom_field($field_id_name, $field, $meta); } } echo '</table>'; echo '</div>'; } echo '</div>'; echo '</div>'; } else { echo '<div class="cuztom_helper">'; echo '<table border="0" cellading="0" cellspacing="0" class="cuztom_table cuztom_helper_table">'; /* Loop through $meta_data */ foreach ($meta_data as $field_id_name => $field) { $meta = get_post_meta($post->ID, $field_id_name, true) ? get_post_meta($post->ID, $field_id_name, true) : false; if ($field['type'] != 'hidden') { echo '<tr>'; echo '<th class="cuztom_th th">'; echo '<label for="' . $field_id_name . '" class="cuztom_label">' . $field['label'] . '</label>'; echo '<div class="cuztom_description description">' . $field['description'] . '</div>'; echo '</th>'; echo '<td class="cuztom_td td">'; if ($field['repeatable'] && Cuztom_Field::_supports_repeatable($field)) { echo '<div class="cuztom_padding_wrap">'; echo '<a class="button-secondary cuztom_add cuztom_button" href="#">'; echo '+ ' . __('Add', CUZTOM_TEXTDOMAIN) . '</a>'; echo '<ul class="cuztom_repeatable_wrap">'; } cuztom_field($field_id_name, $field, $meta); if ($field['repeatable'] && Cuztom_Field::_supports_repeatable($field)) { echo '</ul></div>'; } echo '</td>'; echo '</tr>'; } else { cuztom_field($field_id_name, $field, $meta); } } echo '</table>'; echo '</div>'; } } }
function _cuztom_field_supports_repeatable($field) { return Cuztom_Field::_supports_repeatable($field); }
/** * Used to add the column content to the column head * * @param string $column * @param int $post_id * @return mixed * * @author Gijs Jorissen * @since 1.1 * */ function add_column_content($column, $post_id) { $meta = get_post_meta($post_id, $column, true); if (isset($this->meta_data[0]) && !is_array($this->meta_data[0]) && ($this->meta_data[0] == 'tabs' || $this->meta_data[0] == 'accordion')) { $tabs = array_slice($this->meta_data, 1); foreach ($tabs as $tab => $fields) { foreach ($fields as $field_id_name => $field) { if ($column == $field_id_name) { echo $field['repeatable'] && Cuztom_Field::_supports_repeatable($field) ? implode($meta, ', ') : get_post_meta($post_id, $column, true); break; } } } } else { $field = isset($this->meta_data[$column]) ? $this->meta_data[$column] : null; echo $field['repeatable'] && Cuztom_Field::_supports_repeatable($field) ? implode($meta, ', ') : get_post_meta($post_id, $column, true); } }