I have a script which when running standalone as a php works fine. It's a simple output of an rss feed but the rss is generated on the fly by dircaster. When I turn this into a wordpress plugin, however, it fails to work every time.
This is the error which is often given. Pressing refresh sometimes then makes it work.
Warning: array_slice() expects parameter 1 to be array, null given in /home/evilmer/public_html/frome.me/ffm/wp-content/plugins/fromefm-player/fromefm-player-plugin.php on line 50
Warning: Invalid argument supplied for foreach() in /home/evilmer/public_html/frome.me/ffm/wp-content/plugins/fromefm-player/fromefm-player-plugin.php on line 53
This is the code which is generated based on [ffmplayer show=xxx showno=xx]
. I have not included the entire shortcode code as I don't think it's neccesary.
include_once(ABSPATH . WPINC . '/rss.php');
$num_items = $showno;
$feedurl = 'http://fromefm.co.uk/archive/dircasterX.php?show='.$show;
$feed = fetch_rss($feedurl);
$items = array_slice ($feed->items, 0, $num_items);
$list = "";
foreach ($items as $item )
{
$title = $item[title];
$mp3link = $item[link];
$description = $item[description];
$list .= "$title - $description</br><audio src='$mp3link' preload='none'> </audio>";}
return "
<script>
audiojs.events.ready(function() {
var as = audiojs.createAll();
});
</script>
$list
";
Line 50 is:
$items = array_slice ($feed->items, 0, $num_items);
And line 53 is
foreach ($items as $item )
I'm convinced that it's just not running the DircasterX.php (dircaster.org) script properly or every time but it seems to work ok when I use it standalone and calling it with magpierss instead of the version (rss.php) which is built into wordpress.
The standalone version is currently here http://www.fromefm.co.uk/popupplayer/five.php?show=homelyremedies&showno=6 Instead of using wordpress shortcode it gets the variables from $_get
instead.
There is a demo install of the plugin here (please ignore the js error on fromfmplayer.js as it's unrelated) http://frome.me/ffm/?page_id=48
The warning you got tells you that $feed
is null. Probably because fetch_rss($feedurl)
didn't its results successfully.