-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-plugin-markdown.php
48 lines (40 loc) · 1.4 KB
/
wp-plugin-markdown.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Plugin Name: BP Markdown
* Description: Adds support for Markdown and SmartyPants.
* Author: Bruce Phillips
* Requires PHP: 7.0.
*/
use Michelf\Markdown;
use Michelf\SmartyPantsTypographer;
if (!defined('ABSPATH')) {
@header('HTTP/1.1 404 Not Found');
exit;
}
class BPWP_MarkdownPlugin
{
public static function markdown(string $content): string
{
return Markdown::defaultTransform($content);
}
public static function smartyPants(string $content): string
{
return SmartyPantsTypographer::defaultTransform($content);
}
public static function removeQuicktags(array $qtInit)
{
$qtInit['buttons'] = true; // a non-empty value without further meaning
return $qtInit;
}
}
add_filter('quicktags_settings', BPWP_MarkdownPlugin::class.'::removeQuicktags', 5);
add_filter('the_content', BPWP_MarkdownPlugin::class.'::markdown', 15);
add_filter('the_content', BPWP_MarkdownPlugin::class.'::smartyPants', 20);
add_filter('the_excerpt', BPWP_MarkdownPlugin::class.'::markdown', 15);
add_filter('the_excerpt', BPWP_MarkdownPlugin::class.'::smartyPants', 20);
add_filter('the_title', BPWP_MarkdownPlugin::class.'::smartyPants', 20);
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
remove_filter('the_excerpt', 'wpautop');
remove_filter('the_excerpt', 'wptexturize');
remove_filter('the_title', 'wptexturize');