Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-cli-cron-control-offload
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
WP Plugins
wp-cli-cron-control-offload
Commits
4bd67d52
Commit
4bd67d52
authored
7 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
PHPCS fixes
parent
cfe5ad33
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
includes/class-cli.php
+2
-2
2 additions, 2 deletions
includes/class-cli.php
includes/functions.php
+16
-13
16 additions, 13 deletions
includes/functions.php
with
18 additions
and
15 deletions
includes/class-cli.php
+
2
−
2
View file @
4bd67d52
...
...
@@ -23,8 +23,8 @@ class CLI extends WP_CLI_Command {
*
* @subcommand create
* @synopsis --command=<command> [--timestamp=<timestamp>]
* @param array
$args Array of positional arguments
* @param array
$assoc_args Array of flags
* @param array $args Array of positional arguments
.
* @param array $assoc_args Array of flags
.
*/
public
function
create
(
$args
,
$assoc_args
)
{
$command
=
WP_CLI\Utils\get_flag_value
(
$assoc_args
,
'command'
,
''
);
...
...
This diff is collapsed.
Click to expand it.
includes/functions.php
+
16
−
13
View file @
4bd67d52
<?php
/**
* Common plugin functions
*
* @package WP_CLI_Cron_Control_Offload
*/
namespace
Automattic\WP\WP_CLI_Cron_Control_Offload
;
use
WP_Error
;
...
...
@@ -6,8 +11,8 @@ use WP_Error;
/**
* Create cron event for a given WP-CLI command
*
* @param string $command
* @param int $timestamp Optional.
* @param string $command
WP-CLI command to schedule.
* @param int
$timestamp Optional.
Unix timestamp to schedule command to run at.
* @return int|WP_Error
*/
function
schedule_cli_command
(
$command
,
$timestamp
=
null
)
{
...
...
@@ -25,7 +30,7 @@ function schedule_cli_command( $command, $timestamp = null ) {
return
new
WP_Error
(
'invalid-timestamp'
,
__
(
'Timestamp is in the past.'
,
'wp-cli-cron-control-offload'
)
);
}
$event_args
=
array
(
'command'
=>
$command
,
);
$event_args
=
array
(
'command'
=>
$command
);
$scheduled
=
wp_schedule_single_event
(
$timestamp
,
ACTION
,
$event_args
);
...
...
@@ -39,32 +44,30 @@ function schedule_cli_command( $command, $timestamp = null ) {
/**
* Validate WP-CLI command to be scheduled
*
* @param string $command
* @param string $command
WP-CLI command to validate.
* @return array|WP_Error
*/
function
validate_command
(
$command
)
{
$command
=
trim
(
$command
);
// Strip `wp` if included
// Strip `wp` if included
.
if
(
0
===
stripos
(
$command
,
'wp'
)
)
{
$command
=
trim
(
substr
(
$command
,
2
)
);
}
// Block disallowed commands
// Block disallowed commands
.
$first_command
=
explode
(
' '
,
$command
);
$first_command
=
array_shift
(
$first_command
);
if
(
!
is_command_allowed
(
$first_command
)
)
{
return
new
WP_Error
(
'blocked-command'
,
sprintf
(
__
(
'`%1$s` not allowed'
,
'wp-cli-cron-control-offload'
),
$first_command
)
);
}
// Don't worry about the user WP-CLI runs as
// Don't worry about the user WP-CLI runs as
.
if
(
false
===
stripos
(
$command
,
'--allow-root'
)
)
{
$command
.
=
' --allow-root'
;
}
// TODO: validate further
// Nothing to run
// Nothing to run.
if
(
empty
(
$command
)
)
{
return
new
WP_Error
(
'invalid-command'
,
'Invalid command provided'
);
}
...
...
@@ -75,7 +78,7 @@ function validate_command( $command ) {
/**
* Check if command is allowed
*
* @param string $command
* @param string $command
Top-level WP-CLI command to check against blacklist and whitelist.
* @return bool
*/
function
is_command_allowed
(
$command
)
{
...
...
@@ -89,7 +92,7 @@ function is_command_allowed( $command ) {
*/
function
get_command_whitelist
()
{
// TODO: constant!
// Supported built-in commands
// Supported built-in commands
.
$whitelist
=
array
(
'cache'
,
'cap'
,
...
...
@@ -127,7 +130,7 @@ function get_command_whitelist() {
function
get_command_blacklist
()
{
// TODO: constant!
return
array
(
CLI_NAMESPACE
,
// Don't support scheduling loops
CLI_NAMESPACE
,
// Don't support scheduling loops
.
'cli'
,
'config'
,
'core'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment