diff --git a/classes/NPRAPI.php b/classes/NPRAPI.php
index a096eed..4d3dafd 100644
--- a/classes/NPRAPI.php
+++ b/classes/NPRAPI.php
@@ -96,12 +96,20 @@ function parse() {
return;
}
- $object = simplexml_load_string($xml);
+ try {
+ $object = simplexml_load_string( $xml );
+ } catch ( Exception $e ) {
+ echo "\nXML ERROR: {$e->getMessage()}\n";
+ $this->stories = array();
+ return;
+ }
$this->add_simplexml_attributes($object, $this);
if (!empty($object->message)) {
- $this->message->id = $this->get_attribute($object->message, 'id');
- $this->message->level = $this->get_attribute($object->message, 'level');
+ $this->message = (object) array(
+ 'id' => $this->get_attribute( $object->message, 'id' ),
+ 'level' => $this->get_attribute( $object->message, 'level' )
+ );
}
if (!empty($object->list->story)) {
diff --git a/classes/NPRAPIWordpress.php b/classes/NPRAPIWordpress.php
index 64bcdbb..c16e6d9 100644
--- a/classes/NPRAPIWordpress.php
+++ b/classes/NPRAPIWordpress.php
@@ -94,10 +94,24 @@ function query_by_url( $url ) {
* This function will go through the list of stories in the object and check to see if there are updates
* available from the NPR API if the pubDate on the API is after the pubDate originally stored locally.
*
+ * @see https://github.com/nprds/nprapi-wordpress/commit/ac0a7f7e3b7428ba783853eb76696b499bc85ecc for is_numeric($args)
+ *
+ * @since 1.7
+ *
* @param bool $publish
+ * @param array|int $opts { If numeric it will be `'query_number' otherwise an array of named options.
+ *
+ * @type int $query_number The number of the query for $args['tags_input']
+ *
+ * }
* @return int|null $post_id or null
*/
- function update_posts_from_stories( $publish = TRUE ) {
+ function update_posts_from_stories( $publish = TRUE, $opts = array() ) {
+
+ $opts = wp_parse_args( $opts, array(
+ 'query_number' => is_numeric( $opts ) ? intval( $opts ) : false,
+ ));
+
$pull_post_type = get_option( 'ds_npr_pull_post_type' );
if ( empty( $pull_post_type ) ) {
$pull_post_type = 'post';
@@ -154,6 +168,9 @@ function update_posts_from_stories( $publish = TRUE ) {
'post_type' => $pull_post_type,
'post_date' => $post_date,
);
+ if ( false !== $opts[ 'query_number' ] ) {
+ $args['tags_input'] = get_option( "ds_npr_query_tags_{$opts[ 'query_number' ]}" );
+ }
//check the last modified date and pub date (sometimes the API just updates the pub date), if the story hasn't changed, just go on
if ( $post_mod_date != strtotime( $story->lastModifiedDate->value ) || $post_pub_date != strtotime( $story->pubDate->value ) ) {
@@ -272,16 +289,16 @@ function update_posts_from_stories( $publish = TRUE ) {
//are there any images saved for this post, probably on update, but no sense looking of the post didn't already exist
if ( $existing ) {
$image_args = array(
- 'order'=> 'ASC',
- 'post_mime_type' => 'image',
- 'post_parent' => $post_id,
- 'post_status' => null,
- 'post_type' => 'attachment',
- 'post_date' => $post_date,
+ 'order' => 'ASC',
+ 'post_mime_type' => 'image',
+ 'post_parent' => $post_id,
+ 'post_status' => null,
+ 'post_type' => 'attachment',
+ 'post_date' => $post_date,
);
$attached_images = get_children( $image_args );
}
- foreach ( (array) $story->image as $image ) {
+ foreach ( (array) $story->image as $image_index => $image ) {
$image_url = '';
//check the Add tag(s) to each story pulled from NPR (comma separated).
Increase the number of queries by changing the number in the field above.";