Skip to content
wiki.fftac.org

Plugin - Source Excerpt 03

Back to Plugin

Summary

This source excerpt preserves a bounded section of Antichrist.net/wp-content/plugins/uaix-locale-router/src/Plugin.php so readers can inspect the evidence without opening the full source file.

**Source path:** Antichrist.net/wp-content/plugins/uaix-locale-router/src/Plugin.php

self::log_bootstrap_issue( 'repair-options', $throwable->getMessage() );
		}

		try {
			self::ensure_upload_directories();
			$completed[] = 'upload directories';
		} catch ( \Throwable $throwable ) {
			$errors[] = 'upload directories: ' . $throwable->getMessage();
			self::log_bootstrap_issue( 'repair-uploads', $throwable->getMessage() );
		}

		try {
			self::maybe_create_validation_table();
			$completed[] = 'validation storage';
		} catch ( \Throwable $throwable ) {
			$errors[] = 'validation storage: ' . $throwable->getMessage();
			self::log_bootstrap_issue( 'repair-validation', $throwable->getMessage() );
		}

		try {
			Router::register_rewrite_rules();
			flush_rewrite_rules();
			$completed[] = 'rewrite refresh';
		} catch ( \Throwable $throwable ) {
			$errors[] = 'rewrite refresh: ' . $throwable->getMessage();
			self::log_bootstrap_issue( 'repair-rewrites', $throwable->getMessage() );
		}

		try {
			self::bootstrap_runtime();
			$completed[] = 'runtime bootstrap';
		} catch ( \Throwable $throwable ) {
			$errors[] = 'runtime bootstrap: ' . $throwable->getMessage();
			self::log_bootstrap_issue( 'repair-bootstrap', $throwable->getMessage() );
		}

		update_option( 'uaixlr_install_version', UAIXLR_VERSION );
		self::clear_localized_home_diagnostics();

		return array(
			'completed' => $completed,
			'errors'    => $errors,
		);
	}

	/**
	 * Add Site Health debug information.
	 *
	 * @param array $info Existing debug information.
	 * @return array
	 */
	public static function filter_debug_information( $info ) {
		return SiteHealth::filter_debug_information( $info );
	}

	/**
	 * Register Site Health tests.
	 *
	 * @param array $tests Existing tests.
	 * @return array
	 */
	public static function filter_site_status_tests( $tests ) {
		return SiteHealth::filter_site_status_tests( $tests );
	}

	/**
	 * Run runtime Site Health test.
	 *
	 * @return array
	 */
	public static function site_health_test_runtime() {
		return SiteHealth::site_health_test_runtime();
	}

	/**
	 * Run localized-home Site Health test.
	 *
	 * @return array
	 */
	public static function site_health_test_localized_home() {
		return SiteHealth::site_health_test_localized_home();
	}

	/**
	 * Determine whether the validation history table exists.
	 *
	 * @return bool
	 */
	public static function validation_table_exists() {
		global $wpdb;

		$table_name       = self::validation_table_name();
		$previous_setting = $wpdb->suppress_errors( true );
		$result           = $wpdb->query( "SELECT 1 FROM {$table_name} LIMIT 1" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
		$wpdb->suppress_errors( $previous_setting );

		return false !== $result;
	}

	/**
	 * Determine whether the dictionary storage path is writable.
	 *
	 * @param string $dictionary_dir Dictionary directory path.
	 * @return bool
	 */
	private static function is_dictionary_dir_writable( $dictionary_dir ) {
		if ( is_dir( $dictionary_dir ) ) {
			return is_writable( $dictionary_dir );
		}

		$parent = dirname( $dictionary_dir );

		return is_dir( $parent ) && is_writable( $parent );
	}

	/**
	 * Plugin data file path.
	 *
	 * @param string $file Optional filename.
	 * @return string
	 */
	public static function data_path( $file = '' ) {
		return UAIXLR_PLUGIN_PATH . 'data/' . ltrim( (string) $file, '/\\' );
	}

	/**
	 * Plugin template path.
	 *
	 * @param string $file Optional filename.
	 * @return string
	 */
	public static function template_path( $file = '' ) {
		return UAIXLR_PLUGIN_PATH . 'templates/' . ltrim( (string) $file, '/\\' );
	}

	/**
	 * Dictionary storage path.
	 *
	 * @return string
	 */
	public static function dictionaries_dir() {
		$upload_dir = wp_upload_dir();

		return trailingslashit( $upload_dir['basedir'] ) . 'uaix-locale-router/dictionaries';
	}

	/**
	 * Supported locale defaults file path.
	 *
	 * @return string
	 */
	public static function default_supported_locales_path() {
		return self::data_path( 'default-supported-locales.json' );
	}

	/**
	 * Locale catalog file path.
	 *
	 * @return string
	 */
	public static function locale_catalog_path() {
		return self::data_path( 'cldr-locales.json' );
	}

	/**
	 * Validation history table name.
	 *
	 * @return string
	 */
	public static function validation_table_name() {
		global $wpdb;

		return $wpdb->prefix . 'uaixlr_dictionary_validation';
	}
}