WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a custom widget, but it's not saving if I click on save. When I refresh the page it is not saved. My code looks like follows

/**  * Plugin Name: Sending a
     Contact SMS  * Plugin URI:
     http://www.test.co.za  * Description:
     Allows you to send a contact SMS to
     website owner  * Author: test  *
     Version: 1.0  * Author URI:

     class sendSMS extends WP_Widget {

         function sendSMS() {
               $widget_ops = array(
                   'classname' => 'sendSMS',
                   'description' => 'Allows you to add a small contact form that will send out an sms to the user.',
               $control_ops = array( 'id_base' => 'smsForm-widget' );
               $this->WP_Widget( 'smsForm-widget', 'Send SMS', $widget_ops, $control_ops);  }

         function form ($instance) {
             $defaults = array('title'=> __('Example', 'example'), 'name' =>  __('John Doe', 'example'), 'number' => __('+27825656994', 'example'), 'message' =>  __('Tell Us', 'example') );
             $instance = wp_parse_args( (array) $instance, $defaults );

                        <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'hybrid'); ?></label>
                        <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />

                        <label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e('Your Name:', 'name'); ?></label>
                        <input id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" value="<?php echo $instance['name']; ?>" />

                <!-- Your Name: Text Input -->
                        <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e('Your Cellphone Number:', 'number'); ?></label>
                        <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" value="<?php echo $instance['number']; ?>"  />

                        <label for="<?php echo $this->get_field_id( 'message' ); ?>"><?php _e('Your Message:', 'message'); ?></label>
                        <textarea id="<?php echo $this->get_field_id( 'message' ); ?>" name="<?php echo $this->get_field_name( 'message' ); ?>"><?php echo $instance['message']; ?></textarea>



         function update ($new_instance, $old_instance) {
            $instance = $old_instance;

            /* Strip tags (if needed) and update the widget settings. */
            $instance['title'] = strip_tags( $new_instance['title'] );
            $instance['name'] = strip_tags( $new_instance['name'] );
            $instance['number'] = $new_instance['number'];
            $instance['message'] = $new_instance['message'];

            return $instance;


         function widget ($args,$instance) {
            extract( $args );

            /* Our variables from the widget settings. */
            $title = apply_filters('widget_title', $instance['title'] );
            $name = $instance['name'];
            $number = $instance['number'];
            $message = $instance['message'];

            /* Before widget (defined by themes). */
            echo $before_widget;

            /* Display the widget title if one was input (before and after defined by themes). */
            if ( $title )
                    echo $before_title . $title . $after_title;

            /* Display name from widget settings if one was input. */
            if ( $name )
                    printf( '<p>' . __('Hello. My name is %1$s.', 'example') . '</p>', $name );

            if ( $number )
                    printf( '<p>' . __('Hello. My number is %1$s.', 'example') . '</p>', $name );

            if ( $message )
                    printf( '<p>' . __('Hello. My message is %1$s.', 'example') . '</p>', $message );

            /* After widget (defined by themes). */
            echo $after_widget;  }


        function load_sms_form() {  register_widget( 'sendSMS' ); }

        add_action('widgets_init', 'load_sms_form');

         // register the widget

share|improve this question
up vote 2 down vote accepted

there no "id_base" key in $control_ops; from what I know it only accepts width/height. move it

the id_base is the first argument you have there in WP_Widget()

share|improve this answer
this solved my issue in 2015! Apparently I was using outdated code as my custom widget template – Ejaz Jan 28 '15 at 10:32

the ID of sidebar (in php function) should not contain upparcase char (smsForm-widget)) !!!

share|improve this answer

Your Answer


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.