views:

95

answers:

1

Hello, I'm just putting together a little 'hello world' type plugin to add a widget to the dashboard. The plugin is initialising and everything is fine with that i'm just having a problem adding content to the widget. Here's the code:

/*
 * Setup the class
 */
if(!class_exists("SampleClassSeries")){
    class SampleClassSeries {
        function sampleClassSeries(){
            //Constructor
        }
        //Our dashboard widget
        function addSampleDashboard(){
            ?>
                <p>This is a test plugin samlple yo!</p>
            <?php
        }
        function setup_sample_widgets() {
            wp_add_dashboard_widget('sample_ideas_widget', 'Sample Widget', 'addSampleDashboard');  
        }
    }//End sampleClassSeries
}
/*
 * Initialise the class
 */
if(class_exists("SampleClassSeries")){
    $samp_classSeries = new SampleClassSeries();
}
/*
 * Attach actions and filters
 */
if(isset($samp_classSeries)){
    //Add actions here
    add_action('wp_dashboard_setup', array(&$samp_classSeries, 'setup_sample_widgets'), 1);
}

Now i'm sure the problem lies in the "wp_add_dashboard_widget" where i'm calling "addSampleDashboard". I'm guessing it can't see the function as i'm getting

Warning: call_user_func(addSampleDashboard) [function.call-user-func]: First argument is expected to be a valid callback

Any help would be much appreciated. Thanks.

A: 

Your third argument needs to be a callback, which can take a variety of forms in PHP. In this instance, you probably want the following:

    function setup_sample_widgets() {
        wp_add_dashboard_widget('sample_ideas_widget', 'Sample Widget', array($this,'addSampleDashboard'));  
    }
nickohrn
Ahh it's that simple! Thanks for the answer Nick, worked like a charm.
Nooshu