Plugin Updates

This commit is contained in:
Tony Volpe
2024-03-19 15:33:31 +00:00
parent ff5b56dc44
commit 3a70a6e4bf
317 changed files with 8178 additions and 2933 deletions

View File

@@ -24,6 +24,7 @@ class WPCF7_Mail {
private $name = '';
private $locale = '';
private $template = array();
private $component = '';
private $use_html = false;
private $exclude_blank = false;
@@ -36,6 +37,35 @@ class WPCF7_Mail {
}
/**
* Returns the name of the email template currently processed.
*
* Expected output: 'mail' or 'mail_2'
*/
public static function get_current_template_name() {
$current = self::get_current();
if ( $current instanceof self ) {
return $current->get_template_name();
}
}
/**
* Returns the name of the email template component currently processed.
*
* Expected output: 'recipient', 'sender', 'subject',
* 'additional_headers', 'body', or 'attachments'
*/
public static function get_current_component_name() {
$current = self::get_current();
if ( $current instanceof self ) {
return $current->get_component_name();
}
}
/**
* Composes and sends email based on the specified template.
*
@@ -86,6 +116,22 @@ class WPCF7_Mail {
}
/**
* Returns the name of the email template. A wrapper method of name().
*/
public function get_template_name() {
return $this->name();
}
/**
* Returns the name of the email template component currently processed.
*/
public function get_component_name() {
return $this->component;
}
/**
* Retrieves a component from the email template.
*
@@ -95,8 +141,10 @@ class WPCF7_Mail {
* @return string The text representation of the email component.
*/
public function get( $component, $replace_tags = false ) {
$use_html = ( $this->use_html && 'body' == $component );
$exclude_blank = ( $this->exclude_blank && 'body' == $component );
$this->component = $component;
$use_html = ( $this->use_html && 'body' === $component );
$exclude_blank = ( $this->exclude_blank && 'body' === $component );
$template = $this->template;
$component = isset( $template[$component] ) ? $template[$component] : '';
@@ -127,6 +175,8 @@ class WPCF7_Mail {
}
}
$this->component = '';
return $component;
}
@@ -502,9 +552,7 @@ class WPCF7_MailTaggedText {
: null;
if ( $mail_tag->get_option( 'do_not_heat' ) ) {
$submitted = isset( $_POST[$field_name] )
? wp_unslash( $_POST[$field_name] )
: '';
$submitted = wp_unslash( $_POST[$field_name] ?? '' );
}
$replaced = $submitted;
@@ -514,8 +562,12 @@ class WPCF7_MailTaggedText {
$replaced = $this->format( $replaced, $format );
}
$separator = ( 'body' === WPCF7_Mail::get_current_component_name() )
? wp_get_list_item_separator()
: ', ';
$replaced = wpcf7_flat_join( $replaced, array(
'separator' => wp_get_list_item_separator(),
'separator' => $separator,
) );
if ( $html ) {
@@ -578,103 +630,3 @@ class WPCF7_MailTaggedText {
}
}
/**
* Class that represents a mail-tag.
*/
class WPCF7_MailTag {
private $tag;
private $tagname = '';
private $name = '';
private $options = array();
private $values = array();
private $form_tag = null;
/**
* The constructor method.
*/
public function __construct( $tag, $tagname, $values ) {
$this->tag = $tag;
$this->name = $this->tagname = $tagname;
$this->options = array(
'do_not_heat' => false,
'format' => '',
);
if ( ! empty( $values ) ) {
preg_match_all( '/"[^"]*"|\'[^\']*\'/', $values, $matches );
$this->values = wpcf7_strip_quote_deep( $matches[0] );
}
if ( preg_match( '/^_raw_(.+)$/', $tagname, $matches ) ) {
$this->name = trim( $matches[1] );
$this->options['do_not_heat'] = true;
}
if ( preg_match( '/^_format_(.+)$/', $tagname, $matches ) ) {
$this->name = trim( $matches[1] );
$this->options['format'] = $this->values[0];
}
}
/**
* Returns the name part of this mail-tag.
*/
public function tag_name() {
return $this->tagname;
}
/**
* Returns the form field name corresponding to this mail-tag.
*/
public function field_name() {
return strtr( $this->name, '.', '_' );
}
/**
* Returns the value of the specified option.
*/
public function get_option( $option ) {
return $this->options[$option];
}
/**
* Returns the values part of this mail-tag.
*/
public function values() {
return $this->values;
}
/**
* Retrieves the WPCF7_FormTag object that corresponds to this mail-tag.
*/
public function corresponding_form_tag() {
if ( $this->form_tag instanceof WPCF7_FormTag ) {
return $this->form_tag;
}
if ( $submission = WPCF7_Submission::get_instance() ) {
$contact_form = $submission->get_contact_form();
$tags = $contact_form->scan_form_tags( array(
'name' => $this->field_name(),
'feature' => '! zero-controls-container',
) );
if ( $tags ) {
$this->form_tag = $tags[0];
}
}
return $this->form_tag;
}
}