Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to embed my code at BitBucket in wp post, anyone can suggest me, a good plugin or anytrick to do it?

share|improve this question

1 Answer

Here try the below code, it should give you a good start.

// requrires 3 arguments
// user, project, path
// usage e.g: [bitbucket user="jespern" project="django-piston" path="piston/utils.py"]
function bitbucket_code( $atts ) {
    extract( $atts );
    global $post;
    $path_to_name = str_replace("/", "_", $path);
    $meta_key = "bitbucket_{$user}_{$project}_{$path_to_name}";
    $code = get_post_meta( $post->ID, $meta_key, true );
    if ( !$code ) {
        $bitbucket_url = "https://api.bitbucket.org/1.0/repositories/$user/$project/raw/tip/$path";
        // just in case its not there ;)
        if( !class_exists( 'WP_Http' ) )
                include_once( ABSPATH . WPINC. '/class-http.php' );
        $request = new WP_Http();
        $response = $request->request( $bitbucket_url );
        $code = htmlentities( $response['body'] );
        update_post_meta( $post->ID, $meta_key, $code );
    }
    return '<pre>'. $code . '</pre>';
}               
add_shortcode('bitbucket', 'bitbucket_code');
share|improve this answer

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.