Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'd like to sync my theme's README.markdown into a page on my site and would love to be able to only have to update that text a single time -- namely, when I commit my code up to BitBucket. I have my theme doing hg pull -u on a regular basis, so the code stays fresh and the README will get updated every time I make a change to the source, but my WordPress page containing the README then needs to get updated by hand.

(I'm using Mark Jaquith's Markdown on Save to do the MD->HTML dance.)

Any thoughts?

share|improve this question

2 Answers 2

I achieved that using WP-Cron capabilities.

add_action('wp', 'wpse_26170_activation');

function wpse_26170_activation() {
    if ( !wp_next_scheduled( 'wpse_26170_update_readme_page' ) ) {
        wp_schedule_event( current_time( 'timestamp' ), 'daily', 'wpse_26170_update_readme_page');
    }
}

function wpse_26170_update_readme_page() {
    $page = array(
        'ID'           => 767,
        'post_content' => Markdown( file_get_contents( 'path/to/readme.markdown' ) )
    );

    if (
        // Filters return true if they existed before you removed them
        remove_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' ) &&
        remove_filter( 'content_save_pre', 'wp_filter_post_kses' )
    ) {
        $page['post_content'] = wp_kses_post( $page['post_content'] );
    }

    wp_update_post($page);
}

Now this cron job should run every day updating the page with readme, please note that you have to change 'ID' with your page ID and path to the Markdown file.

If you have troubles getting cron to run please read the following post from Nettuts http://wp.tutsplus.com/articles/insights-into-wp-cron-an-introduction-to-scheduling-tasks-in-wordpress/

Also you still need Markdown On Save plugin because this function uses Markdown class from it.

Actually you can just call the wpse_26170_update_readme_page functions after doing hg pull -u.

share|improve this answer

You may parse the markdown file and show the contents in the page with some method, say with shortcode. When you update the file, it'll automatically updated. Cause, it'll be parsing the markdown file and serving the HTML automatically.

share|improve this answer
    
Displaying the content of a static file isn't quite what I'm looking for, as this puts the content outside of WordPress' search capabilities. I want the data stored as a post inside of wp_posts for all the advantages that provides. –  ZaMoose Aug 22 '11 at 13:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.