PHP
/* 1. Loginseite
--------------------------------------------------------------------------------- */
// deaktiviert den Sprachwechsler
add_filter( 'login_display_language_dropdown', '__return_false');
// deaktiviert den "zurück zum Blog" Link
add_filter( 'login_site_html_link' , '__return_false' );
// passt die Fehlertextanzeige bei falschem Login an
function gw_custom_login_errors() {
return 'Da passt etwas nicht.';
}
add_filter( 'login_errors', 'gw_custom_login_errors' );
/* 2. WordPress Adminbar
--------------------------------------------------------------------------------- */
// deaktiviert verschiedene Menüpunkte in der Adminbar
function gw_disable_adminbar_links() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo');
$wp_admin_bar->remove_menu('comments');
$wp_admin_bar->remove_menu('new-content');
$wp_admin_bar->remove_menu('themes');
$wp_admin_bar->remove_menu('widgets');
$wp_admin_bar->remove_menu('view-site');
$wp_admin_bar->remove_menu('customize');
$wp_admin_bar->remove_menu('menus');
$wp_admin_bar->remove_menu('dashboard');
$wp_admin_bar->remove_menu('edit-profile');
$wp_admin_bar->remove_menu('user-info');
$wp_admin_bar->remove_menu('search');
}
add_action( 'wp_before_admin_bar_render', 'gw_disable_adminbar_links' );
// löscht den Howdy Text in der Adminbar
function gw_remove_howdy($wp_admin_bar)
{
$my_account = $wp_admin_bar->get_node('my-account');
$greeting = str_replace('Willkommen,', '', $my_account->title);
$wp_admin_bar->add_node([
'id' => 'my-account',
'title' => $greeting,
]);
}
add_filter( 'admin_bar_menu', 'gw_remove_howdy' );
/* 3. WordPress Dashboard Widgets
--------------------------------------------------------------------------------- */
// deaktiviert alle Dashboard Widgets
function gw_disable_dashboard_widgets()
{
remove_action('welcome_panel', 'wp_welcome_panel');
remove_meta_box('dashboard_primary', 'dashboard', 'side');
remove_meta_box('dashboard_secondary', 'dashboard', 'side');
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
remove_meta_box('dashboard_php_nag', 'dashboard', 'normal');
remove_meta_box('dashboard_browser_nag', 'dashboard', 'normal');
remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
remove_meta_box('health_check_status', 'dashboard', 'normal');
remove_meta_box('dashboard_activity', 'dashboard', 'normal');
remove_meta_box('dashboard_right_now', 'dashboard', 'normal');
remove_meta_box('network_dashboard_right_now', 'dashboard', 'normal');
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal');
remove_meta_box('dashboard_plugins', 'dashboard', 'normal');
}
add_action( 'wp_dashboard_setup', 'gw_disable_dashboard_widgets' );
// deaktiviert die Hilfe Box
function gw_remove_helpbox(){
global $current_screen;
$current_screen->remove_help_tabs();
}
add_filter( 'contextual_help_list','gw_remove_helpbox' );
// deaktiviert Anwendungspasswörter
add_filter( 'wp_is_application_passwords_available', '__return_false' );
/* 4. CSS Styles in WordPress Backend
--------------------------------------------------------------------------------- */
function gw_backend_styles() {
if(is_admin()){
echo '<style type="text/css">
input#delete_all {
background: red !important;
color: white !important;
border-color: red !important;
}
</style>';
}
}
add_action('admin_head', 'gw_backend_styles');
// ändert anzeige unten im wp backend footer
function gw_change_wp_footer_text () {
echo '<span id="footer-thankyou">Entwickelt von <a href="https://galliweb.ch" target="_blank">Galli Web</a></span>';
}
add_filter( 'admin_footer_text', 'gw_change_wp_footer_text' );
/* 5. Clear WP Head
--------------------------------------------------------------------------------- */
add_filter( 'rest_enabled', '__return_false' );
add_filter( 'rest_jsonp_enabled', '__return_false' );
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'wp_shortlink_wp_head' );
remove_action( 'wp_head', 'rest_output_link_wp_head' );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'wp_resource_hints', 2, 99 );
add_filter('xmlrpc_enabled', '__return_false');
remove_action('embed_head', 'rel_canonical');
add_filter('wpseo_canonical', '__return_false');
// Remove dashicons in frontend for unauthenticated users
function bs_dequeue_dashicons() {
if ( ! is_user_logged_in() ) {
wp_deregister_style( 'dashicons' );
wp_deregister_style( 'wp-block-library' );
}
}
add_action( 'wp_enqueue_scripts', 'bs_dequeue_dashicons' );
// entfernt jQuery Migrate im Frontend
function gw_remove_jquery_migrate($scripts)
{
if (!is_admin() && isset($scripts->registered['jquery'])) {
$script = $scripts->registered['jquery'];
if ($script->deps) { // Check whether the script has any dependencies
$script->deps = array_diff($script->deps, array(
'jquery-migrate'
));
}
}
}
add_action( 'wp_default_scripts', 'gw_remove_jquery_migrate' );
// remove WP Version alltogether
// Pick out the version number from scripts and styles
function remove_version_from_style_js( $src ) {
if ( strpos( $src, 'ver=' . get_bloginfo( 'version' ) ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_version_from_style_js');
add_filter( 'script_loader_src', 'remove_version_from_style_js');
/* 6. Remove Emojis
--------------------------------------------------------------------------------- */
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 ) {
/** This filter is documented in wp-includes/formatting.php */
$emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );
$urls = array_diff( $urls, array( $emoji_svg_url ) );
}
return $urls;
}