-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmozilla-custom.php
155 lines (133 loc) · 5.88 KB
/
mozilla-custom.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/*
Plugin Name: Mozilla Custom Plugins
Plugin URI: https://blog.mozilla.org
Description: Does custom things that we need
Version: .4
Author: Jeremiah Orem, Craig Cook, Maureen Holland
*/
// Our plugin
define('MOZ_PLUGIN_BASE', __FILE__);
// Allow changing the version number in only one place (the header above)
$plugin_data = get_file_data(MOZ_PLUGIN_BASE, array('Version' => 'Version'));
define('MOZ_PLUGIN_VERSION', $plugin_data['Version']);
// Setup Moz plugin url (must be in mu-plugins)
if (is_multisite()) {
define('MOZ_PLUGIN_URL', network_site_url('/wp-content/mu-plugins/mozilla-custom'));
} else {
define('MOZ_PLUGIN_URL', content_url('/mu-plugins/mozilla-custom'));
}
// Force HTTPS for some pages
function moz_ob_handler($buffer) {
$admin_url = get_option('siteurl') . '/wp-admin';
$login_url = get_option('siteurl') . '/wp-login.php';
$comment_url = get_option('siteurl') . '/wp-comments-post.php';
$secure_admin_url = preg_replace('/^https?/', 'https', $admin_url);
$secure_login_url = preg_replace('/^https?/', 'https', $login_url);
$secure_comment_url = preg_replace('/^https?/', 'https', $comment_url);
$replace_this = array($admin_url, $login_url, $comment_url);
$with_this = array($secure_admin_url, $secure_login_url, $secure_comment_url);
if ( is_admin() ) {
$includes_url = get_option('siteurl') . '/wp-includes';
$includes_url = preg_replace('/^https?/', 'http', $includes_url);
$secure_includes_url = preg_replace('/^https?/', 'https', $includes_url);
$replace_this[] = $includes_url;
$with_this[] = $secure_includes_url;
}
if ((is_preview() && 'on' == $_SERVER['HTTPS'])
|| preg_match('/wp-login.php$/',$_SERVER['SCRIPT_FILENAME']) ) {
$site_url = get_option('siteurl');
$site_url = preg_replace('/^https?/', 'http', $site_url);
$secure_site_url = preg_replace('/^https?/', 'https', $site_url);
$replace_this[] = $site_url;
$with_this[] = $secure_site_url;
}
return (str_replace($replace_this, $with_this, $buffer));
}
function moz_register_ob_handler() {
ob_start('moz_ob_handler');
}
// Use full email for usernames
function moz_uid_to_email($userid) {
$details = get_userdata($userid);
update_user_status($userid, 'user_login', $details->user_email);
}
add_action('wpmu_new_user', 'moz_uid_to_email');
// Do something with trackback authors
function moz_trackback_author_switch($commentdata) {
if ($commentdata['comment_type'] == 'trackback') {
$matches = array();
if (preg_match('/^<strong>(.*?)<\/strong>/', $commentdata['comment_content'], $matches)) {
$commentdata['comment_author'] = $matches[1];
}
}
$commentdata['comment_author_IP'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
return $commentdata;
}
add_filter('preprocess_comment', 'moz_trackback_author_switch');
// Strip the email domain from author names
function moz_strip_domain($authorname) {
return preg_replace('/@.*/','',$authorname);
}
add_filter('the_author','moz_strip_domain');
add_filter('get_comment_author','moz_strip_domain');
// Remove some post filtering
function moz_remove_post_filtering() {
remove_filter('content_save_pre', 'wp_filter_post_kses');
// remove_filter('excerpt_save_pre', 'wp_filter_post_kses');
// remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
}
add_action('init', 'moz_remove_post_filtering', 11);
// Don't cache comments
function moz_no_cache_comments() {
if (isset($_COOKIE['comment_author_'.COOKIEHASH]))
nocache_headers();
}
add_action('init', 'moz_no_cache_comments', 12);
// Add more file types to allowed uploads
function moz_add_upload_mimes($mimes) {
$mimes['otf'] = 'application/octet-stream';
$mimes['webm'] = 'video/webm';
$mimes['ogv'] = 'video/ogg';
$mimes['mp4'] = 'video/mp4';
$mimes['m4v'] = 'video/mp4';
$mimes['flv'] = 'video/x-flv';
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'moz_add_upload_mimes');
// Add XSS-Protection header
function moz_http_headers() {
header('X-XSS-Protection: 1; mode=block');
}
add_action('init', 'moz_http_headers');
// Add meta tag for the blog name; ga-snippet.js needs this.
function moz_meta_blogname() {
echo '<meta name="blog-name" content="' . esc_attr(get_bloginfo('name')) . '" />' . "\n";
}
add_action('wp_head', 'moz_meta_blogname', 1);
// Loads the blog.mozilla.org Google Analytics snippet in the head
// of every blog.
function moz_add_webanalytics() {
$blog_id = get_current_blog_id();
// No GA on 258, theglassroomnyc.org. See bug 1309025.
// No GA on 242, hacks.mozilla.org. Hacks uses their own tracking ID, not the global snippet.
if ($blog_id != '258' && $blog_id != '242') :
wp_enqueue_script('ga-snippet', MOZ_PLUGIN_URL . '/ga-snippet.js', '', MOZ_PLUGIN_VERSION);
endif;
}
add_action('wp_enqueue_scripts', 'moz_add_webanalytics');
// Add Co-authors in RSS and other feeds
// /wp-includes/feed-rss2.php uses the_author(), so we selectively filter the_author value
function moz_coauthors_in_rss($the_author) {
if (!is_feed() || !function_exists('coauthors')){
// if it's not a feed or coauthors is disabled, return regular author
return $the_author;
}
else{
// return coauthors
return coauthors(null, null, null, null, false);
}
}
add_filter('the_author', 'moz_coauthors_in_rss');
?>