Skip to content

Instantly share code, notes, and snippets.

@shirokoweb
Last active August 24, 2022 13:10
Show Gist options
  • Save shirokoweb/f87bd0b401450443f156873c67fb49e8 to your computer and use it in GitHub Desktop.
Save shirokoweb/f87bd0b401450443f156873c67fb49e8 to your computer and use it in GitHub Desktop.
Sample functions.php
<?php
// remove API access
// https://developer.wordpress.org/rest-api/using-the-rest-api/frequently-asked-questions/
add_filter( 'rest_authentication_errors', function( $result ) {
if ( ! empty( $result ) ) {
return $result;
}
if ( ! is_user_logged_in() ) {
return new WP_Error( 'rest_not_logged_in', 'You are not currently logged in.', array( 'status' => 401 ) );
}
return $result;
});
// Disable xmlrpc
add_filter( 'xmlrpc_enabled', '__return_false' );
remove_action( 'wp_head', 'rsd_link' );
// Remove Divi calls to Google fonts API
function remove_google_fonts() {
wp_dequeue_style( 'divi-fonts' );
wp_dequeue_style( 'et-gf-open-sans' );
} add_action( 'wp_enqueue_scripts', 'remove_google_fonts', 20 );
// Remove dashicons from frontend
function wpdocs_dequeue_dashicon() {
if (current_user_can( 'update_core' )) {
return;
}
wp_deregister_style('dashicons');
} add_action( 'wp_enqueue_scripts', 'wpdocs_dequeue_dashicon' );
// Enqueue activelink.js only on mission examples page
function conditional_enqueue_stuff() {
if ( is_page( 'mission-examples' ) ) {
wp_enqueue_script('active-link', get_stylesheet_directory_uri() . '/js/activelink.js', array(), FALSE, TRUE);
}
} add_action( 'wp_enqueue_scripts', 'conditional_enqueue_stuff' );
// enable divi functions
function my_enqueue_assets() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
wp_enqueue_script('jquery-sticky', get_stylesheet_directory_uri() . '/js/theia-sticky-sidebar.min.js', array(), FALSE, TRUE);
} add_action( 'wp_enqueue_scripts', 'my_enqueue_assets' );
/**
* Disable the emoji's
*/
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
add_filter( 'wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2 );
} add_action( 'init', 'disable_emojis' );
/**
* Filter function used to remove the tinymce emoji plugin.
*
* @param array $plugins
* @return array Difference betwen the two arrays
*/
function disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}
/**
* Remove emoji CDN hostname from DNS prefetching hints.
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed for.
* @return array Difference betwen the two arrays.
*/
function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) {
if ( 'dns-prefetch' == $relation_type ) {
// Strip out any URLs referencing the WordPress.org emoji location
$emoji_svg_url_bit = 'https://s.w.org/images/core/emoji/';
foreach ( $urls as $key => $url ) {
if ( strpos( $url, $emoji_svg_url_bit ) !== false ) {
unset( $urls[$key] );
}
}
}
return $urls;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment