Ejemplo n.º 1
0
 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;
         }
         $resp = $api->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;
     }
 }