PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / Dependencies / ActionScheduler / classes / abstracts / ActionScheduler_WPCLI_Command.php

ActionScheduler_WPCLI_Command.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at inc/Dependencies/ActionScheduler/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