Is there a better way to define options for custom fields in an admin panel?

It looks like you are using the Settings API to add images to a gallery or slideshow. As @kuchenundkakao suggested, a post type would be a good choice especially if you will have multiple slides, or if you will use different slides inside different galleries.

If you don’t need a custom post type (it is easily overkill), it would be easiest to display a custom form using add_menu_page. Use your own HTML form, and save the data using update_option(). Retrieve your slides with get_option().

An option in WordPress can be saved as an array, and is automatically returned as an array. It is serialized in the database, but you do not need to worry about it. WordPress takes care of it for you.

Here is an example of what you might want use when saving values from an HTML form:

$all_slides = array();

// Get our form data, from fields like: <input name="slides[0][name]">
$submitted_slides = stripslashes_deep($_POST['slides']);

// Get our images that were uploaded using a file input
$slide_files =  $_FILES['slides'];

foreach($submitted_slides as $i => $slide) {
  // Add a slide to our array
  $all_slides[] = array(
    'title' => $slide['title'],
    'description' => $slide['description'],
    'image' => wp_handle_upload( $slide_files[$i] ),
  );
}

// Save our slides to the database
update_option('mytheme-gallery', $all_slides);

You will want to use the admin_post action to process the form submission, and you will want to use nonce verification to make sure you are saving the form for that page specifically. Using that example, you can retrieve your slides with get_option('mytheme-gallery').

I could also suggest the Options Framework plugin by Devin Price to create custom admin pages. It’s overkill if you only need a page for managing the slider though. The main benefit is that it utilizes the media uploader for images, and handles validation for you.

tech