/** * Construct a dropdown of our post types so users can select which to edit. * * @since 1.0.0 * * @param array $post_types Array of post types that are registered. * * @return string HTML select dropdown. */ function cptui_post_types_dropdown($post_types = array()) { $ui = new cptui_admin_ui(); if (!empty($post_types)) { $select = array(); $select['options'] = array(); $select['options'][] = array('attr' => '', 'text' => '--'); foreach ($post_types as $type) { $select['options'][] = array('attr' => $type['name'], 'text' => $type['label']); } $current = cptui_get_current_post_type(); $select['selected'] = $current; echo $ui->get_select_input(array('namearray' => 'cptui_selected_post_type', 'name' => 'post_type', 'selections' => $select, 'wrap' => false)); } }
/** * Construct a dropdown of our taxonomies so users can select which to edit. * * @since 1.0.0 * * @param array $taxonomies Array of taxonomies that are registered. * * @return string HTML select dropdown. */ function cptui_taxonomies_dropdown($taxonomies = array()) { $ui = new cptui_admin_ui(); if (!empty($taxonomies)) { $select = array(); $select['options'] = array(); $select['options'][] = array('attr' => '', 'text' => '--'); foreach ($taxonomies as $tax) { $select['options'][] = array('attr' => $tax['name'], 'text' => $tax['label']); } $current = cptui_get_current_taxonomy(); $select['selected'] = $current; echo $ui->get_select_input(array('namearray' => 'cptui_selected_taxonomy', 'name' => 'taxonomy', 'selections' => $select)); } }
/** * Tests non boolean based select inputs */ public function test_CPTUI_Select_Non_Bool_Second_Option() { $ui = new cptui_admin_ui(); $select = array(); $select['options'] = array(); $select['options'][] = array('attr' => '', 'text' => '--'); $select['options'][] = array('attr' => 'movie', 'text' => 'Movies'); $select['options'][] = array('attr' => 'tv_show', 'text' => 'TV Show'); $select['selected'] = 'tv_show'; $args = array('namearray' => 'cptui_selected_post_type', 'name' => 'post_type', 'selections' => $select, 'wrap' => false); $expected = '<select id="post_type" name="cptui_selected_post_type[post_type]"> <option value="">--</option> <option value="movie">Movies</option> <option value="tv_show" selected="selected">TV Show</option> </select>'; $this->assertHTMLstringsAreEqual($expected, $ui->get_select_input($args)); }