From 73abbfb1e715e59b98d50c8e5f6bf0623fcae34d Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Thu, 23 Jun 2016 13:49:03 -0400 Subject: [PATCH] Don't try to update posts that have no API ID. Also, discovered a bug: https://github.com/nprds/nprapi-wordpress/issues/21 --- get_stories_ui.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/get_stories_ui.php b/get_stories_ui.php index 71ffa37..b0fb36a 100644 --- a/get_stories_ui.php +++ b/get_stories_ui.php @@ -70,14 +70,21 @@ function nprstory_bulk_action_update_action() { $exported = 0; foreach( $post_ids as $post_id ) { $api_id = get_post_meta( $post_id, NPR_STORY_ID_META_KEY, TRUE ); - $api = new NPRAPIWordpress(); - $params = array( 'id' => $api_id, 'apiKey' => get_option( 'ds_npr_api_key' ) ); - $api->request( $params, 'query', get_option( 'ds_npr_api_pull_url' ) ); - $api->parse(); - if ( empty( $api->message ) || $api->message->level != 'warning' ){ - error_log( 'updating story for API ID='.$api_id ); - $story = $api->update_posts_from_stories(); - } + + // don't run API queries for posts that have no ID + // @todo: why do some posts have no ID + // @todo: oh, it's only imported drafts that don't have an ID + if ( !empty( $api_id ) ) { + $api = new NPRAPIWordpress(); + $params = array( 'id' => $api_id, 'apiKey' => get_option( 'ds_npr_api_key' ) ); + $api->request( $params, 'query', get_option( 'ds_npr_api_pull_url' ) ); + $api->parse(); + if ( empty( $api->message ) || $api->message->level != 'warning' ){ + error_log( 'updating story for API ID='.$api_id ); + $story = $api->update_posts_from_stories(); + } + } else { + } } // build the redirect url