<?php /** * Pipe-related classes. * * @link https://contactform7.com/selectable-recipient-with-pipes/ */ /** * Class representing a pair of pipe. */ class WPCF7_Pipe { public $before = ''; public $after = ''; public function __construct( $text ) { $text = (string) $text; $pipe_pos = strpos( $text, '|' ); if ( false === $pipe_pos ) { $this->before = $this->after = trim( $text ); } else { $this->before = trim( substr( $text, 0, $pipe_pos ) ); $this->after = trim( substr( $text, $pipe_pos + 1 ) ); } } } /** * Class representing a list of pipes. */ class WPCF7_Pipes { private $pipes = array(); public function __construct( array $texts ) { foreach ( $texts as $text ) { $this->add_pipe( $text ); } } private function add_pipe( $text ) { $pipe = new WPCF7_Pipe( $text ); $this->pipes[] = $pipe; } public function do_pipe( $input ) { $input_canonical = wpcf7_canonicalize( $input, array( 'strto' => 'as-is', ) ); foreach ( $this->pipes as $pipe ) { $before_canonical = wpcf7_canonicalize( $pipe->before, array( 'strto' => 'as-is', ) ); if ( $input_canonical === $before_canonical ) { return $pipe->after; } } return $input; } public function collect_befores() { $befores = array(); foreach ( $this->pipes as $pipe ) { $befores[] = $pipe->before; } return $befores; } public function collect_afters() { $afters = array(); foreach ( $this->pipes as $pipe ) { $afters[] = $pipe->after; } return $afters; } public function zero() { return empty( $this->pipes ); } public function random_pipe() { if ( $this->zero() ) { return null; } return $this->pipes[array_rand( $this->pipes )]; } public function to_array() { return array_map( static function ( WPCF7_Pipe $pipe ) { return array( $pipe->before, $pipe->after, ); }, $this->pipes ); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
block-editor | Folder | 0777 |
|
|
config-validator | Folder | 0777 |
|
|
css | Folder | 0777 |
|
|
js | Folder | 0777 |
|
|
swv | Folder | 0777 |
|
|
capabilities.php | File | 834 B | 0644 |
|
contact-form-functions.php | File | 10.25 KB | 0644 |
|
contact-form-template.php | File | 5.69 KB | 0644 |
|
contact-form.php | File | 29.96 KB | 0644 |
|
controller.php | File | 3.03 KB | 0644 |
|
file.php | File | 10.13 KB | 0644 |
|
form-tag.php | File | 13.42 KB | 0644 |
|
form-tags-manager.php | File | 14.23 KB | 0644 |
|
formatting.php | File | 12.44 KB | 0644 |
|
functions.php | File | 15.36 KB | 0644 |
|
html-formatter.php | File | 16.32 KB | 0644 |
|
integration.php | File | 8.73 KB | 0644 |
|
l10n.php | File | 3.37 KB | 0644 |
|
mail.php | File | 15.34 KB | 0644 |
|
pipe.php | File | 1.87 KB | 0644 |
|
pocket-holder.php | File | 325 B | 0644 |
|
rest-api.php | File | 12.71 KB | 0644 |
|
shortcodes.php | File | 2.65 KB | 0644 |
|
special-mail-tags.php | File | 6.07 KB | 0644 |
|
submission.php | File | 21.55 KB | 0644 |
|
upgrade.php | File | 3 KB | 0644 |
|
validation-functions.php | File | 6.29 KB | 0644 |
|
validation.php | File | 3.22 KB | 0644 |
|