KC Settings

I’ve been writing WordPress themes for these past two years. Some of them are very simple and some others are quite complex. These themes need a settings panel so the user (or the site admin) can configure their site comfortably. There are many methods around the interwebs on how you can create such a settings panel for your theme/plugin. I tried to adapt some of them into my themes, but there was always something wishpering in my ear telling me to write my own settings panel with my own way :) .

The closest thing I found was the method used by Hybrid, Justin Tadlock‘s very powerful theme framework. However, it lacks some features I need, and it’s not too comfortable to work with. I like the way it uses the metaboxes to present the options though, it’s very WordPress :)

So I began playing with Hybrid’s code and altered the way it handles the options, but keep the presentation intact. I got it working the way I wanted it to, until I need to add another feature (other option type and validation). I came across Otto’s article about WordPress’ Setting API and it inspired to rewrite the code.

After a few fun days, I finally got it right and made it as a plugin so everyone can use it in their project. It still lacks some features (like file upload), but (I think) the base code is easy enough to modify so it won’t take long before I add them :)

For you WordPress lovers out there, here I present my very first public plugin, KC Settings.

Update:
This plugin is now hosted at WordPress plugins directory.

I’ve included a readme.html file so you should read it before using the plugin. The documentation is not complete yet, but should be enough to get you started. Any questions, bug reports, please feel free to contact me.

19 thoughts on “KC Settings”

  1. Love this plugin – it made my life much much easier. One thing I’d also like to see added, though, if you are taking requests is the option to enter a “date” using some other plugin (jquery ui, for example). Thanks for a great plugin!

    1. Thanks for trying out the plugin Joshua and I’m glad that you find it useful. I’m still adding new option types and will try to implement your great idea.

  2. Great plugin, i love it!

    i’m triyng to do something similar to multi-input but referred to the whole meta box.

    do you have any ideas for that?

    thanks

    1. Thanks for using the plugin, Luigi.

      Could you explain more about the whole metabox? The current multiinput type has a javascript bug in it (just discovered it a few days ago) and I will make the fix. It’d be lovely if I could integrate your idea/need into the fix.

      1. sure!

        i create, for example, a metabox for posts named “meta-1″. inside i put a multi-input field.

        using the script to add/remove multi-input fields, i’m trying to add (or remove) meta boxes.
        for the example i’d like to add a “meta-2″ box with another multi-input field.

        i hope you uderstand what i’m triyng to do… :)

  3. Excellent plug-in!

    However, I recently realized a potential limitation concerning the treatment of custom callback functions.

    Particularly, I had to add metadata to custom taxonomy terms, introducing the featured post dropdown list. For every term a user can select at most one post as a featured post for that term. In order to populate the dropdown list, I had to write a custom callback function, but I couldn’t find a way to acquire a reference to the term object itself. I then modified the kc_settings_field function inside form.php so that it passes $object_id and $db_value when calling the callback function. Although $db_value is not necessary, I found it practical not to query the database twice.

    If you think that there is a more elegant solution for acquiring the term object, I would be very happy to hear it. If not, this could be a handy addition for the next version of this great plugin.

    1. Thank you for using the plugin and giving a very valuable feedback Tan!

      My idea is to pass two arguments to the callback function: $args, and $db_value. You will then be able to get all field data from $args, including the $object_id. The old 'args' key will not be passed directly to the callback function but you’ll still be able to get it from the $args array, so you may need to modify your callback function when I push the update (in a day or two hopefully).

  4. Hi this is a really great plugin, thanks :)

    Excuse if this is a silly question but I have been looking through the documentation and cannot find how to output the values of the fields into the template files. I have image urls and links. Im used to working with custom fields but in this case Im using plugin / theme settings.

    A bit of feedback from my experience, not sure how hard this would be to address or if its worth it but when you make lots of sections and fields (in theme and plugin settings) all the blocks build up quite a lot. It would be great if you could minimise the sections you aren’t working on.

    1. Hi Steve, thank you for using the plugin.

      getting the value of theme/plugin options is quite simple:

      kc_get_option( 'PREFIX', 'SECTION_ID', 'FIELD_ID' );

      You can also ommit the field ID to get the value of a section, or ommit the section ID to get all values of the plugin/theme setting.

      By minimizing, did you mean expand/collapse like the metaboxes? I will try to implement this in the next update. Thanks for the suggestion! :)

  5. Hi Aziz,

    thank you for this great plugin ! I’m working on the last version of my plugin category icons lite, it saves me a lot of time and bugs, as I did not want to develop a settings panel. :)
    I just have a little problem : I did not find how to ‘auto-check’ a ‘default’ radio ; even if it is defined as the default choice, it is not checked automatically as it should be with : checked=’true’. Any advice ?

    1. Currently, the ‘default’ entry is only used for reference/fallback. When I added this feature, it was intended to behave exactly like what you said, but then it introduced bugs. Think about older posts/terms/anything created before the settings were added :)
      Perhaps I should mention this in the docs when I release the next version.

      Thank you for using KC Settings.

  6. Thanks for your informations. I added in my plugin a ‘factory/initial/reset setting’ state of options : if there are already options defined, it’ll not be active, but if there’re no options defined and kc settings activated, it’ll be active : I use add_options with the default state in a serialized string. Example of the default state serialized datas:

    a:1:{s:22:"caticonslite-section-1";a:3:{s:22:"caticonslite-posttitle";a:1:{i:0;s:7:"checked";}s:20:"caticonslite-sidebar";a:1:{i:0;s:7:"checked";}s:21:"caticonslite-position";s:4:"left";}}
    1. Thanks!.

      I’ve been planning on setting up GlotPress for my themes/plugins translation so people can contribute easily. I will announce it when it’s ready.

      One more thing. For future support, please create a new topic at the support forum so other people can benefit from it? :)

  7. Hi, your plugin is a lifesaver. However, I feel obligated to mention that there is a problem, your plugin can’t create a new section. When I click the add link, there’s a javascript error. I think this happens after I updated the newest WordPress.

    Uncaught TypeError: Object [object Object] has no method ‘ColorPicker’

  8. Hi Kucrut!

    I think your plugin is awesome and easy to use. I was able to create the custom fields I wanted for my WP contributors to fill up when doing a new post.

    My next problem is displaying the data from the custom fields. I’m not an advance WP developer and I tried following your tutorial but I’m not seeing the data when I open the posts.

    I inserted it after the post content:

    the_content();
    kc_get_option( ‘PREFIX’, ‘Establishment-contact-information’, ‘address’ );

    ————
    section_id: Establishment-contact-information
    field_id: address
    ————

    Am I missing a step? I basically just installed, activated, added the fields in KC Settings and tried to insert the code on blog post.

    Thanks and I look forward to your feedback.

    1. Hi. Thanks for using the plugin!

      For custom fields, you don’t (and shouldn’t) use kc_get_option(). Instead, just use WordPress’s built-in function: get_post_meta( POST_ID, '_FIELD_ID', true );. Don’t forget to append an underscore to the field ID and replace POST_ID with the actual post ID, or you can use get_the_ID() function if you’re inside the loop. It’s in the doc :)

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>