PHP Deprecated: Non-static method should not be called statically

Shortcodes are a WordPress thing, hence not being in the PHP manual. What you do want to look at in the PHP manual is the section on callbacks. add_shortcode() accepts a shortcode name, and a callback. In that section of the PHP manual you can see the 3 main types of callbacks:

// Type 1: Simple callback
call_user_func('my_callback_function');

// Type 2: Static class method call
call_user_func(array('MyClass', 'myCallbackMethod'));

// Type 3: Object method call
$obj = new MyClass();
call_user_func(array($obj, 'myCallbackMethod'));

Your callback function for your shortcode is the 2nd type:

add_shortcode('RSSjb', array('RSSjbClass', 'RSSjb_funct'));

This is the same as calling RSSjbClass::RSSjb_funct, which is how you call a static method, but in your class the RSSjb_funct() method isn’t defined statically:

function RSSjb_funct($atts) {

So the quickest fix is to define that method as static:

public static function RSSjb_funct($atts) {

The other option would be to add the shortcode within the class using $this, or to create an instance of the class and then use that in add_shortcode() like Type 3 above.

Leave a Comment