function load_page_hook() { if (isset($_POST) && isset($_POST['story_id'])) { $story_id = absint($_POST['story_id']); } else { if (isset($_GET['create_draft']) && isset($_GET['story_id'])) { $story_id = absint($_GET['story_id']); } } if (isset($story_id)) { // XXX: check that the API key is actually set $api = new NPR_API_Client(get_option(NPR_API_KEY_OPTION)); $story = $api->story_from_id($story_id); if (!$story) { // XXX: handle error return; } $poster = new Story_Poster(); $resp = $poster->update_post_from_story($story); $created = $resp[0]; $id = $resp[1]; if ($created) { $msg = sprintf('Created <a href="%s">%s</a> as a Draft.', get_edit_post_link($id), $story->title); } else { $msg = sprintf('Updated <a href="%s">%s</a>.', get_edit_post_link($id), $story->title); } $this->created_message = $msg; } }
function embed_callback($matches, $attr, $url, $rawattr) { $url = trim($url); global $post; $story_object = get_post_meta($post->ID, '_npr_api_' . md5($url), true); if (empty($story_object)) { $api = new NPR_API_Client(get_option(NPR_API_KEY_OPTION)); $story_object = $api->story_from_id(absint($matches[1])); update_post_meta($post->ID, '_npr_api_' . md5($url), $story_object); } return 'From <a href="' . esc_url($story_object->html_link) . '">' . $story_object->title . '</a>:' . "\n\n<blockquote>" . $story_object->teaser . "\n<cite><a href='" . esc_url($story_object->short_link) . "'>" . $story_object->short_link . '</a></cite></blockquote>'; }