Skip to content

Commit 2aa735a

Browse files
authored
Merge pull request woocommerce#16709 from woocommerce/fix/16705
Legacy find/replace handling for emails.
2 parents f041155 + 10a873a commit 2aa735a

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

includes/emails/class-wc-email.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,6 @@ class WC_Email extends WC_Settings_API {
190190
*/
191191
protected $placeholders = array();
192192

193-
/**
194-
* Strings to find in subjects/headings.
195-
*
196-
* @deprecated 3.2.0 in favour of placeholders
197-
* @var array
198-
*/
199-
public $find = array();
200-
201-
/**
202-
* Strings to replace in subjects/headings.
203-
*
204-
* @deprecated 3.2.0 in favour of placeholders
205-
* @var array
206-
*/
207-
public $replace = array();
208-
209193
/**
210194
* Constructor.
211195
*/
@@ -250,14 +234,23 @@ public function handle_multipart( $mailer ) {
250234
/**
251235
* Format email string.
252236
*
253-
* @param mixed $string
237+
* @param mixed $string Text to replace placeholders in.
254238
* @return string
255239
*/
256240
public function format_string( $string ) {
257-
// Legacy placeholders. @todo deprecate in 4.0.0.
241+
$find = array_keys( $this->placeholders );
242+
$replace = array_values( $this->placeholders );
243+
244+
// If using legacy find replace, add those to our find/replace arrays first. @todo deprecate in 4.0.0.
245+
if ( isset( $this->find, $this->replace ) ) {
246+
$find = array_merge( $this->find, $find );
247+
$replace = array_merge( $this->replace, $replace );
248+
}
249+
250+
// If using the older style filters for find and replace, ensure the array is associative and then pass through filters. @todo deprecate in 4.0.0.
258251
if ( has_filter( 'woocommerce_email_format_string_replace' ) || has_filter( 'woocommerce_email_format_string_find' ) ) {
259-
$legacy_find = array();
260-
$legacy_replace = array();
252+
$legacy_find = isset( $this->find ) ? $this->find : array();
253+
$legacy_replace = isset( $this->replace ) ? $this->replace : array();
261254

262255
foreach ( $this->placeholders as $find => $replace ) {
263256
$legacy_key = sanitize_title( str_replace( '_', '-', trim( $find, '{}' ) ) );
@@ -267,7 +260,13 @@ public function format_string( $string ) {
267260

268261
$string = str_replace( apply_filters( 'woocommerce_email_format_string_find', $legacy_find, $this ), apply_filters( 'woocommerce_email_format_string_replace', $legacy_replace, $this ), $string );
269262
}
270-
return str_replace( $this->find, $this->replace, $string );
263+
264+
/**
265+
* woocommerce_email_format_string filter for main find/replace code.
266+
*
267+
* @since 3.2.0
268+
*/
269+
return apply_filters( 'woocommerce_email_format_string', str_replace( $find, $replace, $string ), $this );
271270
}
272271

273272
/**

0 commit comments

Comments
 (0)