• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Input Executing WordPress plugin/theme cron events through WP-CLI

wwwAndries

New Pleskian
PRODUCT, VERSION, OPERATING SYSTEM, ARCHITECTURE:
WordPress Toolkit 3.5.0 >

PROBLEM DESCRIPTION:
WordPress plugin/theme cron events are executed through WP-CLI, cron event is removed after executing and reporting status is success, but the plugin/theme "do_action" is actually never excuted.

STEPS TO REPRODUCE:
I’ve disabled the wp-cron for all of the sites I’am managing and use the system cron to run WP-CLI commands like:

${WP_CLI} -instance-id ${INSTANCE_ID} -- cron event run --due-now --url="${WP_SITE_URL}" &>> $CWS_TMP_FILE

The "due-now" cron events were executed and returned success status after executing, but the plugin/theme action/filter never executed. In the WordPress plugin.php the function “do_action_ref_array” was executed but the global $wp_filter[ $tag ] was NULL.

function do_action_ref_array( $tag, $args ) {
global $wp_filter, $wp_actions, $wp_current_filter;

if ( ! isset( $wp_actions[ $tag ] ) ) {
$wp_actions[ $tag ] = 1;
} else {
++$wp_actions[ $tag ];
}

// Do 'all' actions first
if ( isset( $wp_filter['all'] ) ) {
$wp_current_filter[] = $tag;
$all_args = func_get_args();
_wp_call_all_hook( $all_args );
}

+ if ( ! isset( $wp_filter[ $tag ] ) ) {
+ if ( isset( $wp_filter['all'] ) ) {
+ array_pop( $wp_current_filter );
+ }
+ return;
+ }

if ( ! isset( $wp_filter['all'] ) ) {
$wp_current_filter[] = $tag;
}

$wp_filter[ $tag ]->do_action( $args );

array_pop( $wp_current_filter );
}

Because of that, the function returned without an error and WP-CLI reported success, but the $wp_filter[ $tag ]->do_action( $args ); was never executed!

Plesk changed there wrapper for WP-CLI last year and added “skip-plugins: true” and “skip-themes: true” in the wp-cli.yml. Every WP-CLI command is executed without loading plugins and themes. This is the reason why $wp_filter[ $tag ] was NULL and the plugin/theme action/filter was never executed.

Tempory solution
After adding “--skip-plugins=dummy-plugin” at the WP-CLI command “cron event run --due-now”, all scans run fine.


EXPECTED RESULT:
When executing ${WP_CLI} -instance-id ${INSTANCE_ID} -- cron event run --due-now --url="${WP_SITE_URL}", I expect that the cron events of the core, plugins and themes are run.

ANY ADDITIONAL INFORMATION:

YOUR EXPECTATIONS FROM PLESK SERVICE TEAM:
I would expect that skip-plugins and skip-themes would be false because this is the default WP-CLI behavior. At least document this deviation.
 
Back
Top