/**
 * Register custom meta boxes used throughout BadgeOS
 *
 * @since  1.0.0
 * @param  array  $meta_boxes The existing metabox array we're filtering
 * @return array              An updated array containing our new metaboxes
 */
function badgeos_custom_metaboxes(array $meta_boxes)
{
    // Start with an underscore to hide fields from custom fields list
    $prefix = '_badgeos_';
    // Grab our achievement types as an array
    $achievement_types = badgeos_get_achievement_types_slugs();
    // Setup our $post_id, if available
    $post_id = isset($_GET['post']) ? $_GET['post'] : 0;
    // New Achievement Types
    $meta_boxes[] = array('id' => 'achievement_type_data', 'title' => __('Achievement Type Data', 'badgeos'), 'pages' => array('achievement-type'), 'context' => 'normal', 'priority' => 'high', 'show_names' => true, 'fields' => array(array('name' => __('Plural Name', 'badgeos'), 'desc' => __('The plural name for this achievement (Title is singular name).', 'badgeos'), 'id' => $prefix . 'plural_name', 'type' => 'text_medium'), array('name' => __('Show in Menu?', 'badgeos'), 'desc' => ' ' . __('Yes, show this achievement in the BadgeOS menu.', 'badgeos'), 'id' => $prefix . 'show_in_menu', 'type' => 'checkbox'), array('name' => __('Default Badge Image', 'badgeos'), 'desc' => sprintf(__('To set a default image, use the <strong>Default Achievement Image</strong> metabox to the right. For best results, use a square .png file with a transparent background, at least 200x200 pixels. Or, design a badge using the %1$s.', 'badgeos'), badgeos_get_badge_builder_link(array('link_text' => __('Credly Badge Builder', 'badgeos')))), 'id' => $prefix . 'upload_badge_image_achievement', 'type' => 'text_only')));
    // Achievements
    $meta_boxes[] = apply_filters('badgeos_achievement_data_meta_box', array('id' => 'achievement_data', 'title' => __('Achievement Data', 'badgeos'), 'pages' => $achievement_types, 'context' => 'advanced', 'priority' => 'high', 'show_names' => true, 'fields' => apply_filters('badgeos_achievement_data_meta_box_fields', array(array('name' => __('Upload Badge Image', 'badgeos'), 'desc' => sprintf(__('<p>To set an image use the <strong>Achievement Image</strong> metabox to the right. For best results, use a square .png file with a transparent background, at least 200x200 pixels. Or, design a badge using the %1$s.</p><p>If no image is specified, this achievement will default to the %2$s featured image.</p>', 'badgeos'), badgeos_get_badge_builder_link(array('link_text' => __('Credly Badge Builder', 'badgeos'))), '<a href="' . admin_url('edit.php?post_type=achievement-type') . '">' . __('Achievement Type\'s', 'badgeos') . '</a>'), 'id' => $prefix . 'upload_badge_image_achievement', 'type' => 'text_only'), array('name' => __('Points Awarded', 'badgeos'), 'desc' => ' ' . __('Points awarded for earning this achievement (optional). Leave empty if no points are awarded.', 'badgeos'), 'id' => $prefix . 'points', 'type' => 'text_small'), array('name' => __('Earned By:', 'badgeos'), 'desc' => __('How this achievement can be earned.', 'badgeos'), 'id' => $prefix . 'earned_by', 'type' => 'select', 'options' => apply_filters('badgeos_achievement_earned_by', array(array('name' => __('Completing Steps', 'badgeos'), 'value' => 'triggers'), array('name' => __('Minimum Number of Points', 'badgeos'), 'value' => 'points'), array('name' => __('Submission (Reviewed)', 'badgeos'), 'value' => 'submission'), array('name' => __('Submission (Auto-accepted)', 'badgeos'), 'value' => 'submission_auto'), array('name' => __('Nomination', 'badgeos'), 'value' => 'nomination'), array('name' => __('Admin-awarded Only', 'badgeos'), 'value' => 'admin')))), array('name' => __('Minimum Points Requried', 'badgeos'), 'desc' => ' ' . __('Fewest number of points required for earning this achievement.', 'badgeos'), 'id' => $prefix . 'points_required', 'type' => 'text_small'), array('name' => __('Sequential Steps', 'badgeos'), 'desc' => ' ' . __('Yes, steps must be completed in order.', 'badgeos'), 'id' => $prefix . 'sequential', 'type' => 'checkbox'), array('name' => __('Show Earners', 'badgeos'), 'desc' => ' ' . __('Yes, display a list of users who have earned this achievement.', 'badgeos'), 'id' => $prefix . 'show_earners', 'type' => 'checkbox'), array('name' => __('Congratulations Text', 'badgeos'), 'desc' => __('Displayed after achievement is earned. If sending to Credly, a great place for a testimonial for those who complete this achievement.', 'badgeos'), 'id' => $prefix . 'congratulations_text', 'type' => 'textarea'), array('name' => __('Maximum Earnings', 'badgeos'), 'desc' => ' ' . __('Number of times a user can earn this badge (set to 0 for no maximum).', 'badgeos'), 'id' => $prefix . 'maximum_earnings', 'type' => 'text_small', 'std' => '1'), array('name' => __('Hidden?', 'badgeos'), 'desc' => '', 'id' => $prefix . 'hidden', 'type' => 'select', 'options' => array(array('name' => __('Show to User', 'badgeos'), 'value' => 'show'), array('name' => __('Hidden to User', 'badgeos'), 'value' => 'hidden')))), $prefix, $achievement_types)), $achievement_types);
    // Submissions
    $meta_boxes[] = array('id' => 'submission_data', 'title' => __('Submission Status', 'badgeos'), 'pages' => array('submission'), 'context' => 'side', 'priority' => 'default', 'show_names' => true, 'fields' => array(array('name' => __('Current Status', 'badgeos'), 'desc' => ucfirst(get_post_meta($post_id, $prefix . 'submission_status', true)), 'id' => $prefix . 'submission_current', 'type' => 'text_only'), array('name' => __('Change Status', 'badgeos'), 'desc' => badgeos_render_feedback_buttons($post_id), 'id' => $prefix . 'submission_update', 'type' => 'text_only'), array('name' => __('Achievement ID to Award', 'badgeos'), 'desc' => '<a href="' . esc_url(admin_url('post.php?post=' . get_post_meta($post_id, '_badgeos_submission_achievement_id', true) . '&action=edit')) . '">' . __('View Achievement', 'badgeos') . '</a>', 'id' => $prefix . 'submission_achievement_id', 'type' => 'text_small')));
    // Nominations
    $meta_boxes[] = array('id' => 'nomination_data', 'title' => __('Nomination Data', 'badgeos'), 'pages' => array('nomination'), 'context' => 'side', 'priority' => 'default', 'show_names' => true, 'fields' => array(array('name' => __('Current Status', 'badgeos'), 'desc' => ucfirst(get_post_meta($post_id, $prefix . 'nomination_status', true)), 'id' => $prefix . 'nomination_current', 'type' => 'text_only'), array('name' => __('Change Status', 'badgeos'), 'desc' => badgeos_render_feedback_buttons($post_id), 'id' => $prefix . 'nomination_update', 'type' => 'text_only'), array('name' => __('Nominee', 'badgeos'), 'id' => $prefix . 'nomination_user_id', 'desc' => $post_id && get_post_type($post_id) == 'nomination' ? get_userdata(absint(get_post_meta($post_id, '_badgeos_nomination_user_id', true)))->display_name : '', 'type' => 'text_medium'), array('name' => __('Nominated By', 'badgeos'), 'id' => $prefix . 'nominating_user_id', 'desc' => $post_id && get_post_type($post_id) == 'nomination' ? get_userdata(absint(get_post_meta($post_id, '_badgeos_nominating_user_id', true)))->display_name : '', 'type' => 'text_medium'), array('name' => __('Achievement ID to Award', 'badgeos'), 'desc' => '<a href="' . esc_url(admin_url('post.php?post=' . get_post_meta($post_id, '_badgeos_nomination_achievement_id', true) . '&action=edit')) . '">' . __('View Achievement', 'badgeos') . '</a>', 'id' => $prefix . 'nomination_achievement_id', 'type' => 'text_small')));
    return $meta_boxes;
}
/**
 * Add Badge Builder link to Featured Image meta box for achievement posts.
 *
 * @since  1.3.0
 *
 * @param  string  $content Meta box content.
 * @param  integer $post_id Post ID.
 * @return string           Potentially updated content.
 */
function badgeos_badge_builder_filter_thumbnail_metabox($content, $post_id)
{
    // Only add a link to achievement and achievement-type posts
    if (badgeos_is_achievement($post_id) || 'achievement-type' == get_post_type($post_id)) {
        // If no thumbnail, output standard badge builder link
        if (!has_post_thumbnail($post_id)) {
            $content .= '<p>' . badgeos_get_badge_builder_link(array('post_id' => $post_id, 'link_text' => __('Use Credly Badge Builder', 'badgeos'))) . '</p>';
            // Otherwise, if thumbnail is a badge builder badge,`
            // output a "continue editing" link
        } else {
            $attachment_id = get_post_thumbnail_id($post_id);
            $continue = get_post_meta($attachment_id, '_credly_badge_meta', true);
            if ($continue) {
                $content .= '<p>' . badgeos_get_badge_builder_link(array('post_id' => $post_id, 'attachment_id' => $attachment_id, 'link_text' => __('Edit in Credly Badge Builder', 'badgeos'), 'continue' => $continue)) . '</p>';
            }
        }
    }
    // Return the meta box content
    return $content;
}