?oauth2callback=1 (this must be public) * - Click the 'Download JSON' button to download the JSON file that can be copied and pasted into the filter */ $credentials = apply_filters( 'googlesitekit_oauth_secret', '' ); if ( is_string( $credentials ) && trim( $credentials ) ) { $credentials = json_decode( $credentials, true ); } if ( isset( $credentials['web']['client_id'], $credentials['web']['client_secret'] ) ) { return $this->parse_defaults( array( 'oauth2_client_id' => $credentials['web']['client_id'], 'oauth2_client_secret' => $credentials['web']['client_secret'], ) ); } return $this->parse_defaults( $this->options->get( self::OPTION ) ); } /** * Checks whether Site Kit has been setup with client ID and secret. * * @since 1.0.0 * * @return bool True if credentials are set, false otherwise. */ public function has() { $credentials = (array) $this->get(); if ( ! empty( $credentials ) && ! empty( $credentials['oauth2_client_id'] ) && ! empty( $credentials['oauth2_client_secret'] ) ) { return true; } return false; } /** * Parses Credentials data and merges with its defaults. * * @since 1.0.0 * * @param mixed $data Credentials data. * @return array Parsed $data. */ private function parse_defaults( $data ) { $defaults = $this->get_default(); if ( ! is_array( $data ) ) { return $defaults; } return wp_parse_args( $data, $defaults ); } /** * Gets the default value. * * @since 1.2.0 * * @return array */ protected function get_default() { return array( 'oauth2_client_id' => '', 'oauth2_client_secret' => '', ); } /** * Determines whether the authentication proxy is used. * * In order to streamline the setup and authentication flow, the plugin uses a proxy mechanism based on an external * service. This can be overridden by providing actual GCP credentials with the {@see 'googlesitekit_oauth_secret'} * filter. * * @since 1.9.0 * * @return bool True if proxy authentication is used, false otherwise. */ public function using_proxy() { $creds = $this->get(); if ( ! $this->has() ) { return true; } return (bool) preg_match( '/\.apps\.sitekit\.withgoogle\.com$/', $creds['oauth2_client_id'] ); } }