/** * Clear the transient cache when postmeta updated with new values * * @since 1.0 * @see update_metadata() * @param $meta_id meta_id value from database row * @param int $post_id post identifier * @param string $meta_key the key of the updated field * @param string $meta_value the new value */ public static function clear_cache($meta_id, $post_id, $meta_key, $meta_value) { if ($meta_key !== 'angellist-companies') { return; } $post_id = absint($post_id); if ($post_id < 1) { return; } if (!class_exists('AngelList_Content')) { include_once dirname(__FILE__) . '/content.php'; } // key differs based on is_ssl boolean value. trigger both foreach (array(true, false) as $ssl) { delete_transient(AngelList_Content::cache_key($post_id, $ssl)); } }
/** * Append AngelList content to post content * * @since 1.0 * @param string post content * @return string post content with AngelList content appended */ public function content($content) { global $post; if (!(in_the_loop() && isset($post) && $content && isset($this->company_ids) && is_array($this->company_ids))) { return $content; } $post_id = absint($post->ID); if ($post_id < 1) { return $content; } $cache_key = AngelList_Content::cache_key($post_id, is_ssl()); $angellist_content = get_transient($cache_key); if (empty($angellist_content)) { $angellist_content = AngelList_Content::generate_content($this->company_ids); // store markup for one hour. // speeds up page generation, takes heat off the AngelList API server if ($angellist_content) { set_transient($cache_key, $angellist_content, 3600); } } unset($cache_key); // add a newline to separate new content from the last line of a post // avoids possible errors with oEmbed or other single-line detected content on the last line when priority < 10 if ($angellist_content) { return $content . "\n" . $angellist_content; } return $content; }