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.
Best Answer
No, I don't know how to change the message.
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
This worked. Thank you!
Please login or Register to submit your answer
Staff replied 4 months ago
Can you confirm it is a FF error message and not something from your hosting provider?
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'] )
);
}
Staff replied 4 months ago
Ok. So you've changed that second error message and have resolved the issue?