| 1 |
<?php |
| 2 |
/** |
| 3 |
* Text and button notice. |
| 4 |
* |
| 5 |
* @package ULTP\Notice |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace ULTP\Includes\Notice; |
| 9 |
|
| 10 |
defined( 'ABSPATH' ) || exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Standard admin notice: icon, a heading with an offer line, and an upgrade button. |
| 14 |
*/ |
| 15 |
class Content_Notice extends Abstract_Campaign_Notice { |
| 16 |
|
| 17 |
/** |
| 18 |
* Template views/content.php. |
| 19 |
*/ |
| 20 |
const VIEW = 'content'; |
| 21 |
|
| 22 |
/** |
| 23 |
* Content notice settings. |
| 24 |
* |
| 25 |
* @return array |
| 26 |
*/ |
| 27 |
protected function get_defaults() { |
| 28 |
return array_merge( |
| 29 |
parent::get_defaults(), |
| 30 |
array( |
| 31 |
'utm_key' => 'content_notice', |
| 32 |
'content_heading' => '', |
| 33 |
'content_subheading' => '', // May contain one %s, replaced by `discount_content` in bold. |
| 34 |
'discount_content' => '', |
| 35 |
'border_color' => '#0322ff', |
| 36 |
'icon' => '', |
| 37 |
'is_discount_logo' => false, // true: square discount logo and outline button. |
| 38 |
'button_text' => __( 'Upgrade Now!', 'ultimate-post' ), |
| 39 |
'background_color' => '', // Button colour when is_discount_logo is false. |
| 40 |
) |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* The offer line with `discount_content` in bold in place of its %s. |
| 46 |
* |
| 47 |
* The line is usually translated, and on PHP 8 a stray % or an extra placeholder in a |
| 48 |
* translation makes sprintf() throw. Fall back to a plain replacement instead. |
| 49 |
* |
| 50 |
* @return string Safe HTML. |
| 51 |
*/ |
| 52 |
public function get_subheading_html() { |
| 53 |
$format = wp_kses_post( (string) $this->get( 'content_subheading' ) ); |
| 54 |
$discount = '<strong>' . esc_html( $this->get( 'discount_content' ) ) . '</strong>'; |
| 55 |
|
| 56 |
try { |
| 57 |
$html = sprintf( $format, $discount ); |
| 58 |
} catch ( \Throwable $e ) { |
| 59 |
$html = false; |
| 60 |
} |
| 61 |
|
| 62 |
if ( false === $html ) { // PHP 7.4 returns false instead of throwing. |
| 63 |
$html = str_replace( array( '%1$s', '%s' ), $discount, $format ); |
| 64 |
} |
| 65 |
return $html; |
| 66 |
} |
| 67 |
} |
| 68 |
|