-
-
Save brichards/94c384e30fa966aaac3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Output HTML markup for forum post list. | |
* | |
* @since 1.0.0 | |
* | |
* @param integer $post_count Post count. | |
*/ | |
function skbp_output_forum_posts_list( $post_count = 5 ) { | |
echo skbp_get_forum_posts_list( $post_count ); | |
} | |
/** | |
* Generate HTML markup for forum post list. | |
* | |
* @since 1.0.0 | |
* | |
* @param integer $post_count Post count. | |
* @return string HTML Markup. | |
*/ | |
function skbp_get_forum_posts_list( $post_count = 5 ) { | |
$xml = simplexml_load_string( skbp_get_forum_posts_xml() ); | |
$output = ''; | |
$output .= '<h3>' . __( 'Recent Forum Threads', 'skbp' ) . '</h3>'; | |
$output .= '<ul>'; | |
for ( $i = 0; $i < absint( $post_count ); $i++ ) { | |
$output .= '<li>' . skbp_get_forum_post_link( $xml->channel->item[ $i ] ) . '</li>'; | |
} | |
$output .= '</ul>'; | |
return $output; | |
} | |
/** | |
* Retrieve recent forum post XML data. | |
* | |
* @since 1.0.0 | |
* | |
* @return string XML data. | |
*/ | |
function skbp_get_forum_posts_xml() { | |
$forum_feed_xml = get_transient( 'skbp_get_forum_posts_xml' ); | |
if ( false === $forum_feed_xml ) { | |
$get_sat_posts = wp_remote_get( 'https://helpforum.covenanteyes.com/covenanteyes/topics.rss?sort=created_at' ); | |
$forum_feed_xml = wp_remote_retrieve_body( $get_sat_posts ); | |
set_transient( 'skbp_get_forum_posts_xml', $forum_feed_xml, 2 * DAY_IN_SECONDS ); | |
} | |
return maybe_unserialize( $forum_feed_xml ); | |
} | |
/** | |
* Generate HTML markup for a single forum post link. | |
* | |
* @since 1.0.0 | |
* | |
* @param object $item XML item object. | |
* @return string HTML Markup. | |
*/ | |
function skbp_get_forum_post_link( $item = null ) { | |
return is_object( $item ) | |
? sprintf( | |
'<a href="%1$s">%2$s</a>', | |
$item->link, | |
$item->title | |
) | |
: ''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment