Created
August 10, 2017 22:12
-
-
Save craigcook/74d454eede2f43390dc1f5071d004723 to your computer and use it in GitHub Desktop.
moz_custom.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Mozilla Custom Plugins | |
Plugin URI: https://blog.mozilla.org | |
Description: Does custom things that we need | |
Version: .2 | |
Author: Jeremiah Orem, Craig Cook | |
*/ | |
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'); | |
} | |
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'); | |
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'); | |
function moz_strip_domain($authorname) { | |
return preg_replace('/@.*/','',$authorname); | |
} | |
add_filter('the_author','moz_strip_domain'); | |
add_filter('get_comment_author','moz_strip_domain'); | |
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); | |
function moz_no_cache_comments() { | |
if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) | |
nocache_headers(); | |
} | |
add_action('init', 'moz_no_cache_comments', 12); | |
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'); | |
// Outputs blog.mozilla.org google analytics JS scripts prior to the end | |
// of the header in every Mozilla blog. | |
function moz_add_webanalytics_js() { | |
$blog_name = get_bloginfo('name'); | |
$blog_id = get_current_blog_id(); | |
// Add temporary exception for theglassroomnyc.org. See bug 1309025. | |
if ($blog_id != '258') : | |
echo <<<GA_END | |
<script type="text/javascript"> | |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); | |
ga('create', 'UA-36116321-4', 'auto'); | |
ga('set', 'dimension1', '$blog_name'); | |
ga('send', 'pageview'); | |
</script> | |
GA_END; | |
endif; | |
} | |
add_action('wp_head', 'moz_add_webanalytics_js'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment