PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.12
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.12
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / Libraries / action-scheduler / classes / abstracts / ActionScheduler_WPCLI_Command.php

ActionScheduler_WPCLI_Command.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.12, at app/Services/Libraries/action-scheduler/classes/abstracts/ActionScheduler_WPCLI_Command.php

84 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Abstract for WP-CLI commands.
5 */
6 abstract class ActionScheduler_WPCLI_Command extends \WP_CLI_Command {
7
8 const DATE_FORMAT = 'Y-m-d H:i:s O';
9
10 /**
11 * Keyed arguments.
12 *
13 * @var string[]
14 */
15 protected $args;
16
17 /**
18 * Positional arguments.
19 *
20 * @var array<string, string>
21 */
22 protected $assoc_args;
23
24 /**
25 * Construct.
26 *
27 * @param string[] $args Positional arguments.
28 * @param array<string, string> $assoc_args Keyed arguments.
29 * @throws \Exception When loading a CLI command file outside of WP CLI context.
30 */
31 public function __construct( array $args, array $assoc_args ) {
32 if ( ! defined( 'WP_CLI' ) || ! constant( 'WP_CLI' ) ) {
33 /* translators: %s php class name */
34 throw new \Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'action-scheduler' ), get_class( $this ) ) );
35 }
36
37 $this->args = $args;
38 $this->assoc_args = $assoc_args;
39 }
40
41 /**
42 * Execute command.
43 */
44 abstract public function execute();
45
46 /**
47 * Get the scheduled date in a human friendly format.
48 *
49 * @see ActionScheduler_ListTable::get_schedule_display_string()
50 * @param ActionScheduler_Schedule $schedule Schedule.
51 * @return string
52 */
53 protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) {
54
55 $schedule_display_string = '';
56
57 if ( ! $schedule->get_date() ) {
58 return '0000-00-00 00:00:00';
59 }
60
61 $next_timestamp = $schedule->get_date()->getTimestamp();
62
63 $schedule_display_string .= $schedule->get_date()->format( static::DATE_FORMAT );
64
65 return $schedule_display_string;
66 }
67
68 /**
69 * Transforms arguments with '__' from CSV into expected arrays.
70 *
71 * @see \WP_CLI\CommandWithDBObject::process_csv_arguments_to_arrays()
72 * @link https://github.com/wp-cli/entity-command/blob/c270cc9a2367cb8f5845f26a6b5e203397c91392/src/WP_CLI/CommandWithDBObject.php#L99
73 * @return void
74 */
75 protected function process_csv_arguments_to_arrays() {
76 foreach ( $this->assoc_args as $k => $v ) {
77 if ( false !== strpos( $k, '__' ) ) {
78 $this->assoc_args[ $k ] = explode( ',', $v );
79 }
80 }
81 }
82
83 }
84