Skip to content

Instantly share code, notes, and snippets.

@vfontjr
Created July 11, 2025 21:30
Show Gist options
  • Save vfontjr/731ef1f362ab8cdb1c1658a48f8a7afe to your computer and use it in GitHub Desktop.
Save vfontjr/731ef1f362ab8cdb1c1658a48f8a7afe to your computer and use it in GitHub Desktop.
Kim Clark Community Forum Response
<?php
add_filter( 'wp_die_handler', 'my_custom_wp_die_handler' );
function my_custom_wp_die_handler( $handler ) {
return 'my_override_wp_die';
}
function my_override_wp_die( $message, $title = '', $args = array() ) {
if ( trim( $message ) === 'Oops! This file is protected.' ) {
$message = 'This file is protected. <a href="' . esc_url( wp_login_url() ) . '">Please log in</a> to access it.';
$title = 'Protected File';
}
// Fallback to normal error for other cases
if ( ! isset( $args['back_link'] ) ) {
$args['back_link'] = true;
}
return _default_wp_die_handler( $message, $title, $args );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment