0

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

Matthew Sims
  • 25
  • 1
  • 1
  • 7

1 Answers1

0

The warning you got tells you that $feed is null. Probably because fetch_rss($feedurl) didn't its results successfully.

RRikesh
  • 14,112
  • 5
  • 49
  • 70
  • That's what I thought but why? I haven't found anyone with a similar issue with Dircaster.. – Matthew Sims Feb 11 '13 at 09:51
  • `fetch_rss()` has been deprecated btw. Try using [`fetch_feed()`](http://codex.wordpress.org/Function_Reference/fetch_feed) instead. – RRikesh Feb 11 '13 at 09:54
  • Will I need to change `include_once(ABSPATH . WPINC . '/rss.php');` to `include_once(ABSPATH . WPINC . '/feed.php');` as well? – Matthew Sims Feb 11 '13 at 10:03
  • Thanks I'll try this as soon as I can. – Matthew Sims Feb 11 '13 at 10:06
  • 1
    This might have worked. I've updated the code to use simplepie versions of stuff such as `$item[link];` into `$item->get_link(0);` and *touch wood* it appears to be ok. The error was sporadic before but I haven't seen it since so I'll check this as accepted and ask again if the problem reappears. Thank you. – Matthew Sims Feb 11 '13 at 19:55