I'm creating my first Wordpress Plugin and want to let the user configure multiple urls which he can name and safe as "channels".

I've set up a settings page and wanted to store the data through add_option() as json like this:

    "name": "my first saved url",
    "url": "www.example.com"
    "name": "my second saved url",
    "url": "www.another-example.com"

I was considering json because there will be more values in the future than only these two.

I'd like to have just some input fields with name and url which i can validate and put together with existing ones and store them away.

By using the Settings-api from wordpress i have the feeling to be quite limited as far as the settings field correspond with only one option.

I also thought about not using the settings-api at all and just define a custom form with input fields and safe them in the end with update_option().

Does anyone have an idea on how to achieve what i want?

my full code is below i'm happy for any thoughts..

class MySettingsPage{

public function __construct() {
  array( $this, 'init_settings_page' ) 

        array( &$this, 'init_settings' )

public function init_settings_page(){

add_option( 'channels' );

$page_title = 'Settings channels';
$menu_title = 'Channels';
$capability = 'manage_options';
$slug = 'my_saved_urls';
$callback = array( $this, 'plugin_settings_page_content' );
$icon = 'dashicons-admin-plugins';
$position = 30.5;

add_menu_page( $page_title, $menu_title, $capability, $slug, $callback, $icon, $position );


public function plugin_settings_page_content() { ?>
<div class="wrap">
    <form method="post" action="options.php">
            settings_fields( 'my_saved_urls' );
            do_settings_sections( 'my_saved_urls' );
</div> <?php

public function init_settings() {

            'type'                => 'string',

        'Configured channels',
        function () {

        'channel URLs',
        function () {
            echo '<input type="text" name="urls_as_json" value="' . get_option( 'urls_as_json' ) . '" 

  • Haven't worked with the settings API in some time, but doesn't WP just serialize arrays? So there should be no need to do the JSON yourself, it should automatically work already. – kero Mar 11 at 18:24
  • 1
    oh gosh.. you're right. this simplifys alot :D I could just pass the array to update_option() and thats it.. thanks! – blackbart Mar 12 at 11:39

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.