MC4WP_Dynamic_Content_Tags::replace PHP Method

replace() public method

public replace ( string $string, string $escape_mode = '' ) : string
$string string The string containing dynamic content tags.
$escape_mode string Escape mode for the replacement value. Leave empty for no escaping.
return string
    public function replace($string, $escape_mode = '')
    {
        $this->escape_mode = $escape_mode;
        // replace strings like this: {tagname attr="value"}
        $string = preg_replace_callback('/\\{(\\w+)(\\ +(?:(?!\\{)[^}\\n])+)*\\}/', array($this, 'replace_tag'), $string);
        // call again to take care of nested variables
        $string = preg_replace_callback('/\\{(\\w+)(\\ +(?:(?!\\{)[^}\\n])+)*\\}/', array($this, 'replace_tag'), $string);
        return $string;
    }

Usage Example

 /**
  * Replaces the registered tags in the given string
  *
  * @hooked `mc4wp_form_message_html`
  * @hooked `mc4wp_form_content`
  *
  * @param string $string
  * @param MC4WP_Form $form
  * @param MC4WP_Form_Element $element
  *
  * @return string
  */
 public function replace($string, MC4WP_Form $form, MC4WP_Form_Element $element = null)
 {
     $this->form = $form;
     $this->form_element = $element;
     $string = $this->tags->replace($string);
     return $string;
 }
All Usage Examples Of MC4WP_Dynamic_Content_Tags::replace