class-delete.php
7 months ago
class-export.php
7 months ago
class-global-replace.php
7 months ago
class-modify.php
7 months ago
class-nothing.php
7 months ago
class-run.php
7 months ago
class-run.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex\Action\Type; |
| 4 | |
| 5 | use SearchRegex\Action\Action; |
| 6 | use SearchRegex\Schema; |
| 7 | use SearchRegex\Source; |
| 8 | use SearchRegex\Search; |
| 9 | |
| 10 | class Run extends Action { |
| 11 | /** |
| 12 | * Hook name |
| 13 | * |
| 14 | * @var string|false |
| 15 | */ |
| 16 | private $hook = false; |
| 17 | |
| 18 | /** |
| 19 | * Constructor |
| 20 | * |
| 21 | * @param array<string, mixed>|string $options Options. |
| 22 | * @param Schema\Schema $schema Schema. |
| 23 | */ |
| 24 | public function __construct( $options, Schema\Schema $schema ) { |
| 25 | if ( is_array( $options ) && isset( $options['hook'] ) && has_action( $options['hook'] ) ) { |
| 26 | $this->hook = preg_replace( '/[A-Za-z0-9_-]/', '', $options['hook'] ); |
| 27 | } |
| 28 | |
| 29 | parent::__construct( $options, $schema ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @return array<string, mixed> |
| 34 | */ |
| 35 | public function to_json() { |
| 36 | return [ |
| 37 | 'action' => 'action', |
| 38 | 'actionOption' => [ |
| 39 | 'hook' => $this->hook, |
| 40 | ], |
| 41 | ]; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @return bool |
| 46 | */ |
| 47 | public function should_save() { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @param int $row_id |
| 53 | * @param array<string, mixed> $row |
| 54 | * @param Source\Source $source |
| 55 | * @param array<Search\Column> $columns |
| 56 | * @return array<Search\Column> |
| 57 | */ |
| 58 | public function perform( $row_id, array $row, Source\Source $source, array $columns ) { |
| 59 | if ( ! $this->hook || ! $this->should_save() ) { |
| 60 | return $columns; |
| 61 | } |
| 62 | |
| 63 | do_action( $this->hook, $row, $row_id, $source, $columns ); |
| 64 | |
| 65 | return $columns; |
| 66 | } |
| 67 | } |
| 68 |