1

My debug.log has the following message that points to /wp-includes/shortcodes.php on line 319, which is part of WordPress core and probably isn't where the real error is in the code.

PHP Deprecated:  Non-static method RSSjbClass::RSSjb_funct() should not be called statically in /.../wp-includes/shortcodes.php on line 319

I've looked at line 319 and it doesn't help me find or solve the problem. I searched the code and found this with the Class and funct but I don't know what is non-static being called statically.

/**
 * Add shortcode to wordpress
 */
// add_shortcode('RSSjb', 'RSSjb_funct');
add_shortcode('RSSjb', array('RSSjbClass', 'RSSjb_funct'));
/**
 * Shortcode Class and Function
 */
class RSSjbClass {
    function RSSjb_funct($atts) {
        extract(shortcode_atts(array(
        // attributes for Google News
        "gsearch" => '',
        "topic" => '',
        "location" => '',
        "geo" => '',
        "feed" => '', // required
        "filter" => '',
        "num" => '5',
        "ltime" => '',
        "list" => 'ul',
        "target" => '_blank',
        "pubdate" => 'false',
        "pubtime" => 'false',
        "dformat" => get_option('date_format'),
        "tformat" => get_option('time_format'),
        "pubauthor" => 'true',
        "excerpt" => 'false',
        "charex" => '',
        "chartle" => '',
        "title" => '',
        "link" => 'false',
        "sort" => 'false',
        "cachefeed" => '3600'
    ), $atts));

followed by several "ifs" and then

    // call the function to read and display the feed items list
        return $tle . rssjb_List($feed, $filter, $num, $ltime, $list, $target, $pubdate, $pubtime, $dformat, $tformat, $pubauthor, $excerpt, $charex, $chartle, $sort, $cachefeed);
    } else {
        return '<br>RSS or Atom Feed URL not provided. This shortcode does require the attribute feed or location (if Google News).<br /> Ex: <code>[RSSjb feed = "http://your-rss-or-atom-feed-URL-here"]</code>.'; 
    }
    }
}

How do I modify that to fit with what is in /wp-includes/shortcodes.php line 319, which is:

    $output = $m[1] . call_user_func( $shortcode_tags[ $tag ], $attr, $content, $tag ) . $m[6];

    /**
     * Filters the output created by a shortcode callback.
     *
     * @since 4.7.0
     *
     * @param string       $output Shortcode output.
     * @param string       $tag    Shortcode name.
     * @param array|string $attr   Shortcode attributes array or empty string.
     * @param array        $m      Regular expression match array.
     */
    return apply_filters( 'do_shortcode_tag', $output, $tag, $attr, $m );
}

I searched the PHP Manual and it doesn't have anything about shortcodes.

4

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.

  • Thanks for that helpful explanation. Adding public static worked. I'd vote your answer up but I don't have enough reputation yet to be able to do that. Hopefully someone else will vote it up. – Cynthia A Lockley Nov 19 '17 at 9:01
  • 1
    Ah, I just got the needed reputation and voted it up. – Cynthia A Lockley Nov 19 '17 at 9:03
0

If you don't want to call the class method statically you can do the following

add_shortcode('RSSjb', [new RSSjbClass, 'RSSjb_funct']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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