-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzeaks-code-snippets.php
86 lines (68 loc) · 2.59 KB
/
zeaks-code-snippets.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*
Plugin Name: Zeaks Code snippets
Plugin URI: http://zeaks.org
Description: Add code snippets to your posts.
Version: 2.1.1
Author: Zeaks
Author URI: http://zeaks.org
License: GPL2
*/
// Enqueue Scripts
function sunprettify_script_loader() {
wp_enqueue_script('zeaks_code_highlight', plugins_url( 'js/highlight.pack.js', __FILE__ ), array('jquery'),'', false );
}
add_action('wp_enqueue_scripts', 'sunprettify_script_loader');
// Enqueue Styles
function sunprettify_style_loader() {
wp_enqueue_style('zeaks_code_style', plugins_url( 'css/style.css', __FILE__ ), true ,'1.0', 'all' );
}
add_action('wp_enqueue_scripts', 'sunprettify_style_loader', 50 );
// Loading the needed prettyprint() function in the body
function sunprettify_auto_loading() { ?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('pre code').each(function(i, e) {
hljs.highlightBlock(e, ' ')
});
});
</script>
<?php }
add_action('wp_footer', 'sunprettify_auto_loading');
// Necessary to display the shortcode in comments
add_filter( 'get_comment_text', 'do_shortcode' ); //Warning, doing it this way adds ALL shortcodes to forum topics
add_filter( 'bbp_get_reply_content', 'do_shortcode' ); //Warning, doing it this way adds ALL shortcodes to forum replies
add_filter( 'bp_get_activity_content_body', 'do_shortcode' ); //Warning, doing it this way adds ALL shortcodes to forum replies
add_filter( 'bp_get_the_topic_post_content', 'do_shortcode' ); //Warning, doing it this way adds ALL shortcodes to forum replies
class zeaks_code_snippets {
function __construct()
{
remove_filter('the_content','wpautop');
add_filter('the_content','wpautop',99);
add_shortcode('code', array(&$this,'replace_code'));
add_filter('the_excerpt_rss',array(&$this,'strip_shortcodes'));
add_filter('the_content_rss',array(&$this,'strip_shortcodes'));
add_filter('the_excerpt',array(&$this,'strip_shortcodes'),1);
add_filter('the_content',array(&$this,'strip_shortcodes'),99);
if(is_admin()) {
$plugin = plugin_basename(__FILE__);
}
}
function replace_code($atts,$content)
{
if(version_compare(PHP_VERSION,'5.2.3')== -1) {
$content ='<pre>'.htmlspecialchars($content,ENT_NOQUOTES,'UTF-8').'</pre>';
} else {
$content ='<pre><code>'.htmlspecialchars($content,ENT_NOQUOTES,'UTF-8',false).'</code></pre>';
}
return $content;
}
function strip_shortcodes($content)
{
$content=str_replace('[code]','<pre><code>',$content);
$content=str_replace('[/code]','</pre></code>',$content);
return $content;
}
}
$zeaks_code_snippets = new zeaks_code_snippets();
?>