function mbdb_book_metaboxes() { $mbdb_options = get_option('mbdb_options'); // SUMMARY $mbdb_summary_metabox = new_cmb2_box(array('id' => 'mbdb_summary_metabox', 'title' => __('Summary', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'normal', 'priority' => 'high', 'show_names' => false)); $mbdb_summary_metabox->add_field(array('name' => __('Summary', 'mooberry-book-manager'), 'id' => '_mbdb_summary', 'type' => 'wysiwyg', 'options' => array('wpautop' => true, 'media_buttons' => true, 'textarea_rows' => 10, 'tabindex' => '', 'editor_css' => '', 'editor_class' => '', 'teeny' => false, 'dfw' => false, 'tinymce' => true, 'quicktags' => true))); // EXCERPT $mbdb_excerpt_metabox = new_cmb2_box(array('id' => 'mbdb_excerpt_metabox', 'title' => __('Excerpt', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'normal', 'priority' => 'high', 'show_names' => false)); $mbdb_excerpt_metabox->add_field(array('name' => __('Excerpt', 'mooberry-book-manager'), 'id' => '_mbdb_excerpt', 'type' => 'wysiwyg', 'options' => array('wpautop' => true, 'media_buttons' => true, 'textarea_rows' => 15, 'tabindex' => '', 'editor_css' => '', 'editor_class' => '', 'teeny' => false, 'dfw' => false, 'tinymce' => true, 'quicktags' => true))); // REVIEWS $mbdb_reviews_metabox = new_cmb2_box(array('id' => 'mbdb_reviews_metabox', 'title' => _x('Reviews', 'noun: book reviews', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'normal', 'priority' => 'high', 'show_names' => true)); $mbdb_reviews_metabox->add_field(array('id' => '_mbdb_reviews', 'type' => 'group', 'description' => __('Add reviews of your book', 'mooberry-book-manager'), 'options' => array('group_title' => _x('Reviews', 'noun', 'mooberry-book-manager') . ' {#}', 'add_button' => __('Add Review', 'mooberry-book-manager'), 'remove_button' => __('Remove Review', 'mooberry-book-manager'), 'sortable' => true))); $mbdb_reviews_metabox->add_group_field('_mbdb_reviews', array('name' => __('Reviewer Name', 'mooberry-book-manager'), 'id' => 'mbdb_reviewer_name', 'type' => 'text_medium', 'sanitization_cb' => 'mbdb_validate_reviews')); $mbdb_reviews_metabox->add_group_field('_mbdb_reviews', array('name' => _x('Review Link', 'noun: URL to book review', 'mooberry-book-manager'), 'id' => 'mbdb_review_url', 'type' => 'text_url', 'desc' => 'http://www.someWebsite.com/', 'attributes' => array('pattern' => '^(https?:\\/\\/)?([\\da-zA-Z\\.-]+)\\.([a-zA-Z\\.]{2,6}).*'))); $mbdb_reviews_metabox->add_group_field('_mbdb_reviews', array('name' => _x('Review Website Name', 'noun: name of website of book review', 'mooberry-book-manager'), 'id' => 'mbdb_review_website', 'type' => 'text_medium')); $mbdb_reviews_metabox->add_group_field('_mbdb_reviews', array('name' => _x('Review', 'noun: book review', 'mooberry-book-manager'), 'id' => 'mbdb_review', 'type' => 'textarea')); // EDITIONS $mbdb_editions_metabox = new_cmb2_box(array('id' => 'mbdb_editions_metabox', 'title' => __('Formats and Editions', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'normal', 'priority' => 'high', 'show_names' => true)); $mbdb_editions_metabox->add_field(array('id' => '_mbdb_editions', 'type' => 'group', 'description' => __("List the details of your book's hardcover, paperback, and e-book editions. Everything is optional except the format.", 'mooberry-book-manager'), 'options' => array('group_title' => __('Edition', 'mooberry-book-manager') . ' {#}', 'add_button' => __('Add New Edition', 'mooberry-book-manager'), 'remove_button' => __('Remove Edition', 'mooberry-book-manager'), 'sortable' => true))); $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => _x('Format', 'noun: format of a book', 'mooberry-book-manager'), 'id' => '_mbdb_format', 'type' => 'select', 'sanitization_cb' => 'mbdb_validate_editions', 'options' => mbdb_get_editions(), 'description' => __('Add more formats in Settings', 'mooberry-book-manager'))); $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('EAN/ISBN', 'mooberry-book-manager'), 'id' => '_mbdb_isbn', 'type' => 'text_medium')); $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Language', 'mooberry-book-manager'), 'id' => '_mbdb_language', 'type' => 'select', 'options' => mbdb_get_language_array(), 'default' => mbdb_get_default_language($mbdb_options))); $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Number of Pages', 'mooberry-book-manager'), 'id' => '_mbdb_length', 'type' => 'text_small', 'attributes' => array('type' => 'number', 'pattern' => '\\d*', 'min' => 1))); $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Height', 'mooberry-book-manager'), 'id' => '_mbdb_height', 'type' => 'text_small', 'attributes' => array('type' => 'number', 'step' => 'any', 'min' => 0))); $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Width', 'mooberry-book-manager'), 'id' => '_mbdb_width', 'type' => 'text_small', 'attributes' => array('type' => 'number', 'step' => 'any', 'min' => 0))); $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => _x('Unit', 'units of measurement', 'mooberry-book-manager'), 'id' => '_mbdb_unit', 'type' => 'select', 'options' => mbdb_get_units_array(), 'default' => mbdb_get_default_unit($mbdb_options))); $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Suggested Retail Price', 'mooberry-book-manager'), 'id' => '_mbdb_retail_price', 'type' => 'text_small', 'attributes' => array('pattern' => '^\\d*([.,]\\d{2}$)?', 'min' => 0))); $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Currency', 'mooberry-book-manager'), 'id' => '_mbdb_currency', 'type' => 'select', 'options' => mbdb_get_currency_array(), 'default' => mbdb_get_default_currency($mbdb_options))); $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Edition Title', 'mooberry-book-manager'), 'id' => '_mbdb_edition_title', 'type' => 'text_medium', 'desc' => __('First Edition, Second Edition, etc.', 'mooberry-book-mananger'))); // ADDITIONAL INFORMATION $mbdb_additional_info_metabox = new_cmb2_box(array('id' => 'mbdb_additional_info_metabox', 'title' => __('Additional Information', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'normal', 'priority' => 'high', 'show_names' => false)); $mbdb_additional_info_metabox->add_field(array('name' => __('Additional Information', 'mooberry-book-manager'), 'id' => '_mbdb_additional_info', 'type' => 'wysiwyg', 'description' => __('Any additional information you want to display on the page. Will be shown at the bottom of the page, after the reviews.', 'mooberry-book-manager'), 'options' => array('wpautop' => true, 'media_buttons' => true, 'textarea_rows' => 15, 'tabindex' => '', 'editor_css' => '', 'editor_class' => '', 'teeny' => false, 'dfw' => false, 'tinymce' => true, 'quicktags' => true))); // COVER $mbdb_cover_image_metabox = new_cmb2_box(array('id' => 'mbdb_cover_image_metabox', 'title' => _x('Cover', 'noun', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'side', 'priority' => 'default', 'show_names' => false, 'allow' => array('attachment'))); $mbdb_cover_image_metabox->add_field(array('name' => _x('Book Cover', 'noun', 'mooberry-book-manager'), 'id' => '_mbdb_cover', 'type' => 'file', 'allow' => array('attachment'))); // BOOK INFO $mbdb_bookinfo_metabox = new_cmb2_box(array('id' => 'mbdb_bookinfo_metabox', 'title' => __('Book Details', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'side', 'priority' => 'default', 'show_names' => true)); $mbdb_bookinfo_metabox->add_field(array('name' => __('Subtitle', 'mooberry-book-manager'), 'id' => '_mbdb_subtitle', 'type' => 'text_small')); $mbdb_bookinfo_metabox->add_field(array('name' => __('Release Date', 'mooberry-book-manager'), 'id' => '_mbdb_published', 'type' => 'text_date', 'desc' => 'yyyy/mm/dd', 'date_format' => 'Y/m/d', 'sanitization_cb' => 'mbdb_format_date')); $mbdb_bookinfo_metabox->add_field(array('name' => __('Publisher', 'mooberry-book-manager'), 'id' => '_mbdb_publisherID', 'type' => 'select', 'options' => mbdb_get_publishers(), 'desc' => __('Set up Publishers in Settings.', 'mooberry-book-manager'))); $mbdb_bookinfo_metabox->add_field(array('name' => __('Goodreads Link', 'mooberry-book-manager'), 'id' => '_mbdb_goodreads', 'type' => 'text_url', 'desc' => 'http://www.goodreads.com/your/Unique/Text/', 'attributes' => array('pattern' => '^(https?:\\/\\/)?www.goodreads.com.*'))); $mbdb_bookinfo_metabox->add_field(array('name' => __('Series Order', 'mooberry-book-manager'), 'id' => '_mbdb_series_order', 'desc' => __('(leave blank if not part of a series)', 'mooberry-book-manager'), 'type' => 'text_small', 'attributes' => array('type' => 'number', 'step' => 'any', 'min' => 0))); // BUYLINKS $mbdb_buylinks_metabox = new_cmb2_box(array('id' => 'mbdb_buylinks_metabox', 'title' => _x('Retailer Links', 'noun: URLs to book retailers', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'side', 'priority' => 'default', 'show_names' => true)); $mbdb_buylinks_metabox->add_field(array('id' => '_mbdb_buylinks', 'type' => 'group', 'description' => __('Add links where readers can purchase your book', 'mooberry-book-manager'), 'options' => array('group_title' => _x('Retailer Link', 'noun', 'mooberry-book-manager') . ' {#}', 'add_button' => __('Add Retailer Link', 'mooberry-book-manager'), 'remove_button' => __('Remove Retailer Link', 'mooberry-book-manager'), 'sortable' => true))); $mbdb_buylinks_metabox->add_group_field('_mbdb_buylinks', array('name' => __('Retailer', 'mooberry-book-manager'), 'id' => '_mbdb_retailerID', 'type' => 'select', 'options' => mbdb_get_retailers(), 'sanitization_cb' => 'mbdb_validate_retailers', 'description' => __('Add more retailers in Settings', 'mooberry-book-manager'))); $mbdb_buylinks_metabox->add_group_field('_mbdb_buylinks', array('name' => _x('Link', 'noun: URL', 'mooberry-book-manager'), 'id' => '_mbdb_buylink', 'type' => 'text_url', 'desc' => 'http://www.someWebsite.com/', 'attributes' => array('pattern' => mbdb_url_validation_pattern()))); // DOWNLOAD LINKS $mbdb_downloadlinks_metabox = new_cmb2_box(array('id' => 'mbdb_downloadlinks_metabox', 'title' => _x('Download Links', 'noun', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'side', 'priority' => 'low', 'show_names' => true)); $mbdb_downloadlinks_metabox->add_field(array('id' => '_mbdb_downloadlinks', 'type' => 'group', 'description' => __('If your book is available to download for free, add the links for each format.', 'mooberry-book-manager'), 'options' => array('group_title' => _x('Download Link', 'noun', 'mooberry-book-manager') . ' {#}', 'add_button' => __('Add Download Link', 'mooberry-book-manager'), 'remove_button' => __('Remove Download Link', 'mooberry-book-manager'), 'sortable' => true))); $mbdb_downloadlinks_metabox->add_group_field('_mbdb_downloadlinks', array('name' => _x('Format', 'noun', 'mooberry-book-manager'), 'id' => '_mbdb_formatID', 'type' => 'select', 'options' => mbdb_get_formats(), 'sanitization_cb' => 'mbdb_validate_downloadlinks', 'description' => __('Add more formats in Settings', 'mooberry-book-manager'))); $mbdb_downloadlinks_metabox->add_group_field('_mbdb_downloadlinks', array('name' => _x('Link', 'noun', 'mooberry-book-manager'), 'id' => '_mbdb_downloadlink', 'type' => 'text_url', 'attributes' => array('pattern' => mbdb_url_validation_pattern()))); $mbdb_summary_metabox = apply_filters('mbdb_summary_metabox', $mbdb_summary_metabox); $mbdb_editions_metabox = apply_filters('mbdb_editions_metabox', $mbdb_editions_metabox); $mbdb_excerpt_metabox = apply_filters('mbdb_excerpt_metabox', $mbdb_excerpt_metabox); $mbdb_reviews_metabox = apply_filters('mbdb_reviews_metabox', $mbdb_reviews_metabox); $mbdb_additional_info_metabox = apply_filters('mbdb_additional_info_metabox', $mbdb_additional_info_metabox); $mbdb_cover_image_metabox = apply_filters('mbdb_cover_image_metabox', $mbdb_cover_image_metabox); $mbdb_bookinfo_metabox = apply_filters('mbdb_bookinfo_metabox', $mbdb_bookinfo_metabox); $mbdb_buylinks_metabox = apply_filters('mbdb_buylinks_metabox', $mbdb_buylinks_metabox); $mbdb_downloadlinks_metabox = apply_filters('mbdb_downloadlinks_metabox', $mbdb_downloadlinks_metabox); }
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>'); }