admin管理员组文章数量:1291643
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.
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.
Share Improve this question edited May 25, 2021 at 11:56 PauloBoaventura 1327 bronze badges asked Nov 19, 2017 at 7:53 Cynthia A LockleyCynthia A Lockley 551 gold badge1 silver badge7 bronze badges2 Answers
Reset to default 8Shortcodes 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.
If you don't want to call the class method statically you can do the following
add_shortcode('RSSjb', [new RSSjbClass, 'RSSjb_funct']);
本文标签: pluginsPHP Deprecated Nonstatic method should not be called statically
版权声明:本文标题:plugins - PHP Deprecated: Non-static method should not be called statically 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741537753a2384131.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论