mirror of
https://gh.wpcy.net/https://github.com/fairpm/fair-plugin.git
synced 2026-06-10 01:04:28 +08:00
Signed-off-by: John Blackbourn <john@johnblackbourn.com> Signed-off-by: Andy Fragen <andy@thefragens.com> Signed-off-by: Carrie Dils <carriedils@gmail.com> Signed-off-by: Norcross <andrew.norcross@gmail.com> Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: joedolson <joedolson@users.noreply.github.com> Signed-off-by: Joe Dolson <design@joedolson.com> Signed-off-by: Shadi Sharaf <shady@sharaf.me> Co-authored-by: Chuck Adams <chaz@chaz.works> Co-authored-by: John Blackbourn <john@johnblackbourn.com> Co-authored-by: Andy Fragen <andy@thefragens.com> Co-authored-by: Norcross <andrew.norcross@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: rmccue <21655+rmccue@users.noreply.github.com> Co-authored-by: joedolson <joedolson@users.noreply.github.com> Co-authored-by: Joe Dolson <design@joedolson.com> Co-authored-by: Shady Sharaf <shady@sharaf.me> Co-authored-by: cdils <3099408+cdils@users.noreply.github.com>
98 lines
2.2 KiB
PHP
98 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* Namespace for the plugin.
|
|
*
|
|
* @package FAIR
|
|
*/
|
|
|
|
namespace FAIR;
|
|
|
|
use Fragen\Git_Updater;
|
|
|
|
const CACHE_BASE = 'fair-';
|
|
const CACHE_LIFETIME = 12 * HOUR_IN_SECONDS;
|
|
const CACHE_LIFETIME_FAILURE = HOUR_IN_SECONDS;
|
|
const NS_SEPARATOR = '\\';
|
|
|
|
/**
|
|
* Bootstrap.
|
|
*/
|
|
function bootstrap() {
|
|
// Prevent accidental re-initialization of the plugin.
|
|
static $did_init = false;
|
|
if ( $did_init ) {
|
|
return;
|
|
}
|
|
|
|
$did_init = true;
|
|
|
|
register_class_path( __NAMESPACE__, __DIR__ . DIRECTORY_SEPARATOR );
|
|
|
|
// Modules.
|
|
Avatars\bootstrap();
|
|
Credits\bootstrap();
|
|
Dashboard_Widgets\bootstrap();
|
|
Default_Repo\bootstrap();
|
|
Disable_Openverse\bootstrap();
|
|
Icons\bootstrap();
|
|
Importers\bootstrap();
|
|
Packages\bootstrap();
|
|
Pings\bootstrap();
|
|
Salts\bootstrap();
|
|
Settings\bootstrap();
|
|
Site_Health\bootstrap();
|
|
Updater\bootstrap();
|
|
Upgrades\bootstrap();
|
|
User_Notification\bootstrap();
|
|
Version_Check\bootstrap();
|
|
|
|
// Self-update check.
|
|
( new Git_Updater\Lite( PLUGIN_FILE ) )->run();
|
|
}
|
|
|
|
/**
|
|
* Register a path for autoloading.
|
|
*
|
|
* @param string $prefix The namespace prefix.
|
|
* @param string $path The path to the class files.
|
|
* @return void
|
|
*/
|
|
function register_class_path( string $prefix, string $path ) : void {
|
|
$prefix_length = strlen( $prefix );
|
|
spl_autoload_register( function ( $class ) use ( $prefix, $prefix_length, $path ) {
|
|
if ( ! str_starts_with( $class, $prefix . NS_SEPARATOR ) ) {
|
|
return;
|
|
}
|
|
|
|
// Strip prefix from the start (ala PSR-4).
|
|
$class = substr( $class, $prefix_length + 1 );
|
|
$class = strtolower( $class );
|
|
$class = str_replace( '_', '-', $class );
|
|
$file = '';
|
|
|
|
// Split on namespace separator.
|
|
$last_ns_pos = strripos( $class, NS_SEPARATOR );
|
|
if ( $last_ns_pos !== false ) {
|
|
$namespace = substr( $class, 0, $last_ns_pos );
|
|
$class = substr( $class, $last_ns_pos + 1 );
|
|
$file = str_replace( NS_SEPARATOR, DIRECTORY_SEPARATOR, $namespace ) . DIRECTORY_SEPARATOR;
|
|
}
|
|
$file .= 'class-' . $class . '.php';
|
|
|
|
$path = $path . $file;
|
|
|
|
if ( file_exists( $path ) ) {
|
|
require_once $path;
|
|
}
|
|
} );
|
|
Version_Check\bootstrap();
|
|
}
|
|
|
|
/**
|
|
* Check if WP-CLI is running.
|
|
*
|
|
* @return bool True if running in WP-CLI, false otherwise.
|
|
*/
|
|
function is_wp_cli(): bool {
|
|
return defined( 'WP_CLI' ) && WP_CLI;
|
|
}
|