function mbdb_validate_book_fields($groupname, $fieldIDname, $fieldname, $message)
{
    do_action('mbdb_before_validate' . $groupname);
    $flag = false;
    foreach ($_POST[$groupname] as $key => $group) {
        // both fields must be filled in
        $is_field1 = mbdb_check_field($fieldIDname, $group) && $group[$fieldIDname] != '0';
        $is_field2 = mbdb_check_field($fieldname, $group);
        $flag = !($is_field1 && $is_field2);
        // if it's the last element and both sides of the check are empty, ignore the error
        // because CMB2 will automatically delete it from the repeater group
        $flag = mbdb_allow_blank_last_elements($is_field1, $is_field2, $groupname, $key, $flag);
        if ($flag) {
            break;
        }
    }
    do_action('mbdb_validate' . $groupname . '_before_msg', $flag, $group);
    mbdb_msg_if_invalid($flag, $groupname, $group, apply_filters('mbdb_validate' . $groupname . '_msg', $message));
    do_action('mbdb_validate' . $groupname . '_after_msg', $flag, $group);
}
function mbdb_output_editions($mbdb_editions, $attr)
{
    $output_html = '';
    $counter = 0;
    $default_language = mbdb_get_default_language();
    foreach ($mbdb_editions as $edition) {
        $is_isbn = mbdb_check_field('_mbdb_isbn', $edition);
        $is_height = mbdb_check_field('_mbdb_height', $edition);
        $is_width = mbdb_check_field('_mbdb_width', $edition);
        $is_pages = mbdb_check_field('_mbdb_length', $edition);
        $is_price = mbdb_check_field('_mbdb_retail_price', $edition);
        $is_language = mbdb_check_field('_mbdb_language', $edition);
        $is_title = mbdb_check_field('_mbdb_edition_title', $edition);
        $output_html .= '<span class="mbm-book-editions-format" id="mbm_book_editions_format_' . $counter . '" name="mbm_book_editions_format[' . $counter . ']">';
        if ($is_isbn || $is_pages || $is_height && $is_width) {
            $output_html .= '<a class="mbm-book-editions-toggle" id="mbm_book_editions_toggle_' . $counter . '" name="mbm_book_editions_toggle[' . $counter . ']"></a>';
        }
        $format_name = mbdb_get_format_name($edition['_mbdb_format']);
        $output_html .= '<span class="mbm-book-editions-format-name">' . $format_name . '</span>';
        if ($is_language && $edition['_mbdb_language'] != $default_language) {
            $output_html .= ' <span class="mbm-book-editions-language">(' . mbdb_get_language_name($edition['_mbdb_language']) . ')</span>';
        }
        if ($is_title) {
            $output_html .= ' - <span class="mbm-book-editions-title">' . $edition['_mbdb_edition_title'] . '</span>';
        }
        if ($is_price && $edition['_mbdb_retail_price'] != '0.00') {
            $output_html .= ': <span class="mbm-book-editions-srp"><span class="mbm-book-editions-currency">' . mbdb_get_currency_symbol($edition['_mbdb_currency']) . '</span><span class="mbm-book-editions-price">' . $edition['_mbdb_retail_price'] . '</span></span>';
        }
        if ($is_isbn || $is_height && $is_width || $is_pages) {
            $output_html .= '<div name="mbm_book_editions_subinfo[' . $counter . ']" id="mbm_book_editions_subinfo_' . $counter . '" class="mbm-book-editions-subinfo">';
            if ($is_isbn) {
                $output_html .= '<strong>' . __('ISBN', 'mooberry-book-manager') . ':</strong> <span class="mbm-book-editions-isbn">' . $edition['_mbdb_isbn'] . '</span><br>';
            }
            if ($is_height && $is_width) {
                $output_html .= '<strong>' . __('Size', 'mooberry-book-manager') . ':</strong> <span class="mbm-book-editions-size"><span class="mbm-book-editions-height">' . $edition['_mbdb_width'] . '</span>x<span class="mbm-book-editions-width">' . $edition['_mbdb_height'] . '</span> <span class="mbm-book-editions-unit">' . $edition['_mbdb_unit'] . '</span></span><br>';
            }
            if ($is_pages) {
                $output_html .= '<strong>' . __('Pages', 'mooberry-book-manager') . ':</strong> <span class="mbm-book-editions-length">' . $edition['_mbdb_length'] . '</span>';
            }
            $output_html .= '</div>';
        }
        $output_html .= '</span>';
        $counter++;
    }
    return apply_filters('mbdb_shortcode_editions', '<div class="mbm-book-editions"><span class="mbm-book-editions-label">' . esc_html($attr['label']) . '</span>' . $output_html . '<span class="mbm-book-editions-after">' . esc_html($attr['after']) . '</span></div>');
}