Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have built a widget class such as (using pear naming standards):

class CoreTheme_Adminpanel_Widgets_Download extends WP_Widget{

    function CoreTheme_Adminpanel_Widgets_Download(){
        parent::__construct( false, 'Aisis Download Button' );

        $aisi_widget_options = array( 'classname' => 'download', 'description' => __('This widget will allow you to display a download button.', 'downlaod') );

        $aisis_control_options = array( 'width' => 300, 'height' => 350, 'id_base' => 'download-widget' );  
    }

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

        $url = $instance['url'];
        $title = $instance['title'];
        $show_info = $instance['info'];

        echo $before_widget;
        ?>
        <a href="<?php if($url){echo $url;}?>" class="btn btn-success btn-xlarge"><?php if($title){echo $title;}?></a>
        <div class="well"><p><?php if($show_info){echo $show_info; }?></p></div>
        <?php
        echo $show_info;

        echo $after_widget;
    }

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

        $instance['url'] = strip_tags( $new_instance['url'] );
        $instance['title'] = strip_tags( $new_instance['title'] );
        $instance['info'] = $new_instance['info'];

        return $instance;
    }   

    function form(){
        $instance = wp_parse_args((array)$instance);    

        echo '<label>Download Url</label>';

        if(!isset($insance['url'])){
            echo '<input type="url" name="'.$this->get_field_name('url').'" />';
        }else{
            echo '<input type="url" name="'.$this->get_field_name('url').'" value="'.$instance['url'].'"/>';
        }

        echo '<label>Download Button Title</label>';

        if(!isset($insance['title'])){
            echo '<input type="text" name="'.$this->get_field_name('title').'" />';
        }else{
            echo '<input type="text" name="'.$this->get_field_name('title').'" value="'.$instance['title'].'"/>';
        }

        echo '<label>Information</label>';

        if(!isset($insance['info'])){
            echo '<textarea name="'.$this->get_field_name('info').'"></textarea>';
        }else{
            echo '<textarea name="'.$this->get_field_name('info').'">'.$instance['info'].'</textarea>';
        }       

    }
}

// Register the widget
function register_download() {
    register_widget( 'CoreTheme_Adminpanel_Widgets_Download' );
}

// Add said action
add_action( 'widgets_init', 'register_download' );

My question is, according too: register_widget() I did every thing correctly, so where's my widget?

share|improve this question
What happens if you drop the PHP 4 code and call parent::__construct( 'download-widget', __('Aisis Download Buton', 'download'), $aisi_widget_options, $aisis_control_options );? – toscho Mar 21 at 20:56
Doesn't work, se the updated code. – TheWebs Mar 21 at 21:17
Replace $this->WP_Widget( with parent::__construct(. Your current code cannot work, that's why I asked @AndyAdams. – toscho Mar 21 at 21:22
@toscho Still doesn't show up. I have WP_Debug turned on, no errors. – TheWebs Mar 21 at 21:25

closed as too localized by toscho Mar 22 at 8:48

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

2 Answers

Just a stab:

In your constructor, try calling the parent constructor at the top:

function CoreTheme_Adminpanel_Widgets_Download(){
    // This line:
    parent::__construct( false, 'Aisis Download Button' );
    $aisi_widget_options = array( 'classname' => 'download', 'description' => __('This widget will allow you to display a download button.', 'downlaod') );

    $aisis_control_options = array( 'width' => 300, 'height' => 350, 'id_base' => 'download-widget' );
    $this->WP_Widget( 'download-widget', __('Aisis Download Buton', 'download'), $aisi_widget_options, $aisis_control_options );        
}

As to why this would work - I did a quick test with a widget I had locally, and it seemed to disable it when I removed the parent call...that's about it!

share|improve this answer
Please explain why that could solve the problem. I am really curious now. :) – toscho Mar 21 at 21:05
It doesn't. At least it didn't for me - please see the updated OP code. – TheWebs Mar 21 at 21:17
Aside from the widget form losing its content on save - the widget works fine for me in a fresh WP install. – vancoder Mar 21 at 21:31
You need to pass the options to the parent constructor like so: parent::__construct( 'aisisdbwid', 'Aisis Download Button', $aisi_widget_options, $aisis_control_options ); and then run it at the bottom of CoreTheme_Adminpanel_Widgets_Download. The second call to $this->WP_Widget runs the parent constructor a second time unnecessarily – s_ha_dum Mar 22 at 0:34

The key here people:

make sure to load the file you are trying to use before stating it doesn't work.

share|improve this answer

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