-
Notifications
You must be signed in to change notification settings - Fork 1
/
iet_custom_style.php
131 lines (103 loc) · 3.75 KB
/
iet_custom_style.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
<?php
/*
Plugin Name: IET Custom Style
Plugin URI: https://github.com/IET-OU/oer-evidence-hub-org
Description: Custom CSS for WordPress sites run by IET at The Open University [LACE]+
Author: Nick Freear [@IET-OU]
Author URI: https://github.com/IET-OU
Version: 0.2
*/
/** See also:
* @link https://github.com/IET-OU/oer-evidence-hub-org/blob/juxtalearn/custom-functions/my_custom_functions.php#L57
* @copyright Nick Freear, 30 September 2014.
*/
define( 'IET_CUSTOM_STYLE_REGISTER_FILE', __FILE__ ); #preg_replace('@^.*wp-content\/plugins@', '', __FILE__));
class IET_Custom_Style_Plugin {
protected $host;
public function __construct() {
$this->host = self::get_option( 'iet_custom_style_hostname', filter_input( INPUT_SERVER, 'HTTP_HOST' ));
if ($this->is_juxtalearn()) {
#$this->add_action( 'admin_enqueue_scripts', .. );
$this->add_action( 'admin_head', 'wp_head_style' );
}
if ($this->get_option( 'iet_custom_style_no_google_font' )) {
$this->add_action( 'wp_enqueue_scripts', 'wp_enqueue_scripts', 20 );
}
$this->add_action( 'wp_head', 'wp_head_style', 999 );
$this->add_action( 'wp_footer', 'wp_footer_javascript' );
$this->add_action( 'init', 'init_rewrites' );
// Search form shortcode [Bug: #39]
add_shortcode( 'iet_search_form', 'get_search_form' );
}
/** De-register remote Google Font styles for local devs.
*/
public function wp_enqueue_scripts() {
wp_deregister_style( 'tinyforge-fonts' );
wp_deregister_style( 'open-sans' );
}
/** Custom CSS styles.
*/
public function wp_head_style() {
$css_selector = self::get_option( 'iet_custom_style_menu_special_selector',
'.main-navigation ul > .menu-item-type-custom a[href *= clipit]' );
$custom_css = self::get_option( 'iet_custom_style_css' );
?>
<link id="iet-custom-style-link" rel="stylesheet" href="<?php echo plugins_url(
'css/iet-custom-style.css', IET_CUSTOM_STYLE_REGISTER_FILE ) ?>" />
<?php if ($custom_css): ?>
<style id="iet-custom-style-css">
<?php echo $custom_css ?>
</style>
<?php
endif;
$this->msie_print_shiv();
}
/** Javascript to add a <html> class based on the hostname.
*/
public function wp_footer_javascript() {
$host = json_encode( $this->host );
?>
<script>
//
document.documentElement.className += " " + (<?php echo $host ?> || document.location.hostname).replace(/\./g, "-");
</script>
<?php
}
/** Clean URLs [LACE]
*/
public function init_rewrites() {
add_rewrite_rule( "^(post-type|list)/([^/]+)/?",
'index.php?post_type=$matches[2]', 'top' );
add_rewrite_rule( "^([^/]+)/(full)?-?list/?",
'index.php?post_type=$matches[1]', 'top' );
}
/** HTML5 print shiv/shim for Internet Explorer [Bug: #31].
*/
protected function msie_print_shiv() {
if (!$this->is_juxtalearn()) return; ?>
<!--[if lt IE 9]>
<script src="<?php echo plugins_url(
'html5shiv/dist/html5shiv-printshiv.min.js',
IET_CUSTOM_STYLE_REGISTER_FILE ) ?>"></script>
<![endif]-->
<?php
}
/** Get values for a named option from the options database table.
* Uses WordPress `get_option()`. Falls back to a PHP defined() constant.
*
* @link https://codex.wordpress.org/Function_Reference/get_option
*/
public static function get_option( $key, $default = NULL ) {
$_KEY = strtoupper( $key );
$default = /*!$default &&*/ defined( $_KEY ) ? constant( $_KEY ) : $default;
return get_option( $key, $default );
}
protected function add_action( $hook, $function = '', $priority = 10 ) {
add_action( $hook, array( &$this, $function ), $priority );
}
protected function is_juxtalearn() {
return 'trickytopic.juxtalearn.net' == $this->host;
}
}
$iet_custom_style = new IET_Custom_Style_Plugin();
#End.