'none', // none|managed|byo 'status' => 'disconnected', // disconnected|pending|connected|expired|revoked 'integration_id' => '', 'site_url' => '', 'ossengine_website_id' => '', 'script_url' => '', 'tracking_enabled' => true, 'exclude_admin' => true, 'plugin_version' => OSSENGINE_VERSION, 'account_url' => '', 'status_message' => '', 'updated_at' => 0, ); } /** * Seed defaults on activation. Does not overwrite existing config. */ public function seed_defaults() { if ( false === get_option( self::OPTION_CONNECTION, false ) ) { add_option( self::OPTION_CONNECTION, $this->defaults(), '', true ); } if ( false === get_option( self::OPTION_BYO, false ) ) { add_option( self::OPTION_BYO, array( 'enabled' => false, 'url' => '', 'website_id' => '', ), '', true ); } } /** * Get the managed connection array merged over defaults. * * @return array */ public function get_connection() { $stored = get_option( self::OPTION_CONNECTION, array() ); if ( ! is_array( $stored ) ) { $stored = array(); } return array_merge( $this->defaults(), $stored ); } /** * Update managed connection fields. * * @param array $fields Fields to merge. */ public function update_connection( array $fields ) { $connection = array_merge( $this->get_connection(), $fields ); $connection['plugin_version'] = OSSENGINE_VERSION; $connection['updated_at'] = time(); update_option( self::OPTION_CONNECTION, $connection, true ); } /** * Store the site token server-side only (no autoload, never to JS). * * @param string $token Opaque site token. */ public function set_site_token( $token ) { update_option( self::OPTION_TOKEN, (string) $token, false ); } /** * Get the stored site token. * * @return string */ public function get_site_token() { $token = get_option( self::OPTION_TOKEN, '' ); return is_string( $token ) ? $token : ''; } /** * Drop the site token (disconnect). */ public function clear_site_token() { delete_option( self::OPTION_TOKEN ); } /** * Reset managed connection to disconnected, preserving nothing remote. */ public function reset_connection() { $this->update_connection( array( 'mode' => 'none', 'status' => 'disconnected', 'integration_id' => '', 'ossengine_website_id' => '', 'script_url' => '', 'status_message' => '', ) ); $this->clear_site_token(); } /** * Get BYO config. * * @return array */ public function get_byo() { $stored = get_option( self::OPTION_BYO, array() ); if ( ! is_array( $stored ) ) { $stored = array(); } return array_merge( array( 'enabled' => false, 'url' => '', 'website_id' => '', ), $stored ); } /** * Update BYO config. * * @param array $fields Fields to merge. */ public function update_byo( array $fields ) { update_option( self::OPTION_BYO, array_merge( $this->get_byo(), $fields ), true ); } /** * Queue a one-time admin notice (rendered + cleared by Settings). * * @param string $type updated|error. * @param string $message Message text. */ public function set_notice( $type, $message ) { update_option( self::OPTION_NOTICE, array( 'type' => 'error' === $type ? 'error' : 'updated', 'message' => (string) $message, ), false ); } /** * Take and clear the queued admin notice. * * @return array|null */ public function take_notice() { $notice = get_option( self::OPTION_NOTICE, null ); delete_option( self::OPTION_NOTICE ); return is_array( $notice ) ? $notice : null; } /** * Backend base URL (filterable for staging/tests). * * @return string */ public function backend_url() { $url = apply_filters( 'ossengine_backend_url', OSSENGINE_DEFAULT_BACKEND_URL ); return is_string( $url ) ? rtrim( $url, '/' ) : OSSENGINE_DEFAULT_BACKEND_URL; } /** * Dashboard base URL (filterable for staging/tests). * * @return string */ public function dashboard_url() { $url = apply_filters( 'ossengine_dashboard_url', OSSENGINE_DEFAULT_DASHBOARD_URL ); return is_string( $url ) ? rtrim( $url, '/' ) : OSSENGINE_DEFAULT_DASHBOARD_URL; } /** * Analytics app base URL (filterable for staging/tests). * * This is the hosted Umami app where site owners view their stats * (app.umamiengine.com), distinct from the account dashboard * (dashboard.umamiengine.com) used for billing/integrations. * * @return string */ public function analytics_app_url() { $default = defined( 'OSSENGINE_DEFAULT_ANALYTICS_APP_URL' ) ? OSSENGINE_DEFAULT_ANALYTICS_APP_URL : 'https://app.umamiengine.com'; $url = apply_filters( 'ossengine_analytics_app_url', $default ); return is_string( $url ) && '' !== $url ? rtrim( $url, '/' ) : $default; } /** * Signup URL for new UmamiEngine customers. * * Points at the dashboard login/get-started page, which handles both * account creation (Google/GitHub SSO) and login. * * @return string */ public function signup_url() { $path = defined( 'OSSENGINE_DEFAULT_SIGNUP_PATH' ) ? OSSENGINE_DEFAULT_SIGNUP_PATH : '/login'; $url = $this->dashboard_url() . $path; return apply_filters( 'ossengine_signup_url', $url ); } }