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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
<?php
namespace SIW\Compatibility;
use SIW\Properties;
class WordPress {
const REST_API_PREFIX = 'api';
const DEFAULT_EDITOR ='html';
public static function init() {
$self = new self();
add_action( 'widgets_init', [ $self, 'unregister_widgets'], 99 );
add_filter( 'nonce_life', [ $self, 'set_nonce_life' ] );
add_filter( 'oembed_response_data', [ $self, 'set_oembed_response_data' ] );
add_filter( 'rest_url_prefix', [ $self, 'set_rest_url_prefix' ] );
add_filter( 'user_contactmethods', [ $self, 'remove_user_contactmethods' ], PHP_INT_MAX );
add_action( 'after_setup_theme', [ $self, 'add_custom_logo_support'] );
add_action( 'init', [ $self, 'add_page_excerpt_support'] );
add_action( 'core_version_check_query_args', [ $self, 'remove_core_version_check_query_args'] );
add_action( 'wp_enqueue_scripts', [ $self, 'dequeue_styles' ], PHP_INT_MAX );
add_filter( 'wp_default_editor', [ $self, 'set_default_editor'] );
add_filter( 'site_status_tests', [ $self, 'remove_update_check'] );
add_filter( 'http_headers_useragent', [ $self, 'set_http_headers_useragent'] );
add_filter( 'big_image_size_threshold', [ $self, 'set_big_image_size_threshold'] );
add_action( 'do_feed', [ $self, 'disable_feed' ] , 1 );
add_action( 'do_feed_rdf', [ $self, 'disable_feed' ] , 1 );
add_action( 'do_feed_rss', [ $self, 'disable_feed' ] , 1 );
add_action( 'do_feed_rss2', [ $self, 'disable_feed' ] , 1 );
add_action( 'do_feed_atom', [ $self, 'disable_feed' ] , 1 );
add_action( 'do_feed_rss2_comments', [ $self, 'disable_feed' ] , 1 );
add_action( 'do_feed_atom_comments', [ $self, 'disable_feed' ] , 1 );
add_filter( '404_template', [ $self, 'set_404_template']);
add_filter( 'widget_text', 'do_shortcode' );
add_filter( 'safe_style_css', [ $self, 'add_allowed_css_attributes' ] );
add_filter( 'embed_oembed_html', [ $self, 'fix_youtube_embed' ] );
}
public function set_rest_url_prefix() {
return self::REST_API_PREFIX;
}
public function unregister_widgets() {
unregister_widget( 'WP_Widget_Pages' );
unregister_widget( 'WP_Widget_Recent_Posts' );
unregister_widget( 'WP_Widget_Calendar' );
unregister_widget( 'WP_Widget_Archives' );
if ( get_option( 'link_manager_enabled' ) ) {
unregister_widget( 'WP_Widget_Links' );
}
unregister_widget( 'WP_Widget_Meta' );
unregister_widget( 'WP_Widget_Categories' );
unregister_widget( 'WP_Widget_Recent_Comments' );
unregister_widget( 'WP_Widget_RSS' );
unregister_widget( 'WP_Widget_Tag_Cloud' );
unregister_widget( 'WP_Widget_Custom_HTML' );
unregister_widget( 'WP_Widget_Media_Audio' );
unregister_widget( 'WP_Widget_Media_Video' );
unregister_widget( 'WP_Widget_Media_Image' );
unregister_widget( 'WP_Widget_Media_Gallery' );
}
public function set_nonce_life() {
return 2 * DAY_IN_SECONDS;
}
public function set_oembed_response_data( array $data ) {
$data['author_name'] = Properties::NAME;
$data['author_url'] = SIW_SITE_URL;
return $data;
}
public function remove_user_contactmethods( array $contactmethods ) {
unset( $contactmethods['aim'] );
unset( $contactmethods['jabber'] );
unset( $contactmethods['yim'] );
return $contactmethods;
}
public function add_custom_logo_support() {
add_theme_support( 'custom-logo' );
}
public function add_page_excerpt_support() {
add_post_type_support( 'page', 'excerpt' );
}
public function remove_core_version_check_query_args( array $query ) {
unset( $query['local_package'] );
unset( $query['blogs'] );
unset( $query['users'] );
unset( $query['multisite_enabled'] );
unset( $query['initial_db_version'] );
return $query;
}
public function dequeue_styles() {
wp_dequeue_style( 'wp-block-library' );
}
public function disable_feed() {
wp_redirect( home_url() );
exit;
}
public function set_404_template() {
return SIW_TEMPLATES_DIR . '/404.php';
}
public function set_default_editor() {
return self::DEFAULT_EDITOR;
}
public function set_http_headers_useragent() {
return Properties::NAME;
}
public function set_big_image_size_threshold() {
return Properties::MAX_IMAGE_SIZE;;
}
public function remove_update_check( array $tests ) {
unset( $tests['async']['background_updates'] );
return $tests;
}
public function add_allowed_css_attributes( array $attributes ) {
$attributes[] = 'fill';
$attributes[] = 'opacity';
$attributes[] = 'transform';
$attributes[] = 'content';
return $attributes;
}
public function fix_youtube_embed( string $cache ) {
$regex = '/<iframe[^>]*(?<=src=")(https:\/\/www\.youtube\.com\/embed.*?)(?=[\"])/m';
preg_match( $regex, $cache, $matches );
if ( ! isset( $matches[1] ) ) {
return $cache;
}
$url_parts = parse_url( $matches[1] );
$url = $url_parts['scheme'] . '://' . 'www.youtube-nocookie.com' . $url_parts['path'];
$url = add_query_arg( [
'rel' => false,
'modestbranding' => true,
'controls' => true,
'fs' => false,
], $url );
return str_replace( $matches[1], $url, $cache );
}
}