Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a client whom I want to give as much Dashboard control over the admin area as possible. I know how to create a custom dashboard widget that contains just text/html but I have no idea how to create one that contains just a single text input field.

Adding the form html would be straightforward I can see that but I don't know:

  1. Where to submit the form data too
  2. How to redirect back to the Dashboard after the form is submitted
  3. How to retrieve the value in my non-admin theme templates
share|improve this question
add comment

1 Answer

You need a set of functions to :

  • process datas
  • sanitize options
  • allow datas to be updated
  • output the form

I like to proceed this way. I set also a function to grab datas so I can call them the simpliest way :

add_action('wp_dashboard_setup', 'wpse_106458_add_widget');

function wpse_106458_add_widget() {

  $title = my_function_get_options();
  $title = $title['title'];

  wp_add_dashboard_widget('widget_id', $title, 'callback_output', 'widget_control' );
}

Hope it helps.

EDIT: I wrap it with this :

if ( is_admin() || ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) ) {/* code goes here */}

This allows to apply code only where it's necessary.

share|improve this answer
    
Thanks, I really appreciate your help :) I came across this script which I removed from the Theme page and inserted into a Dashboard Widget via functions.php it helped a lot: themeshaper.com/2010/06/03/sample-theme-options –  Kev Jul 14 '13 at 14:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.