How can I change the error message for a protected file or make it redirect to login?

By: Kim Clark | Asked: 07/11/2025
ForumsCategory: How-toHow can I change the error message for a protected file or make it redirect to login?
Kim Clark asked 4 months ago

Hello. I have setup a form for uploading private files. I would like to send a link to a protected file to a user and have that user either redirected to a login page or to receive a better error message than "Oops! This file is protected." How can I change the error message so I can add a login link to it? Thank you.

Bobby Clapp
Staff replied 4 months ago

Can you confirm it is a FF error message and not something from your hosting provider?

Kim Clark
replied 4 months ago

Yes, it is from this function in FF:
private static function handle_download_error( $download ) {
status_header( $download['code'] );

if ( 404 === $download['code'] ) {
$message = __( 'Oops! That file no longer exists', 'formidable-pro' );
} else {
$message = __( 'Oops! That file is protected', 'formidable-pro' );
}

$title = is_user_logged_in() ? $download['message'] : '';

wp_die(
'' . esc_html( $message ) . '',
'' . esc_html( $title ) . '',
absint( $download['code'] )
);
}

Bobby Clapp
Staff replied 4 months ago

Ok. So you've changed that second error message and have resolved the issue?

1 Answers

Best Answer

Kim Clark answered 4 months ago

No, I don't know how to change the message.

Victor Font
Staff replied 4 months ago

Changing this message requires use of the WordPress wp_die_handler filter hook. https://developer.wordpress.org/reference/hooks/wp_die_handler/

I've taken the liberty to write a code snippet for you. I have not tested this code. It should work, but I can't guarantee it.

You can copy the code into your functions.php or the code snippets plugin. Don't copy the "<?php" tag. If you need a developers help to get this working, please visit https://formidable-masterminds.com/developers-directory.

https://gist.github.com/vfontjr/731ef1f362ab8cdb1c1658a48f8a7afe

Kim Clark
replied 4 months ago

This worked. Thank you!

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right