'Store email', 'dynamic' => false ); * return $list; * } ); * add_filter( 'cpod_placeholder_values', function ( $values, $product_id, $country ) { * $values['store_email'] = '…'; * return $values; * }, 10, 3 ); * * Dynamic placeholders depend on the visitor's country and today's date. The * page is rendered with the default country (it may be cached), the value is * wrapped in and the frontend script updates it. * * @package CPODKit */ namespace CPODKit\Core; defined( 'ABSPATH' ) || exit; class Placeholders { /** * Registered placeholders: name => array( label, dynamic ). * * @return array */ public static function definitions() { $list = (array) apply_filters( 'cpod_placeholders', array() ); foreach ( $list as $name => $info ) { $list[ $name ] = wp_parse_args( (array) $info, array( 'label' => $name, 'dynamic' => false ) ); } return $list; } /** * Values for a product and destination country: name => HTML. * * @param int $product_id Product id (0 when not on a product). * @param string $country ISO code. * @return array */ public static function values( $product_id, $country ) { return (array) apply_filters( 'cpod_placeholder_values', array(), (int) $product_id, (string) $country ); } /** * Replace {{placeholders}}; unknown or empty ones disappear, and so do * paragraphs or list items left empty by them. * * @param string $html Content (already sanitized). * @param int $product_id Product id. * @return string */ public static function replace( $html, $product_id = 0, $country = null ) { if ( false === strpos( $html, '{{' ) ) { return $html; } $definitions = self::definitions(); $values = self::values( $product_id, null === $country ? Settings::default_country() : $country ); $html = preg_replace_callback( '/\{\{\s*([a-z0-9_]+)\s*\}\}/', static function ( $m ) use ( $definitions, $values ) { $name = $m[1]; $value = isset( $values[ $name ] ) ? (string) $values[ $name ] : ''; if ( isset( $definitions[ $name ] ) && $definitions[ $name ]['dynamic'] ) { return '' . esc_html( $value ) . ''; } return $value; }, $html ); return preg_replace( '#<(p|li)>\s*#', '', $html ); } /** Help box listing the placeholders available with the running modules. */ public static function help() { $list = self::definitions(); if ( ! $list ) { return; } ?>

—

$info ) : ?>
{{}}