Skip to content

Commit

Permalink
Do not require jetpack_require_lib() to exist on the site
Browse files Browse the repository at this point in the history
If `class WPCom_GHF_Markdown_Parser` already exists, then we can just
use it.

This allows site owners to integrate Markdown sync without requiring all
of Jetpack.  In this case they should copy the relevant code into their
site from here, and load it themselves:

https://github.com/Automattic/jetpack/tree/master/_inc/lib/markdown

As of this writing this code works independently of the rest of Jetpack.
  • Loading branch information
nylen committed Feb 26, 2020
1 parent d2c9fe1 commit eecfdb7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions wp-content/mu-plugins/markdown-sync/inc/class-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,14 @@ protected function update_post_from_markdown_source( $post_id ) {
if ( is_wp_error( $markdown_source ) ) {
return $markdown_source;
}
if ( ! function_exists( 'jetpack_require_lib' ) ) {
return new WP_Error( 'missing-jetpack-require-lib', 'jetpack_require_lib() is missing on system.' );
if (
! function_exists( 'jetpack_require_lib' ) &&
! class_exists( 'WPCom_GHF_Markdown_Parser' )
) {
return new WP_Error(
'missing-jetpack-require-lib',
'Missing `jetpack_require_lib()` or `class WPCom_GHF_Markdown_Parser`.'
);
}

// Transform GitHub repo HTML pages into their raw equivalents
Expand Down Expand Up @@ -330,7 +336,10 @@ protected function update_post_from_markdown_source( $post_id ) {
}

// Transform to HTML and save the post
jetpack_require_lib( 'markdown' );
if ( ! class_exists( 'WPCom_GHF_Markdown_Parser' ) ) {
// We checked for jetpack_require_lib() above.
jetpack_require_lib( 'markdown' );
}
$parser = new WPCom_GHF_Markdown_Parser();
$parser->preserve_shortcodes = false;
$html = $parser->transform( $markdown );
Expand Down

0 comments on commit eecfdb7

Please sign in to comment.