How to save and retreive an array from checkbox list in Theme Options

enter image description here

I am developing a very simple WP theme and I wonder how could I get this functioning.

The main goal is to save the value of the selected checkboxes and retreive it in the front-end footer to load the links of the pages. I have been looking for this in many blogs and WP Codex but I can’t get it to work. Either the information is outdated or not quite specific.

As you can see, I am using an OOP approach and it’s been working very well, but it shouldn’t have anything to do with the WP core behaviour.

I have this Theme Options page (in progress):

Using the following code:

<?php

require_once(ABSPATH . 'wp-admin/includes/screen.php');

class ThemeOptions {

      function __construct() {
        add_action('admin_menu', array($this, 'load_menu_item'));

      }

  function load_menu_item() {
    add_submenu_page('options-general.php', 'Opciones de Plantilla',     'Opciones de Plantilla', 'administrator', 'themeoptions', array($this,     'load_form'));
  }

  function load_form() { ?>

<div class="dvContenedorGeneral">
  <h1>Opciones de Plantilla</h1>
  <p>
    En esta páginas podrás configurar las opciones de la plantilla <b>Heroes
    And Villains</b>. Haz clic en cada pestaña para modificar los parámetros
    de cada apartado.
  </p>
  <div class="dvContenedorPestañas">
      <div class="dvBarraLateral">
        <div id="link-general" class="dvItemLateral activo"> General </div>
        <div id="link-header" class="dvItemLateral inactivo"> Header </div>
        <div id="link-blog" class="dvItemLateral inactivo"> Blog </div>
        <div id="link-footer" class="dvItemLateral inactivo"> Footer </div>
      </div>
      <div id="general" class="dvConfiguracion">
        CONFIGURACIÓN GENERAL
      </div>
      <div id="header" class="dvConfiguracion">
        CONFIGURACIÓN DEL HEADER
      </div>
      <div id="blog" class="dvConfiguracion">
        CONFIGURACIÓN DEL BLOG
      </div>
      <div id="footer" class="dvConfiguracion">
        <div class="dvTituloInterno"> Enlaces </div>
        <div class="dvContenedorInterno">
            <p>
              Selecciona los enlaces a páginas que se mostrarán en el footer.
            </p>
            <form method="post" action="">
              <div class="dvContenedorItemsFooter">
              <?php
                $paginas = get_pages();
                foreach($paginas as $pagina) {
              ?>
                <div class="dvItemFooter">
                  <input id="<?php echo 'page_'.$pagina->ID ?>" type="checkbox" name="checkFooter" value="<?php echo utf8_encode($pagina->post_title) ?>" />
                  <label for="<?php echo 'page_'.$pagina->ID ?>"><?php echo utf8_encode($pagina->post_title) ?></label>
                </div>
                <?php
                }
                ?>
               </div>
            </form>
      </div>
      <?php submit_button(); ?>
      </div>
    </div>

  <?php }

}

Can you guys help me out? I would be very much grateful! Thanks in advance.

Read more here:: How to save and retreive an array from checkbox list in Theme Options

Leave a Reply

Your email address will not be published. Required fields are marked *