/** * Get an array of achievements * * @since 1.0.0 * @param array $args An array of our relevant arguments * @return array An array of the queried achievements */ function badgeos_get_achievements($args = array()) { // Setup our defaults $defaults = array('post_type' => badgeos_get_achievement_types_slugs(), 'suppress_filters' => false, 'achievement_relationsihp' => 'any'); $args = wp_parse_args($args, $defaults); // Hook join functions for joining to P2P table to retrieve the parent of an acheivement if (isset($args['parent_of'])) { add_filter('posts_join', 'badgeos_get_achievements_parents_join'); add_filter('posts_where', 'badgeos_get_achievements_parents_where', 10, 2); } // Hook join functions for joining to P2P table to retrieve the children of an acheivement if (isset($args['children_of'])) { add_filter('posts_join', 'badgeos_get_achievements_children_join', 10, 2); add_filter('posts_where', 'badgeos_get_achievements_children_where', 10, 2); add_filter('posts_orderby', 'badgeos_get_achievements_children_orderby'); } // Get our achievement posts $achievements = get_posts($args); // Remove all our filters remove_filter('posts_join', 'badgeos_get_achievements_parents_join'); remove_filter('posts_where', 'badgeos_get_achievements_parents_where'); remove_filter('posts_join', 'badgeos_get_achievements_children_join'); remove_filter('posts_where', 'badgeos_get_achievements_children_where'); remove_filter('posts_orderby', 'badgeos_get_achievements_children_orderby'); return $achievements; }
/** * Register [badgeos_achievements_list] shortcode. * * @since 1.4.0 */ function badgeos_register_achievements_list_shortcode() { // Setup a custom array of achievement types $achievement_types = array_diff(badgeos_get_achievement_types_slugs(), array('step')); array_unshift($achievement_types, 'all'); badgeos_register_shortcode(array('name' => __('Achievement List', 'badgeos'), 'description' => __('Output a list of achievements.', 'badgeos'), 'slug' => 'badgeos_achievements_list', 'output_callback' => 'badgeos_achievements_list_shortcode', 'attributes' => array('type' => array('name' => __('Achievement Type(s)', 'badgeos'), 'description' => __('Single, or comma-separated list of, achievement type(s) to display.', 'badgeos'), 'type' => 'text', 'values' => $achievement_types, 'default' => 'all'), 'limit' => array('name' => __('Limit', 'badgeos'), 'description' => __('Number of achievements to display.', 'badgeos'), 'type' => 'text', 'default' => 10), 'show_filter' => array('name' => __('Show Filter', 'badgeos'), 'description' => __('Display filter controls.', 'badgeos'), 'type' => 'select', 'values' => array('true' => __('True', 'badgeos'), 'false' => __('False', 'badgeos')), 'default' => 'true'), 'show_search' => array('name' => __('Show Search', 'badgeos'), 'description' => __('Display a search input.', 'badgeos'), 'type' => 'select', 'values' => array('true' => __('True', 'badgeos'), 'false' => __('False', 'badgeos')), 'default' => 'true'), 'orderby' => array('name' => __('Order By', 'badgeos'), 'description' => __('Parameter to use for sorting.', 'badgeos'), 'type' => 'select', 'values' => array('menu_order' => __('Menu Order', 'badgeos'), 'ID' => __('Achievement ID', 'badgeos'), 'title' => __('Achievement Title', 'badgeos'), 'date' => __('Published Date', 'badgeos'), 'modified' => __('Last Modified Date', 'badgeos'), 'author' => __('Achievement Author', 'badgeos'), 'rand' => __('Random', 'badgeos')), 'default' => 'menu_order'), 'order' => array('name' => __('Order', 'badgeos'), 'description' => __('Sort order.', 'badgeos'), 'type' => 'select', 'values' => array('ASC' => __('Ascending', 'badgeos'), 'DESC' => __('Descending', 'badgeos')), 'default' => 'ASC'), 'user_id' => array('name' => __('User ID', 'badgeos'), 'description' => __('Show only achievements earned by a specific user.', 'badgeos'), 'type' => 'text'), 'include' => array('name' => __('Include', 'badgeos'), 'description' => __('Comma-separated list of specific achievement IDs to include.', 'badgeos'), 'type' => 'text'), 'exclude' => array('name' => __('Exclude', 'badgeos'), 'description' => __('Comma-separated list of specific achievement IDs to exclude.', 'badgeos'), 'type' => 'text'), 'wpms' => array('name' => __('Include Multisite Achievements', 'badgeos'), 'description' => __('Show achievements from all network sites.', 'badgeos'), 'type' => 'select', 'values' => array('true' => __('True', 'badgeos'), 'false' => __('False', 'badgeos')), 'default' => 'false')))); }
/** * 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; }
/** * Load up our activity triggers so we can add actions to them * * @since 1.0.0 * @return void */ function badgeos_load_activity_triggers() { // Grab our activity triggers $activity_triggers = badgeos_get_activity_triggers(); // Loop through each achievement type and add triggers for unlocking them foreach (badgeos_get_achievement_types_slugs() as $achievement_type) { // Grab the post type object, and bail if it's not actually an object $post_type_object = get_post_type_object($achievement_type); if (!is_object($post_type_object)) { continue; } // Add trigger for unlocking ANY and ALL posts for each achievement type $activity_triggers['badgeos_unlock_' . $achievement_type] = sprintf(__('Unlocked a %s', 'badgeos'), $post_type_object->labels->singular_name); $activity_triggers['badgeos_unlock_all_' . $achievement_type] = sprintf(__('Unlocked all %s', 'badgeos'), $post_type_object->labels->name); } // Loop through each trigger and add our trigger event to the hook foreach ($activity_triggers as $trigger => $label) { add_action($trigger, 'badgeos_trigger_event', 10, 20); } }
/** * Preferences for BadgeOS * @since 1.0.8 * @version 1.0 */ public function preferences() { $prefs = $this->prefs; $badge_post_types = badgeos_get_achievement_types_slugs(); foreach ($badge_post_types as $post_type) { if (in_array($post_type, apply_filters('mycred_badgeos_excludes', array('step')))) { continue; } if (!isset($prefs[$post_type])) { $prefs[$post_type] = array('creds' => 10, 'log' => '', 'deduct' => 1, 'deduct_log' => '%plural% deduction'); } $post_type_object = get_post_type_object($post_type); $title = sprintf(__('Default %s for %s', 'mycred'), $this->core->plural(), $post_type_object->labels->singular_name); ?> <label for="<?php echo $this->field_id(array($post_type, 'creds')); ?> " class="subheader"><?php echo $title; ?> </label> <ol> <li> <div class="h2"><input type="text" name="<?php echo $this->field_name(array($post_type, 'creds')); ?> " id="<?php echo $this->field_id(array($post_type, 'creds')); ?> " value="<?php echo $this->core->number($prefs[$post_type]['creds']); ?> " size="8" /></div> <span class="description"><?php echo $this->core->template_tags_general(__('Use zero to disable users gaining %_plural%', 'mycred')); ?> </span> </li> <li class="empty"> </li> <li> <label for="<?php echo $this->field_id(array($post_type, 'log')); ?> "><?php _e('Default Log template', 'mycred'); ?> </label> <div class="h2"><input type="text" name="<?php echo $this->field_name(array($post_type, 'log')); ?> " id="<?php echo $this->field_id(array($post_type, 'log')); ?> " value="<?php echo esc_attr($prefs[$post_type]['log']); ?> " class="long" /></div> <span class="description"><?php echo $this->available_template_tags(array('general', 'post')); ?> </span> </li> <li> <input type="checkbox" name="<?php echo $this->field_name(array($post_type, 'deduct')); ?> " id="<?php echo $this->field_id(array($post_type, 'deduct')); ?> " <?php checked($prefs[$post_type]['deduct'], 1); ?> value="1" /> <label for="<?php echo $this->field_id(array($post_type, 'deduct')); ?> "><?php echo $this->core->template_tags_general(__('Deduct %_plural% if user looses ' . $post_type_object->labels->singular_name, 'mycred')); ?> </label> </li> <li class="empty"> </li> <li> <label for="<?php echo $this->field_id(array($post_type, 'deduct_log')); ?> "><?php _e('Log template', 'mycred'); ?> </label> <div class="h2"><input type="text" name="<?php echo $this->field_name(array($post_type, 'deduct_log')); ?> " id="<?php echo $this->field_id(array($post_type, 'deduct_log')); ?> " value="<?php echo esc_attr($prefs[$post_type]['deduct_log']); ?> " class="long" /></div> <span class="description"><?php echo $this->available_template_tags(array('general', 'post')); ?> </span> </li> </ol> <?php } }
public function achievements() { global $blog_id, $json_api; $type = badgeos_get_achievement_types_slugs(); // Drop steps from our list of "all" achievements $step_key = array_search('step', $type); if ($step_key) { unset($type[$step_key]); } $type[] = 'submission'; //$user_id = get_current_user_id(); // Get the current user if one wasn't specified if (!$user_id) { if ($json_api->query->user_id) { $user_id = $json_api->query->user_id; } else { return array("message" => "No user_id"); } } // Get submissions $args = array('post_type' => 'submission', 'posts_per_page' => -1, 'author' => $user_id, 'post_status' => 'publish', 'fields' => 'ids'); $sub_arg = $args; $submissions = get_posts($args); $hidden = badgeos_get_hidden_achievement_ids($type); // Initialize our output and counters $achievements = array(); $achievement_count = 0; // Grab our earned badges (used to filter the query) $earned_ids = badgeos_get_user_earned_achievement_ids($user_id, $type); $earned_ids = array_map('intval', $earned_ids); // Query Achievements $args = array('post_type' => $type, 'posts_per_page' => -1, 'post_status' => 'publish'); $args['post__in'] = array_merge(array(0), $earned_ids); $exclude = array(); // exclude badges which are submissions if (!empty($submissions)) { foreach ($submissions as $sub_id) { $exclude[] = absint(get_post_meta($sub_id, '_badgeos_submission_achievement_id', true)); $args['post__in'][] = $sub_id; } $args['post__in'] = array_diff($args['post__in'], $exclude); } // Loop Achievements $achievement_posts = new WP_Query($args); $query_count += $achievement_posts->found_posts; $base_url = site_url() . '/' . get_option('json_api_base', 'api') . '/badge/assertion/?uid='; $pushed_badges = ($pushed_items = get_user_meta(absint($user_id), '_badgeos_backpack_pushed')) ? (array) $pushed_items : array(); while ($achievement_posts->have_posts()) { $achievement_posts->the_post(); $achievement_id = get_the_ID(); if (!in_array($achievement_id, $hidden)) { $uid = $achievement_id . "-" . get_post_time('U', true) . "-" . $user_id; $button_text = !in_array($base_url . $uid, $pushed_badges) ? __('Send to Mozilla Backpack', 'badgeos_obi_issuer') : __('Resend to Mozilla Backpack', 'badgeos_obi_issuer'); $badge_html = get_post_type() === 'submission' ? badgeos_render_achievement(get_post_meta(get_the_ID(), '_badgeos_submission_achievement_id', true)) : badgeos_render_achievement($achievement_id); $badge_html .= '<div class="badgeos_backpack_action">'; $badge_html .= '<a href="" class="badgeos_backpack button" data-uid="' . $base_url . $uid . '">' . $button_text . '</a> '; $badge_html .= '<input type="checkbox" value="' . $base_url . $uid . '" name="badgeos_backpack_issues[]" />'; $badge_html .= '</div>'; $achievements[] = array("uid" => $base_url . $uid, "type" => get_post_type($achievement_id), "data" => $badge_html); $achievement_count++; } } return array("achievements" => $achievements, "count" => $achievement_count); }
/** * Register custom Post2Post relationships */ function register_achievement_relationships() { // Grab all our registered achievement types and loop through them $achievement_types = badgeos_get_achievement_types_slugs(); if (is_array($achievement_types) && !empty($achievement_types)) { foreach ($achievement_types as $achievement_type) { // Connect steps to each achievement type // Used to get an achievement's required steps (e.g. This badge requires these 3 steps) p2p_register_connection_type(array('name' => 'step-to-' . $achievement_type, 'from' => 'step', 'to' => $achievement_type, 'admin_box' => false, 'fields' => array('order' => array('title' => __('Order', 'badgeos'), 'type' => 'text', 'default' => 0)))); // Connect each achievement type to a step // Used to get a step's required achievement (e.g. this step requires earning Level 1) p2p_register_connection_type(array('name' => $achievement_type . '-to-step', 'from' => $achievement_type, 'to' => 'step', 'admin_box' => false, 'fields' => array('order' => array('title' => __('Order', 'badgeos'), 'type' => 'text', 'default' => 0)))); } } }
/** * Globally replace "Featured Image" text with "Achievement Image". * * @since 1.3.0 * * @param string $string Original output string. * @return string Potentially modified output string. */ function badgeos_featured_image_metabox_title($string = '') { // If this is a new achievement type post // OR this is an existing achievement type post // AND the text is "Featured Image" // ...replace the string if ((isset($_GET['post_type']) && in_array($_GET['post_type'], badgeos_get_achievement_types_slugs()) || isset($_GET['post']) && badgeos_is_achievement($_GET['post'])) && 'Featured Image' == $string) { $string = __('Achievement Image', 'badgeos'); } elseif ((isset($_GET['post_type']) && 'achievement-type' == $_GET['post_type'] || isset($_GET['post']) && 'achievement-type' == get_post_type($_GET['post'])) && 'Featured Image' == $string) { $string = __('Default Achievement Image', 'badgeos'); } return $string; }
/** * Helper function tests that we're in the main loop * * @since 1.0.0 * @param bool|integer $id The page id * @return boolean A boolean determining if the function is in the main loop */ function badgeos_is_main_loop($id = false) { $slugs = badgeos_get_achievement_types_slugs(); // only run our filters on the badgeos singular pages if (is_admin() || empty($slugs) || !is_singular($slugs)) { return false; } // w/o id, we're only checking template context if (!$id) { return true; } // Checks several variables to be sure we're in the main loop (and won't effect things like post pagination titles) return $GLOBALS['post']->ID == $id && in_the_loop() && empty($GLOBALS['badgeos_reformat_content']); }
/** * AJAX Helper for selecting achievement types in Shortcode Embedder * * @since 1.4.0 */ function badgeos_ajax_get_achievement_types() { // If no query was sent, die here if (!isset($_REQUEST['q'])) { die; } $achievement_types = array_diff(badgeos_get_achievement_types_slugs(), array('step')); $matches = preg_grep("/{$_REQUEST['q']}/", $achievement_types); $found = array_map('get_post_type_object', $matches); // Include an "all" option as the first option array_unshift($found, (object) array('name' => 'all', 'label' => __('All', 'badgeos'))); // Return our results wp_send_json_success($found); }
public function shortcode($atts) { $atts = shortcode_atts(array('type' => 'all', 'format' => 'simple', 'user_id' => 0, 'link_to' => false), $atts); if ($atts['type'] == 'all') { $atts['type'] = badgeos_get_achievement_types_slugs(); } $points = absint(badgeos_get_users_points($atts['user_id'])); $level = $this->get_level_info($points, $atts['type']); // no progress bar if (!$level['next_points']) { return ''; } $progress = $points / $level['next_points'] * 100 . "%"; $output = ''; if ($atts['link_to']) { $output .= '<a href="' . $atts['link_to'] . '">'; } $title = ""; if ($level['current_achievement']) { $title = get_the_title($level['current_achievement']) . ": "; } $output .= $this->wppb_get_progress_bar(false, false, $progress, false, $progress, true, sprintf(__("%s%d/%d Points", 'badgeos-activity-progress'), $title, $points, $level['next_points'])); if ($atts['link_to']) { $output .= '</a>'; } if ($atts['format'] == 'extended') { $progress = $output; $output = __('Current activity level:', 'badgeos-activity-progress'); if ($level['current_achievement']) { $output .= '<div class="badgeos-badge-wrap">'; $output .= badgeos_get_achievement_post_thumbnail($level['current_achievement']); $output .= '<span class="badgeos-title-wrap"><a href="' . get_permalink($level['current_achievement']) . '">' . get_the_title($level['current_achievement']) . '</a></span>'; $output .= '</div>'; } else { $output .= ' ' . __('No activity level reached.', 'badgeos-activity-progress') . '<br>'; } $output .= '<p>' . sprintf(__("Activity points needed for next level: %d", 'badgeos-activity-progress'), $level['next_points']) . '</p>'; $output .= $progress; } wp_enqueue_style('activity-progress-shortcode'); return $output; }
/** * Add a Credly Badge Settings metabox on the badge CPT * * @since 1.0.0 * @return void */ public function badge_metabox_add() { foreach (badgeos_get_achievement_types_slugs() as $achievement_type) { add_meta_box('badgeos_credly_details_meta_box', __('Badge Sharing Options', 'badgeos'), array($this, 'badge_metabox_show'), $achievement_type, 'advanced', 'default'); } }
/** * Helper function for generating the HTML output for configuring a given step * * @since 1.0.0 * @param integer $step_id The given step's ID * @param integer $post_id The given step's parent $post ID * @return string The concatenated HTML input for the step */ function badgeos_steps_ui_html($step_id = 0, $post_id = 0) { // Grab our step's requirements and measurement $requirements = badgeos_get_step_requirements($step_id); $count = !empty($requirements['count']) ? $requirements['count'] : 1; $achievement_types = badgeos_get_achievement_types_slugs(); ?> <li class="step-row step-<?php echo $step_id; ?> " data-step-id="<?php echo $step_id; ?> "> <div class="step-handle"></div> <a class="delete-step" href="javascript: badgeos_delete_step( <?php echo $step_id; ?> );"><?php _e('Delete', 'badgeos'); ?> </a> <input type="hidden" name="post_id" value="<?php echo $post_id; ?> " /> <input type="hidden" name="order" value="<?php echo get_step_menu_order($step_id); ?> " /> <?php echo apply_filters('badgeos_steps_ui_html_require_text', __('Require', 'badgeos'), $step_id, $post_id); ?> <?php do_action('badgeos_steps_ui_html_after_require_text', $step_id, $post_id); ?> <select class="select-trigger-type" data-step-id="<?php echo $step_id; ?> "> <?php foreach (badgeos_get_activity_triggers() as $value => $label) { echo '<option value="' . esc_attr($value) . '" ' . selected($requirements['trigger_type'], $value, false) . '>' . esc_html($label) . '</option>'; } ?> </select> <?php do_action('badgeos_steps_ui_html_after_trigger_type', $step_id, $post_id); ?> <select class="select-achievement-type select-achievement-type-<?php echo $step_id; ?> "> <option value=""></option> <?php foreach ($achievement_types as $achievement_type) { if ('step' == $achievement_type) { continue; } echo '<option value="' . $achievement_type . '" ' . selected($requirements['achievement_type'], $achievement_type, false) . '>' . ucfirst($achievement_type) . '</option>'; } ?> </select> <?php do_action('badgeos_steps_ui_html_after_achievement_type', $step_id, $post_id); ?> <select class="select-achievement-post select-achievement-post-<?php echo $step_id; ?> "> <option value=""></option> </select> <input type="text" size="5" placeholder="<?php _e('Post ID', 'badgeos'); ?> " value="<?php esc_attr_e($requirements['achievement_post']); ?> " class="select-achievement-post select-achievement-post-<?php echo $step_id; ?> "> <?php do_action('badgeos_steps_ui_html_after_achievement_post', $step_id, $post_id); ?> <input class="required-count" type="text" size="2" maxlength="2" value="<?php echo $count; ?> " placeholder="1"> <?php echo apply_filters('badgeos_steps_ui_html_count_text', __('time(s).', 'badgeos'), $step_id, $post_id); ?> <?php do_action('badgeos_steps_ui_html_after_count_text', $step_id, $post_id); ?> <div class="step-title"><label for="step-<?php echo $step_id; ?> -title"><?php _e('Label', 'badgeos'); ?> :</label> <input type="text" name="step-title" id="step-<?php echo $step_id; ?> -title" class="title" value="<?php echo get_the_title($step_id); ?> " /></div> <span class="spinner spinner-step-<?php echo $step_id; ?> "></span> </li> <?php }