=' ) && class_exists( '\WC_Address_Provider' ); } /** * Starts once WooCommerce is loaded. */ public static function loaded() { if ( is_admin() ) { require_once STREETFILL_PATH . 'includes/class-admin.php'; Admin::init(); } if ( ! self::wc_supported() ) { return; } Assets::init(); // Without a key there are no suggestions, and the browser's own autofill stays on. if ( Settings::has_key() ) { require_once STREETFILL_PATH . 'includes/class-provider.php'; add_filter( 'woocommerce_address_providers', array( __CLASS__, 'register_provider' ) ); } /** * Streetfill is loaded. * * @param string $version Plugin version. * @param string $api Extension API generation. */ do_action( 'streetfill_loaded', STREETFILL_VERSION, STREETFILL_API ); } /** * Adds Streetfill to WooCommerce's address providers. * * @param mixed $providers Providers from other plugins. * @return mixed */ public static function register_provider( $providers ) { if ( ! is_array( $providers ) ) { return $providers; } $providers[] = new Provider(); return $providers; } /** * The plugin's own languages folder for the `streetfill` text domain, only * while WordPress has no file of its own for the locale. * * @param string|false $path Folder WordPress found, false for none. * @param string $domain Text domain. * @param string $locale Locale. * @return string|false */ public static function own_translations( $path, $domain, $locale ) { if ( 'streetfill' !== $domain || ! is_string( $locale ) || 1 !== preg_match( '/^[a-z]{2,3}(_[A-Z]{2})?(_[a-z0-9]+)?$/', $locale ) ) { return $path; } if ( is_string( $path ) && '' !== $path && self::has_translation( $path, $locale ) ) { return $path; } $own = STREETFILL_PATH . 'languages/'; return self::has_translation( $own, $locale ) ? $own : $path; } /** * Whether a folder holds the plugin's translation for a locale. * * @param string $dir Folder. * @param string $locale Locale. * @return bool */ private static function has_translation( $dir, $locale ) { $dir = trailingslashit( $dir ); return is_readable( $dir . 'streetfill-' . $locale . '.mo' ) || is_readable( $dir . 'streetfill-' . $locale . '.l10n.php' ); } }