“Draft Saved” is a translatable string, so it can be changed to anything else through the “gettext” filter. The callback you add to the filter needs to watch for that specific string, and only change it if the current user’s role is contributor.
“View Preview” should also be translatable, but I’ve not found it in the language files. IMO it ought to remain as-is anyway, even if you alter the other string.
Thank you @bcworkz for the reply.
I’m using following code with no luck. Can you say what’s wrong?
add_action('new_to_pending', 'amar_submit_notice');
add_action('auto-draft_to_pending', 'amar_submit_notice');
add_action('draft_to_pending', 'amar_submit_notice');
function amar_submit_notice() {
add_filter( 'gettext', 'change_submit_pending_notice');
}
function change_submit_pending_notice( $text ) {
$text = str_ireplace( 'Draft Saved.', 'Your post has been submitted.', $text );
return $text;
}
It looks like REACT based code like the block editor uses a different mechanism to translate strings separate from the PHP “gettext” filter. For example, using the string 'Post draft updated.' in your code works as expected in the classic editor.
There is a “Draft Saved” string in the normal gettext translation file used by PHP, but the “Draft saved.” string (note subtle differences) actually used by the block editor occurs in a translation .json file which doesn’t involve the PHP “gettext” filter.
There’s an equivalent mechanism within the REACT code, but sadly I don’t know much about how it works. The string has to occur somewhere in the script, so there has to be a way to override it, it’s the nature of JavaScript. I just don’t know exactly how to accomplish it.
Sorry to mislead you about a solution. In my defense it does work for PHP based strings 🙂
Thanks for your time. I would like to left the thread open hoping someone might come with a solution.