dashed-slug.net › Forums › General discussion › sweet alerts help – Not Urgent
Tagged: alert, dialog, i18n, line break, modal, string, sweetalert
- This topic has 5 replies, 2 voices, and was last updated 5 years, 8 months ago by megeanwasson.
-
AuthorPosts
-
February 7, 2019 at 10:23 am #5844megeanwassonParticipant
Hi Alex,
This is such a cool addition 🙂
I have figured out how to style the alerts with css.
I would however also like to change how the text inside the alert is displayed (not the styling)In File: /plugins/wallets/includes/wallets-ko-i18n.php on line 43 you have the alert message:
__( 'Successfully submitted a withdrawal request of %1$s %2$s to %3$s Please check your e-mail for confirmation instructions.', 'wallets-front' )
In the text above I have tried <br /> and \n \r\n but none of those usual methods work, they end up just showing those codes instead of doing the actual linebreaks.I would like to have it display like this inside the alert box:
Successfully submitted a withdrawal request of:<br />
%1$s %2$s<br />
to %3$s<br />
Please check your e-mail for confirmation instructions.I am not sure how to do that, none of the solutions on google search works.
Your insight to this would be most useful.
Regards
MeganFebruary 7, 2019 at 10:42 am #5846alexgKeymasterHello Megan,
If you change the single quotes to double quotes, then you can use escaped characters. You should be able to use
\n
to do a line break. If you are interested, you can learn more about this here.Don’t forget to use the filter to replace the strings, so as not to have to apply your changes to the plugin on every update.
with regards
EDIT: This solution is not entirely correct. Please stand by and I will give you a full example of how to do this shortly.
February 7, 2019 at 11:02 am #5848megeanwassonParticipantHey Alex 🙂
I tried with double quotes did not work, but definitely your link to the php explanation did help. This is what worked, was so simple I did not even think to try it before.if ( Dashed_Slug_Wallets::get_option( ‘wallets_confirm_withdraw_user_enabled’ ) ) {
$translation_array[‘submit_wd’] = apply_filters(
‘wallets_ui_text_submit_wd’,
__( ‘Successfully submitted a withdrawal request of:
%1$s %2$s
to %3$s
Please check your e-mail for confirmation instructions.’, ‘wallets-front’ ));
That worked like a charm 🙂February 7, 2019 at 11:02 am #5849alexgKeymasterThe problem with the above solution is that once you switch to double quotes, the sprintf placeholders get interpreted by PHP as inline variables, so the
$
signs need to be escaped.The complete solution suffers from a mild case of LTS, and it is this:
function filter_wallets_ui_text_submit_wd( $string ) { return "Successfully submitted a withdrawal request of %1\$s %2\$s to %3\$s.\nPlease check your e-mail for confirmation instructions."; } add_filter( 'wallets_ui_text_submit_wd', 'filter_wallets_ui_text_submit_wd' );
February 7, 2019 at 11:03 am #5850alexgKeymasterMegan I saw your reply after I posted mine. Good job, but please see my earlier comment about using the filter to avoid problems on plugin updates.
February 7, 2019 at 11:07 am #5851megeanwassonParticipantYes Thank You I always use filters 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.