$settings Settings. * @return array Name => text. */ public static function strings( array $settings ) { $out = array(); foreach ( $settings['texts'] as $key => $value ) { if ( '' !== trim( (string) $value, " \t\n\r\0\x0B\f" ) ) { $out[ 'text_' . $key ] = (string) $value; } } foreach ( $settings['custom_services'] as $service ) { foreach ( $service['cookies'] as $i => $cookie ) { if ( '' !== trim( (string) $cookie[1], " \t\n\r\0\x0B\f" ) ) { $out[ 'cookie_' . $service['id'] . '_' . $i . '_duration' ] = (string) $cookie[1]; } if ( '' !== trim( (string) $cookie[2], " \t\n\r\0\x0B\f" ) ) { $out[ 'cookie_' . $service['id'] . '_' . $i ] = (string) $cookie[2]; } } } return $out; } /** * Lists the strings in Polylang's Languages > Translations screen. */ public static function register_polylang_strings() { if ( 'polylang' !== self::plugin() ) { return; } foreach ( self::strings( Settings::get() ) as $name => $value ) { pll_register_string( $name, $value, self::CONTEXT, 'text_message' === $name ); } } /** * Sends the strings to WPML String Translation. */ public static function register_wpml_strings() { if ( 'wpml' !== self::plugin() ) { return; } Settings::flush(); foreach ( self::strings( Settings::get() ) as $name => $value ) { do_action( 'wpml_register_single_string', self::CONTEXT, $name, $value ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML's own hook. } } /** * A string in the current language, or as typed when there is no translation. * * @param string $name Name from strings(). * @param string $value Text as typed by the owner. * @return string */ public static function translate( $name, $value ) { $plugin = self::plugin(); if ( 'polylang' === $plugin ) { $value = pll__( $value ); } elseif ( 'wpml' === $plugin ) { $value = (string) apply_filters( 'wpml_translate_single_string', $value, self::CONTEXT, $name ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML's own hook. } /** * Filters an owner-entered string before visitors see it, for other translation plugins. * * @param string $value Text. * @param string $name Stable name, such as text_title or cookie_custom-chat_0. */ return (string) apply_filters( 'ariconsent_translate_string', $value, $name ); } /** * The privacy policy URL in the current language. * * @param array $settings Settings. * @return string Empty when there is no policy page. */ public static function privacy_url( array $settings ) { $page = (int) $settings['privacy_page']; if ( ! $page ) { return (string) get_privacy_policy_url(); } $plugin = self::plugin(); if ( 'polylang' === $plugin && function_exists( 'pll_get_post' ) ) { $translated = (int) pll_get_post( $page ); $page = $translated ? $translated : $page; } elseif ( 'wpml' === $plugin ) { $page = (int) apply_filters( 'wpml_object_id', $page, 'page', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML's own hook. } $url = get_permalink( $page ); return $url ? (string) $url : ''; } }