0

I created a custom options page for may theme using this code:

add_action( 'admin_menu', 'jrl_add_admin_menu' );
function jrl_add_admin_menu()
{
    add_menu_page('Options', 'Options', 'manage_options', 'functions','custom_options','dashicons-welcome-learn-more');
}
function custom_options()
{
?>
    <div id="jrl-wrap">
    <div id="icon-tools" class="icon32"></div>
        <h1>Options</h1>
        <p>Add Informations.</p>
        <hr>
        <form method="post" action="options.php" enctype="multipart/form-data">
            <?php wp_nonce_field('update-options') ?>
  <table class="widefat">
  <tr valign="">
  <th scope="row"><label for="myplugin_option_name">Title:</label></th>
  <td><input type="text" name="jrlname" size="45" value="<?php echo get_option('jrlname'); ?>" /></td>
  </tr>
  <tr valign="">
  <th scope="row"><label for="myplugin_option_name">Title Abbreviation:</label></th>
  <td><input type="text" name="abr" size="45" value="<?php echo get_option('abr'); ?>" /></td>
  </tr>  <br>
  <tr valign="">
  <th scope="row"><label for="myplugin_option_name">Publisher:</label></th>
  <td><input type="text" name="pub" size="45" value="<?php echo get_option('pub'); ?>" /></td>
  </tr>
  </table><hr>
            <p class="submit"><input type="submit" name="Submit" value="Save Options"  /></p>
            <input type="hidden" name="action" value="update" />
            <input type="hidden" name="page_options" value="jrlname,abr,pub" />
        </form>
    </div>
<?php
}
function load_custom_wp_admin_style() {
    wp_register_style( 'custom_wp_admin_css', get_stylesheet_directory_uri() . '/functions/options.css', false, '1.0.0' );
    wp_enqueue_style( 'custom_wp_admin_css' );
}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );

I need to add a repeater field to this options page. I found a method to add meta box to custom taxonomy using this code from (https://github.com/bainternet/Tax-Meta-Class):

require_once( get_stylesheet_directory() . '/Tax-meta-class/Tax-meta-class.php' );
$rep = array(
   'id' => 'demo_meta_box',
   'title' => 'Demo Meta Box',
   'pages' => array('category'),
   'context' => 'normal',
   'fields' => array(),
   'local_images' => false,
   'use_with_theme' => true
);
$my_meta = new Tax_Meta_Class($rep);
$repeater_fields[] = $my_meta->addText('re_text_field_id',array('name'=> 'My Text '),true);
$repeater_fields[] = $my_meta->addTextarea('re_textarea_field_id',array('name'=> 'My Textarea '),true);
$repeater_fields[] = $my_meta->addCheckbox('re_checkbox_field_id',array('name'=> 'My Checkbox '),true);
$repeater_fields[] = $my_meta->addImage('image_field_id',array('name'=> 'My Image '),true);
 $my_meta->addRepeaterBlock('re_',array('inline' => true, 'name' => 'This is a Repeater Block','fields' => $repeater_fields));
$my_meta->Finish();

How can I use this last code to add the meta box to the options page & not to a taxonomy? I tried to add the code to the first one changing : 'pages' => array('category'), to 'pages' => array('functions'), where functions is the slug of my custom options page but nothing happened, no fields displayed in the options page. Am I missing something here? Any help please?

  • Just to let you know, Tax Meta Class by Bainternet has issues that you should aware of. – Mayeenul Islam Sep 8 '15 at 12:22
  • Thanks a lot @MayeenulIslam. I'll take a look. But do you have any alternative clean solution please? – nisr Sep 8 '15 at 12:28
  • scalable? no. I don't have any concrete solution right now for repeated fields. But I wrote an article in Bengali about how taxonomy meta works, with how to negotiate with the URL issues. You may not get help from the Bengali article, even with translator, but you can have a look at the code snippets there. But you have to build your own repeated fields, using jQuery. – Mayeenul Islam Sep 8 '15 at 16:45
  • take a look at this github.com/bainternet/Admin-Page-Class – Bainternet Sep 9 '15 at 6:12
  • @MayeenulIslam please get your facts right before notifying people about "bugs" or "issues". – Bainternet Sep 9 '15 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.