-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathjquery-filters.php
188 lines (161 loc) · 6.11 KB
/
jquery-filters.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
/**
* Plugin Name: jQuery Filters
* Description: Default filters for all jQuery sites.
*/
if ( defined( 'WP_INSTALLING' ) ) {
return;
}
require_once __DIR__ . '/../sites.php';
$options = jquery_default_site_options();
$sites = jquery_sites();
$options = array_merge( $options, $sites[ JQUERY_LIVE_SITE ]['options'] );
foreach ( $options as $option => $value ) {
// Skip these on live sites (both production and staging),
// where they are managed by puppet.
// Local testing with a fresh database does not
// currently work if these are skipped.
if ( JQUERY_STAGING !== 'local' ) {
if ( $option === 'stylesheet' || $option === 'template' ) {
// Don't mess with themes for now.
continue;
}
if ( $option === 'active_plugins' ) {
// On live sites (including staging ones),
// Puppet manages activation of per-site plugins.
continue;
}
}
add_filter( 'pre_option_' . $option, function () use ( $value ) {
return $value;
} );
}
unset( $sites, $options, $option );
// Ensure that the local port is used for template assets, if it exists.
add_filter( 'theme_root_uri', function( $value ) {
// All environment variables are set either in the local wp-config.php or via puppet.
// Staging sites set JQUERY_STAGING to the boolean `true` instead of 'local'.
// Production sites set it to false.
if ( JQUERY_STAGING === 'local' ) {
// Don't specify http vs https here, as the site may be accessed via either.
$siteurl = '//' . strtr( JQUERY_STAGING_FORMAT, [ '%s' => JQUERY_LIVE_SITE ] );
$value = $siteurl . '/wp-content/themes';
}
return $value;
});
// Remove misc links from <head> on non-blog sites
if ( !get_option( 'jquery_is_blog' ) ) {
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
// Remove shortlink <head> and header.
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10 );
remove_action( 'template_redirect', 'wp_shortlink_header', 11 );
// Disable WordPress auto-paragraphing for posts, except on actual blog sites
remove_filter( 'the_content', 'wpautop' );
}
// Disable WordPress text transformations (smart quotes, etc.) for posts.
remove_filter( 'the_content', 'wptexturize' );
// Disable more restrictive multisite upload settings.
remove_filter( 'upload_mimes', 'check_upload_mimes' );
// Give unfiltered upload ability to super admins.
define( 'ALLOW_UNFILTERED_UPLOADS', true );
// Until unfiltered uploads make it into XML-RPC:
add_filter( 'upload_mimes', function( $mimes ) {
$mimes['eot'] = 'application/vnd.ms-fontobject';
$mimes['svg'] = 'image/svg+xml';
$mimes['ttf'] = 'application/x-font-ttf';
$mimes['woff'] = 'application/font-woff';
$mimes['xml'] = 'text/xml';
$mimes['php'] = 'application/x-php';
$mimes['json'] = 'application/json';
return $mimes;
} );
// Increase file size limit to 1GB
add_filter( 'pre_site_option_fileupload_maxk', function() {
return 1024 * 1024;
} );
// Disable the new image sizes feature.
// It adds a style tag that would require a CSP exception.
add_filter( 'wp_img_tag_add_auto_sizes', '__return_false' );
// Allow full HTML in term descriptions.
add_action( 'init', 'jquery_unfiltered_html_for_term_descriptions' );
add_action( 'set_current_user', 'jquery_unfiltered_html_for_term_descriptions' );
function jquery_unfiltered_html_for_term_descriptions() {
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'pre_term_description', 'wp_filter_post_kses' );
if ( ! current_user_can( 'unfiltered_html' ) )
add_filter( 'pre_term_description', 'wp_filter_post_kses' );
}
// Bypass multisite checks.
add_filter( 'ms_site_check', '__return_true' );
// Add body classes found in postmeta.
add_filter( 'body_class', function( $classes ) {
$body_class_setting = get_option( 'jquery_body_class' );
if ( $body_class_setting ) {
array_unshift( $classes, $body_class_setting );
}
if ( strpos( JQUERY_LIVE_SITE, 'api.' ) === 0 ) {
array_unshift( $classes, 'api' );
}
if ( is_page() ) {
$classes[] = 'page-slug-' . sanitize_html_class( strtolower( get_queried_object()->post_name ) );
}
if ( is_singular() && $post_classes = get_post_meta( get_queried_object_id(), 'body_class', true ) ) {
$classes = array_merge( $classes, explode( ' ', $post_classes ) );
}
if ( is_archive() || is_search() ) {
$classes[] = 'listing';
}
return $classes;
});
add_filter( 'option_uploads_use_yearmonth_folders', '__return_false' );
add_filter( 'upload_dir', function( $upload_dir ) {
if ( defined( 'UPLOADS' ) ) {
$upload_dir['path'] = $upload_dir['basedir'] = UPLOADS;
} else {
$upload_dir['path'] = $upload_dir['basedir'] = WP_CONTENT_DIR . '/uploads';
}
return $upload_dir;
});
add_filter( 'get_terms', function( $terms, $taxonomies, $args ) {
if ( !isset( $args[ 'orderby' ] ) || $args[ 'orderby' ] !== 'natural' ) {
return $terms;
}
$sortedTerms = array();
foreach( $terms as $term ) {
$sortedTerms[ $term->name ] = $term;
}
uksort( $sortedTerms, 'strnatcasecmp' );
if ( strtolower( $args[ 'order' ] ) === 'desc' ) {
$sortedTerms = array_reverse( $sortedTerms );
}
return $sortedTerms;
}, 20, 3 );
add_filter( 'xmlrpc_wp_insert_post_data', function ( $post_data, $content_struct ) {
if ( $post_data['post_type'] !== 'page' ) {
return $post_data;
}
if ( isset( $content_struct['page_template'] ) ) {
$post_data['page_template'] = $content_struct['page_template'];
}
if ( isset( $content_struct['menu_order'] ) ) {
$post_data['menu_order'] = $content_struct['menu_order'];
}
return $post_data;
}, 10, 2 );
if ( JQUERY_STAGING && !defined( 'XMLRPC_REQUEST' ) ) {
ob_start( 'jquery_com_ob_local_urls' );
}
function jquery_com_ob_local_urls( $content ) {
$pairs = [];
foreach ( jquery_sites() as $site => $_ ) {
// Replace HTTPS with protocol-relative so navigation stays within HTTP locally.
$pairs[ 'https://' . $site ] = '//' . jquery_site_expand( $site );
// Update any remaining HTTP or protocol-relative urls.
$pairs[ '//' . $site ] = '//' . jquery_site_expand( $site );
}
return strtr( $content, $pairs );
}