admin管理员组文章数量:1130349
Okay so I have a method within a class which looks like
$this->addToSitemap('page', $urls);
This is used to append extra pages to the Yoast Sitemap. Here 'page' is the type of sitemap within yoast and $urls are the new urls. This method looks like this
public function addToSitemap($type = '', $links = array())
{
$CustomSitemaps = $this;
add_filter( "wpseo_sitemap_{type}_content", function() use
(&$CustomSitemaps) { return $CustomSitemaps->parseLinks($links); } );
}
Now here I am using an anonymous function because I need to pass the $links variable to the callback.
I am using $CustomSitemaps = $this; because an anonymous function does not allow $this. But for some reason his is still not working. If i do this
public function addToSitemap($type = '', $links = array())
{
$CustomSitemaps = $this;
add_filter( "wpseo_sitemap_{type}_content", function() use
(&$CustomSitemaps) { var_dump($CustomSitemaps->parseLinks($links));
die(); return $CustomSitemaps->parseLinks($links); } );
}
I see no nothin dumping on the screen. But if I do below $CustomSitemaps = $this; I do see it
Okay so I have a method within a class which looks like
$this->addToSitemap('page', $urls);
This is used to append extra pages to the Yoast Sitemap. Here 'page' is the type of sitemap within yoast and $urls are the new urls. This method looks like this
public function addToSitemap($type = '', $links = array())
{
$CustomSitemaps = $this;
add_filter( "wpseo_sitemap_{type}_content", function() use
(&$CustomSitemaps) { return $CustomSitemaps->parseLinks($links); } );
}
Now here I am using an anonymous function because I need to pass the $links variable to the callback.
I am using $CustomSitemaps = $this; because an anonymous function does not allow $this. But for some reason his is still not working. If i do this
public function addToSitemap($type = '', $links = array())
{
$CustomSitemaps = $this;
add_filter( "wpseo_sitemap_{type}_content", function() use
(&$CustomSitemaps) { var_dump($CustomSitemaps->parseLinks($links));
die(); return $CustomSitemaps->parseLinks($links); } );
}
I see no nothin dumping on the screen. But if I do below $CustomSitemaps = $this; I do see it
本文标签: phpUsing this with an anonymous function in filters
版权声明:本文标题:php - Using $this with an anonymous function in filters 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749056373a2309408.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论