0

I'm trying to call a method into a function widget. The $this of the widget is passed to that method, but I get the following error:

Strict Standards: Non-static method class_name::method_name() should not be called statically, assuming $this from incompatible context in C:\xampp\htdocs\wp\wp-content\themes\...... on line 446

Here's what I'm trying to do exactly.

The widget form function:

class new_widget extends WP_Widget {
    function form($instance) {
        <?php widget_fields::input($instance, 'title'); ?>
    }
}

And the class which I'm using out of the score of the widget class:

class widget_fields {
    function input($t, $slug) {
        ?>
        <p>
            <input type="text" name="<?php echo $this->get_field_name($slug); ?>" value="<?php echo $t[$slug]; ?>" />          
        </p>
        <?php

    }
}
2
  • My widget is fine. I just grabbed the part of function form($instance) from it. I wanted to show that I'm trying to add a form input through a class. The issue is just with using $this (of the widget) outside it. Commented Mar 9, 2016 at 8:28
  • Yeah. Know how to use $this out of scope of the widget class without getting an error? Commented Mar 9, 2016 at 10:00

1 Answer 1

0

Like the error suggests, your are calling the function statically. If you wanna use it that way you gotta change

 function input

to:

static function input
1
  • I'm using a dynamic variable $this. I can't call it statically. Commented Mar 9, 2016 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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