plugin = $plugin; } /** * Gets the system user access token. * * @since 2.0.0 * * @return string */ public function get_access_token() { $access_token = get_option( self::OPTION_WA_UTILITY_ACCESS_TOKEN, '' ); return $access_token; } /** * Gets the WA installation ID. * * @since 2.0.0 * * @return string */ public function get_wa_installation_id() { $wa_installation_id = get_option( self::OPTION_WA_INSTALLATION_ID, '' ); return $wa_installation_id; } /** * Determines whether the site is integrated whatsapp utility. * * A site is connected if there is an access token stored. * * @since 2.0.0 * * @return bool */ public function is_connected() { return (bool) $this->get_access_token(); } /** * Gets the stored whatsapp external ID. * * @since 2.0.0 * * @return string */ public function get_whatsapp_external_id() { if ( ! is_string( $this->wa_external_id ) ) { $external_id = get_option( self::OPTION_WA_EXTERNAL_BUSINESS_ID ); if ( ! is_string( $external_id ) || empty( $external_id ) ) { /** * Filters the whatsapp external ID. * * This is passed to Meta when Onboarding. * Should be non-empty and without special characters, otherwise the ID will be obtained from the site URL as fallback. * * @since 2.0.0 * * @param string $external_id the whatsapp external ID */ $external_id_prefix = sanitize_key( (string) get_bloginfo( 'name' ) ); if ( empty( $external_id_prefix ) ) { $external_id_prefix = sanitize_key( str_replace( array( 'http', 'https', 'www' ), '', get_bloginfo( 'url' ) ) ); } $external_id = uniqid( sprintf( '%s-', $external_id_prefix ), false ); $this->update_whatsapp_external_business_id( $external_id ); } $this->wa_external_id = $external_id; } return $external_id; } /** * Stores the given wa external id. * * @since 2.6.13 * * @param string $value external business id */ public function update_whatsapp_external_business_id( $value ) { update_option( self::OPTION_WA_EXTERNAL_BUSINESS_ID, is_string( $value ) ? $value : '' ); } }