Forum Moderators: coopster

Message Too Old, No Replies

Line break on PHP file

Add a line break

         

cm35

1:23 am on Sep 16, 2021 (gmt 0)



Hello everyone,

I am a complete beginner to programming and would like to have your help to be able to do a newline on a PHP file.

Here is the text as it appears in the email sent to the customers through Wordpress :

Voici le récapitulatif de votre commande effectuée sur XXX. Veuillez procéder au règlement de la facture via ce lien sécurisé : Payer pour cette commande - Pay for this order. Here is the summary of your order made on XXX. Please proceed to the payment of the invoice via this secure link: Payer pour cette commande - Pay for this order

I would like a line break between the French and English text as follows:

Voici le récapitulatif de votre commande effectuée sur XXX. Veuillez procéder au règlement de la facture via ce lien sécurisé : Payer pour cette commande - Pay for this order

Here is the summary of your order made on XXX. Please proceed to the payment of the invoice via this secure link: Payer pour cette commande - Pay for this order

I tried to use \ n "\ n" or even r \ n \ between the two texts but it doesn't work.

Here is the code :
<?php if ( $order->needs_payment() ) { ?>
<p>
<?php
printf(
wp_kses(
/* translators: %1$s Site title, %2$s Order pay link */
__( 'Voici le récapitulatif de votre commande effectuée sur %1$s. Veuillez procéder au règlement de la facture via ce lien sécurisé: %2$s Here is the summary of your order made on %1$s. Please proceed to the payment of the invoice via this secure link: %2$s', 'woocommerce' ),
array(
'a' => array(
'href' => array(),
),
)
),
esc_html( get_bloginfo( 'name', 'display' ) ),
'<a href="' . esc_url( $order->get_checkout_payment_url() ) . '">' . esc_html__( 'Payer pour cette commande - Pay for this order', 'woocommerce' ) . '</a>'
);
?>
</p>


If anyone had a tip for a newline between the two texts, that would be great.

Thanks in advance for your time.

CM

lucy24

2:37 am on Sep 16, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I tried to use \ n "\ n" or even r \ n \ between the two texts but it doesn't work.
Did you mean within the two texts? In any case, if you’re outputting html--as implied by the <a href> bit--it would have to be an html line break, which is <br>.

NickMNS

2:42 am on Sep 16, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if you’re outputting html--as implied by the <a href>

Or better yet:

<p>Voici le récapitulatif de votre commande effectuée sur XXX. Veuillez procéder au règlement de la facture via ce lien sécurisé : Payer pour cette commande</p>
<p>Pay for this order. Here is the summary of your order made on XXX. Please proceed to the payment of the invoice via this secure link:</p>


Or even better yet:
Have one French page and one English page, and detect the user language preference to decide which one to show.

NickMNS

2:51 am on Sep 16, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just a side note...
This is a great example of my biggest annoyance of PHP. The code (PHP) and the content (HTML) are all jumbled together in a big mess, readability is about zero. What happened to separation of concerns?

I am a complete beginner to programming

Consider learning another language, modern Javascript, with frameworks such as React, Vue or Angular and something like NodeJs for the server side, or Python. These are not really any more difficult than PHP but are the languages that are in demand today, and they allow you to do far more than create a simple static web page.

cm35

5:15 am on Sep 16, 2021 (gmt 0)



Hi there,

Thank you for your messages. A webmaster has built the website, I am only the owner ^^
Due to the pandemic, I am trying to update by myself few things (easy ones). Using <p> and </p> create a critical error on Wordpress when I send the invoice. <br> doesn't change anything.

I may haven't written correctly the entire code. Would you mind to type the entire code ? (from my first message)

Thank you for your time.

CM

robzilla

9:49 am on Sep 16, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The wp_kses() [developer.wordpress.org] function in Wordpress filters out all HTML except what is explicitly allowed.

So if you want to use <p> and/or <br>, you would need to put those into the array in the second parameter. Something like:

 wp_kses(
/* translators: %1$s Site title, %2$s Order pay link */
__( '<p>Voici le récapitulatif de votre commande effectuée sur %1$s. Veuillez procéder au règlement de la facture via ce lien sécurisé:<br>%2$s</p>
<p>Here is the summary of your order made on %1$s. Please proceed to the payment of the invoice via this secure link:<br>%2$s</p>', 'woocommerce'),
array(
'a' => array(
'href' => array(),
), 'p' => array(), 'br' => array()
)

(Note that if you get a critical error, you've probably made an error somewhere that breaks the code. You'll find the line number where the error is in your website's error log file.)

cm35

11:34 am on Sep 16, 2021 (gmt 0)



Dear Robzilla+,

Thank you for your message and the explanation.
I will try tomorrow &#129310;

Thank you again for your time.

CM