portrino / cms-observer-client-wordpress
CMS Observer Client - Reports WordPress core, PHP/DB version and installed plugins to a CMS Observer instance
Package info
github.com/portrino/cms-observer-client-wordpress
Type:wordpress-plugin
pkg:composer/portrino/cms-observer-client-wordpress
Requires
- php: ^8.1
- composer/installers: ^2.0
Requires (Dev)
- brain/monkey: ^2.6
- ergebnis/composer-normalize: ^2.30
- friendsofphp/php-cs-fixer: ^3.14
- mockery/mockery: ^1.6
- php-stubs/wp-cli-stubs: ^2.11
- phpstan/phpstan: ^2.0
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^10.5
- rector/rector: ^2.0
- seld/jsonlint: ^1.9
- shipmonk/composer-dependency-analyser: ^1.8
- spaze/phpstan-disallowed-calls: ^4.0
- symfony/yaml: ^6.4 || ^7.0
- szepeviktor/phpstan-wordpress: ^2.0
- tomasvotruba/cognitive-complexity: ^1.0
- tomasvotruba/type-coverage: ^2.0
- typo3/coding-standards: ^0.8 || ^0.9
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This plugin reports a site's WordPress core version, PHP + DB versions, and installed plugin and theme versions to a central CMS Observer instance, which flags insecure and outdated versions.
Important
Without a central CMS Observer instance this plugin is somewhat useless. So set up your central CMS Observer instance first and then connect any number of WordPress sites by using this client.
Needs CMS Observer 0.7.0 or newer (version 1.x of this plugin works with older ones, without themes).
Works on single sites and multisite networks. A network is reported as one site: its configuration is network-wide, and a plugin or theme counts as active when it's active on any site of the network (a plugin also when network-activated). The parent of an active child theme counts as active too.
π₯ Installation
Composer
The recommended way for Composer based WordPress setups (e.g. Bedrock):
composer require portrino/cms-observer-client-wordpress
ZIP
Download cms-observer-client-<version>.zip from the
GitHub releases and upload it under
Plugins > Add New > Upload Plugin. (Don't use GitHub's "Source code" ZIP, it unpacks to a different directory.)
Activate the plugin, on multisite network-wide.
π§ Configuration
-
On the Observer, register a new site with the type
wordpress(using command line or web interface) and copy the printed token:php bin/console app:site:create "<name>" wordpress "<site-url>" -
In WordPress, go to Settings > CMS Observer (on multisite: Network Admin > Settings > CMS Observer) and set:
API URLβ the Observer's base URL, must usehttps://Tokenβ the token from step 1
Alternatively define
CMS_OBSERVER_API_URLandCMS_OBSERVER_TOKENas constants inwp-config.phpor as environment variables. They take precedence over the settings page (environment variable first), so a sharedwp-config.phpcan serve several environments.
Several environments (production, staging, β¦)
- Set the token for each environment as environment variable or constant in
wp-config.php, not on the settings page. A token saved on the settings page lives inwp_optionsand is copied along with the database, e.g. when staging gets the production database, and staging would then report as production. The Observer catches this as long as staging has a different domain: the report carries all domains of the site (domains), and the Observer rejects it with HTTP 409 when none matches the registered site URL. WP-CLI shows the Observer's message, the settings page shows the last failed push. - Register the site on the Observer with exactly the host WordPress uses (
home_url()): the comparison is exact,www.example.comdoesn't matchexample.com. - Set
WP_ENVIRONMENT_TYPEin each environment'swp-config.php(e.g.define('WP_ENVIRONMENT_TYPE', 'staging');), the report sends it asapplicationContext. Without it WordPress reportsproduction.
π Run
The plugin sends the report once a day via WP-Cron. On sites with low traffic, or with DISABLE_WP_CRON, run
WP-Cron from a system cron job, or push the report with WP-CLI:
wp cms-observer push
To check what would be sent without sending it:
wp cms-observer push --dry-run
π Credits
This project is the WordPress counterpart of the TYPO3 extension cms-observer-client-typo3.
π§βπ» Contributing
Please have a look at CONTRIBUTING.md.