humanmade / Cavalcade

A better wp-cron. Horizontally scalable, works perfectly with multisite.
https://engineering.hmn.md/projects/cavalcade/
Other
512 stars 46 forks source link

Question: How do determine whether Cavalcade is active from other Code? #114

Closed JanThiel closed 2 years ago

JanThiel commented 2 years ago

Hey there,

within the context of a Logging Plugin ( https://github.com/Pierre-Lannoy/wp-decalog ) question arise how one would be able to safely determine whether Cavalcade is installed and active on a WordPress site.

When logging pre_clear_scheduled_hook and other schedule / cron related actions and filters external cron systems like Cavalcade have different return values than WP-Cron. To be able to distinguish between "fails" of WP-Cron and intentional return values from Cavalcade one would first need to recognize an external Cron system being present.

This is the related issue in Decalog: https://github.com/Pierre-Lannoy/wp-decalog/issues/20

Can anyone advice on the most reasonable way to get this done for Cavalcade? The usual ways won't work, as it is installed as MU-Plugin and thus is not checkable using WP APIs. There are some options / constants one might check but it all does not feels right. Using class_exists does not work due to the namespaces. And importing non existing namespaces throws exceptions.

Am I missing something obvious?

Anyway, I am glad for any help :-) Thanks alot!

Jan

JanThiel commented 2 years ago

So yes ... missed something very obvious ... tried with class_exists but function_exists would have been the solution. 🤦

For reference:

if ( function_exists( 'HM\Cavalcade\Plugin\get_database_version' ) && function_exists( '\HM\Cavalcade\Plugin\is_installed' ) && \HM\Cavalcade\Plugin\is_installed() ) {
    ... Cavalcade is there ...
}