Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Created March 16, 2016 09:09
Show Gist options
  • Save remcotolsma/8a89ede9d5bb48b66c35 to your computer and use it in GitHub Desktop.
Save remcotolsma/8a89ede9d5bb48b66c35 to your computer and use it in GitHub Desktop.
The Pronamic Manuals plugin allows you to easily add the GitHub manuals to your WordPress website.
{
"name": "remco/pronamic-manuals",
"authors": [
{
"name": "Remco Tolsma",
"email": "[email protected]"
}
],
"require": {
"michelf/php-markdown": "^1.6"
}
}
<?php
/*
Plugin Name: Pronamic Manuals
Plugin URI: http://www.pronamic.eu/plugins/pronamic-manuals/
Description: The Pronamic Manuals plugin allows you to easily add the GitHub manuals to your WordPress website.
Version: 1.0.0
Requires at least: 3.6
Author: Pronamic
Author URI: http://www.pronamic.eu/
Text Domain: pronamic-manuals
Domain Path: /languages/
License: GPL
GitHub URI: https://github.com/pronamic/wp-pronamic-manuals
*/
/**
* Autoload
*/
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
/**
* Shortcode
*
* @see https://michelf.ca/projects/php-markdown/configuration/
*/
function shortcode_manual() {
$content = '';
$url = 'https://raw.githubusercontent.com/wp-pay/test-suite/master/manuals/3.9.0/formidable/2.0.22/buckaroo/README.md';
$dir = dirname( $url );
$result = wp_remote_get( $url );
if ( 200 === wp_remote_retrieve_response_code( $result ) ) {
$content = wp_remote_retrieve_body( $result );
$parser = new \Michelf\Markdown();
$parser->header_id_func = function ( $header ) {
return sanitize_title( $header );
};
$parser->url_filter_func = function( $url ) use ( $dir ) {
if ( '#' === $url[0] ) {
return $url;
}
return $dir . '/' . $url;
};
$content = $parser->transform( $content );
}
return $content;
}
add_shortcode( 'manual', 'shortcode_manual' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment