WPCF7_Pipes{}
Class representing a list of pipes.
Хуков нет.
Использование
$WPCF7_Pipes = new WPCF7_Pipes(); // use class methods
Методы
- public __construct( $texts = null )
- private add_pipe( $text )
- public collect_afters()
- public collect_befores()
- public do_pipe( $input )
- public merge( self $another )
- public random_pipe()
- public to_array()
- public zero()
Код WPCF7_Pipes{} WPCF7 Pipes{} CF7 6.0.5
class WPCF7_Pipes { private $pipes = array(); public function __construct( $texts = null ) { foreach ( (array) $texts as $text ) { $this->add_pipe( $text ); } } private function add_pipe( $text ) { $pipe = new WPCF7_Pipe( $text ); $this->pipes[] = $pipe; } public function merge( self $another ) { $this->pipes = array_merge( $this->pipes, $another->pipes ); } 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 ); } }