/** * Callback de meta_box itpt-meta-box * * @param mixed[] $post Post */ function itpt_meta_box_callback($post) { // Seguridad wp_nonce_field('itpt_meta_box', 'itpt_meta_box_noncename'); // Obtengo meta actuales $post_meta = get_post_custom($post->ID); // Obtengo tecnologías del post $post_meta_tecnologias = ""; if (isset($post_meta['tecnologias'])) { $post_meta_tecnologias = unserialize($post_meta['tecnologias'][0]); } // Obtengo listado completo de tecnologías $tecnologias = itpt_get_tecnologias(); // Inicio HTML echo '<ul class="ofertalaboral-listado-tecnologias">'; // Genero checkbox de tecnologias foreach ($tecnologias as $t) { // Defino checked por cada una $checked = ""; if (is_array($post_meta_tecnologias) && in_array($t->nombre, $post_meta_tecnologias)) { $checked = 'checked="checked"'; } ?> <li> <input type="checkbox" name="itpt_nombre[]" id="itpt_nombre" value="<?php echo $t->nombre; ?> " <?php echo $checked; ?> > <label for="itpt_nombre"><?php echo $t->nombre; ?> </label> </li> <?php } echo "</ul>"; // Fin HTML // Inicio CSS ?> <style> ul.ofertalaboral-listado-tecnologias li { width: 24%; display: inline-block; line-height: 15px; } ul.ofertalaboral-listado-tecnologias li input { margin: 0px; } </style> <?php // Fin CSS }
function itpt_load_content() { // Variables $show_error = false; $nombre = ''; $tecnologias = array(); // Proceso POST - Nuevo $result = itpt_handle_post(); if ($result !== true) { $nombre = $_POST['nombre-tecnologia']; $show_error = true; $error_msg = $result; } // Proceso POST - Eliminacion itpt_handle_delete(); // Obtengo listado $tecnologias = itpt_get_tecnologias(); ?> <div class="wrap"> <h2>Tecnologías</h2> <h4>Nueva tecnología</h4> <form class="form-inline" method="post"> <div class="form-group <?php if ($show_error === true) { echo "has-error"; } ?> "> <label class="sr-only" for="nombre">Nombre</label> <input type="text" class="form-control" id="nombre" placeholder="Nombre" name="nombre-tecnologia" value="<?php echo $nombre; ?> " autofocus> </div> <button type="submit" class="btn btn-primary" name="registrar-tecnologia">Registrar</button> <?php if ($show_error === true) { ?> <span id="helpBlock" class="help-block" style="color:#a94442;font-weight:bold"> <?php echo $error_msg; ?> </span> <?php } ?> </form> <h4>Tecnologías registradas</h4> <?php if (count($tecnologias) == 0) { ?> <p>No hay tecnologías registradas</p> <?php } else { ?> <ul id="list-tecnologias"> <?php foreach ($tecnologias as $t) { ?> <li> <form method="post" onsubmit="return confirmDelete('<?php echo $t->nombre; ?> ')"> <button type="submit" class="btn btn-danger btn-xs" name="eliminar-tecnologia"> <b>x</b> </button> <input type="hidden" name="id-tecnologia" value="<?php echo $t->id; ?> "> <span class="label label-default"><?php echo $t->nombre; ?> </span> </form> </li> <?php } ?> </ul> <?php } ?> </div> <script type="text/javascript"> function confirmDelete(nombre) { if(confirm("¿Estas seguro que deseas eliminar la tecnología " + nombre +"?")) { return true; } return false; } </script> <?php }