function form($instance) { $title = isset($instance['title']) ? strip_tags($instance['title']) : false; $space = isset($instance['space']) ? $instance['space'] : false; ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title', 'wpsight'); ?> : <input class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " type="text" value="<?php echo esc_attr($title); ?> " /> </label> </p> <p <?php if (count(wpsight_post_spaces()) == 1 && count(wpsight_listing_spaces()) == 1) { echo 'style="display:none"'; } ?> > <label for="<?php echo $this->get_field_id('space'); ?> "><?php _e('Space', 'wpsight'); ?> :</label> <select class="widefat" id="<?php echo $this->get_field_id('space'); ?> " name="<?php echo $this->get_field_name('space'); ?> "> <?php foreach (wpsight_post_spaces() as $k => $v) { // Use title if label is empty $label = !empty($v['label']) ? $v['label'] : $v['title']; echo '<option value="' . $v['key'] . '" ' . selected($v['key'], $space, false) . '>' . $label . '</option>'; } foreach (wpsight_listing_spaces() as $k => $v) { // Use title if label is empty $label = !empty($v['label']) ? $v['label'] : $v['title']; echo '<option value="' . $v['key'] . '" ' . selected($v['key'], $space, false) . '>' . $label . '</option>'; } ?> </select><br /> <span class="description"><?php _e('Select the space to display', 'wpsight'); ?> </span> </p><?php }
function wpsight_meta_box_listing_spaces() { // Get listing spaces $spaces = wpsight_listing_spaces(); if (empty($spaces)) { return; } // Loop through existing spaces foreach ($spaces as $space => $v) { // Set meta box $meta_box = array('id' => $space, 'title' => $v['title'], 'pages' => $v['post_type'], 'context' => 'normal', 'priority' => 'high', 'fields' => array($v['key'] => array('name' => $v['label'], 'id' => $v['key'], 'type' => $v['type'], 'desc' => $v['description'], 'rows' => $v['rows']))); } // endforeach // Apply filter to array $meta_box = apply_filters('wpsight_meta_box_listing_spaces', $meta_box); return $meta_box; }