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
0
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
0
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
009d0381
Commit
009d0381
authored
7 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Reogranize to match use and priority
parent
c28c37b3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
includes/functions.php
+51
-51
51 additions, 51 deletions
includes/functions.php
with
51 additions
and
51 deletions
includes/functions.php
+
51
−
51
View file @
009d0381
...
...
@@ -2,6 +2,57 @@
namespace
Automattic\WP\WP_CLI_Cron_Control_Offload
;
/**
* Create cron event for a given WP-CLI command
*
* return bool|\WP_Error
*/
function
schedule_cli_command
(
$args
)
{
$event_args
=
validate_args
(
$args
);
if
(
is_wp_error
(
$event_args
)
)
{
return
$event_args
;
}
$scheduled
=
wp_schedule_single_event
(
strtotime
(
'+30 seconds'
),
ACTION
,
array
(
'command'
=>
$event_args
)
);
return
false
!==
$scheduled
;
}
/**
* Validate WP-CLI command to be scheduled
*
* @param string $args
* @return array|\WP_Error
*/
function
validate_args
(
$args
)
{
// Strip `wp` if included
if
(
0
===
stripos
(
$args
,
'wp'
)
)
{
$args
=
trim
(
substr
(
$args
,
2
)
);
}
// Block disallowed commands
$command
=
explode
(
' '
,
$args
);
$command
=
array_shift
(
$command
);
if
(
!
is_command_allowed
(
$command
)
)
{
return
new
\WP_Error
(
"
$command
not allowed"
);
}
// Don't worry about the user WP-CLI runs as
if
(
false
===
stripos
(
$args
,
'--allow-root'
)
)
{
$args
.
=
' --allow-root'
;
}
// TODO: validate further
// Nothing to run
if
(
empty
(
$args
)
)
{
return
new
\WP_Error
(
'Invalid command provided'
);
}
return
$args
;
}
/**
* Check if command is allowed
*
...
...
@@ -71,54 +122,3 @@ function get_command_blacklist() {
'server'
,
);
}
/**
* Create cron event for a given WP-CLI command
*
* return bool|\WP_Error
*/
function
schedule_cli_command
(
$args
)
{
$event_args
=
validate_args
(
$args
);
if
(
is_wp_error
(
$event_args
)
)
{
return
$event_args
;
}
$scheduled
=
wp_schedule_single_event
(
strtotime
(
'+30 seconds'
),
ACTION
,
array
(
'command'
=>
$event_args
)
);
return
false
!==
$scheduled
;
}
/**
* Validate WP-CLI command to be scheduled
*
* @param string $args
* @return array|\WP_Error
*/
function
validate_args
(
$args
)
{
// Strip `wp` if included
if
(
0
===
stripos
(
$args
,
'wp'
)
)
{
$args
=
trim
(
substr
(
$args
,
2
)
);
}
// Block disallowed commands
$command
=
explode
(
' '
,
$args
);
$command
=
array_shift
(
$command
);
if
(
!
is_command_allowed
(
$command
)
)
{
return
new
\WP_Error
(
"
$command
not allowed"
);
}
// Don't worry about the user WP-CLI runs as
if
(
false
===
stripos
(
$args
,
'--allow-root'
)
)
{
$args
.
=
' --allow-root'
;
}
// TODO: validate further
// Nothing to run
if
(
empty
(
$args
)
)
{
return
new
\WP_Error
(
'Invalid command provided'
);
}
return
$args
;
}
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