\n"; } } /** * Connect, step 2 (ADR 0055): publishes getReport's token and asks for this site's key. On * success the key is saved: Check now, re-tests and the weekly email work from WordPress. * * @return true|WP_Error */ public static function fetch_site_key() { $token = GetReport_Api::verify_token(); if ( is_wp_error( $token ) ) { return $token; } update_option( 'getreport_verify_token', $token, true ); $key = GetReport_Api::plugin_key(); if ( is_wp_error( $key ) ) { return $key; } update_option( 'getreport_api_key', $key['key'], false ); return true; } /** The saved API key, or ''. */ public static function api_key() { return (string) get_option( 'getreport_api_key', '' ); } /** * Defaults. Everything that sends data anywhere is off; everything local is on. * * @return array */ public static function defaults() { return array( 'capture_bots' => true, 'trusted_proxies' => '', 'ip_refresh' => false, 'beacon' => false, 'post_types' => array( 'post', 'page', 'product' ), 'stale_months' => 18, 'retention_days' => 90, 'delete_on_uninstall' => false, 'welcome_dismissed' => false, 'date_types' => array( 'post' ), 'author_types' => array( 'post' ), 'facts' => array( 'name' => '', 'founded' => '', 'address' => '', 'phone' => '', 'email' => '', 'same_as' => '', ), ); } /** * One setting, or all of them. * * @param string|null $key Setting. * @return mixed */ public static function setting( $key = null ) { $saved = get_option( self::SETTINGS, array() ); $all = array_merge( self::defaults(), is_array( $saved ) ? $saved : array() ); return null === $key ? $all : ( $all[ $key ] ?? null ); } /** * Saves some settings, keeping the others. * * @param array $values Values. */ public static function save_settings( $values ) { $all = array_merge( self::setting(), $values ); update_option( self::SETTINGS, array_intersect_key( $all, self::defaults() ), false ); } /** * Post types the audit and the editor panel cover (the saved ones that exist here). * * @return string[] */ public static function post_types() { return array_values( array_filter( (array) self::setting( 'post_types' ), 'post_type_exists' ) ); } /** Activation: tables and the daily maintenance event. */ public static function activate() { GetReport_Db::install(); GetReport_Cron::schedule_daily(); } /** Hooks everything. */ public static function boot() { GetReport_Db::maybe_upgrade(); if ( self::connected() && self::verify_token() ) { add_action( 'init', array( __CLASS__, 'serve_verify_file' ), 1 ); add_action( 'wp_head', array( __CLASS__, 'print_verify_meta' ), 1 ); } GetReport_Fixes::register_runtime(); GetReport_Bots::register(); GetReport_Referrals::register(); GetReport_Audit::register(); GetReport_Editor::register(); if ( is_admin() ) { GetReport_Admin::register(); } GetReport_Cron::register(); } }