] * : table, json or csv. * --- * default: table * --- * * ## EXAMPLES * * wp ariconsent status * * @param array $args Positional arguments. * @param array $assoc_args Options. */ public function status( $args, $assoc_args ) { $checks = Health::checks(); $rows = array_map( static function ( $check ) { return array( 'status' => $check['status'], 'check' => $check['label'], ); }, $checks ); \WP_CLI\Utils\format_items( $assoc_args['format'] ?? 'table', $rows, array( 'status', 'check' ) ); \WP_CLI::log( sprintf( 'Score: %d of 100', Health::score( $checks ) ) ); } /** * Scans the site (homepage and newest pages) for services and trackers that load before consent. * * ## OPTIONS * * [--pages=] * : Most pages to load. * --- * default: 10 * --- * * ## EXAMPLES * * wp ariconsent scan --pages=25 * * @param array $args Positional arguments. * @param array $assoc_args Options. */ public function scan( $args, $assoc_args ) { $pages = Health::scan_site( (int) ( $assoc_args['pages'] ?? 10 ) ); if ( ! $pages ) { \WP_CLI::error( 'The site could not be loaded from this server.' ); } \WP_CLI::log( sprintf( 'Pages scanned: %d', $pages ) ); $found = (array) get_option( Admin\Admin::DETECTED_OPT, array() ); $unblocked = (array) get_option( Health::UNBLOCKED_OPT, array() ); \WP_CLI::log( 'Found: ' . ( $found ? implode( ', ', $found ) : 'none' ) ); if ( $unblocked ) { \WP_CLI::warning( 'Loading before consent: ' . implode( ', ', $unblocked ) ); } \WP_CLI::success( 'Scan finished.' ); } /** * Asks every visitor for consent again, by raising the policy revision. * * ## OPTIONS * * [--yes] * : Do not ask for confirmation. * * ## EXAMPLES * * wp ariconsent reconsent --yes * * @param array $args Positional arguments. * @param array $assoc_args Options. */ public function reconsent( $args, $assoc_args ) { \WP_CLI::confirm( 'Every visitor will be asked for consent again. Continue?', $assoc_args ); $settings = Settings::get(); $settings['revision'] = (int) $settings['revision'] + 1; Settings::update( $settings ); \WP_CLI::success( sprintf( 'Policy revision is now %d.', $settings['revision'] ) ); } /** * Prints the settings as JSON, to import on another site. * * ## EXAMPLES * * wp ariconsent export > ariconsent-settings.json * * @param array $args Positional arguments. * @param array $assoc_args Options. */ public function export( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter -- WP-CLI passes both. \WP_CLI::line( (string) wp_json_encode( Settings::export_data(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ); } /** * Imports settings from a file made with `wp ariconsent export`. * * ## OPTIONS * * * : Path to the JSON file. * * ## EXAMPLES * * wp ariconsent import ariconsent-settings.json * * @param array $args Positional arguments. * @param array $assoc_args Options. */ public function import( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- WP-CLI passes both. $path = (string) $args[0]; if ( ! is_readable( $path ) ) { \WP_CLI::error( 'Cannot read ' . $path ); } $json = file_get_contents( $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local file given on the command line. if ( false === $json ) { \WP_CLI::error( 'Cannot read ' . $path ); } $result = Settings::import_data( json_decode( $json, true ) ); if ( is_wp_error( $result ) ) { \WP_CLI::error( $result->get_error_message() ); } \WP_CLI::success( 'Settings imported.' ); } }