v1.0.0
This commit is contained in:
commit
1ef08bd731
27 changed files with 4854 additions and 0 deletions
105
includes/class-fontdelbosc-transit-plugin.php
Normal file
105
includes/class-fontdelbosc-transit-plugin.php
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin bootstrap: hooks, assets, options.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Bootstraps the plugin.
|
||||
*/
|
||||
class Fontdelbosc_Transit_Plugin {
|
||||
|
||||
private const OPTION_NAME = 'fontdelbosc_transit_options';
|
||||
|
||||
/**
|
||||
* Default options.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
private static array $defaults = array(
|
||||
'incident_cache_ttl' => 300,
|
||||
'zbe_cache_ttl' => 86400,
|
||||
'default_view' => 'c15',
|
||||
'max_incidents' => 20,
|
||||
'zbe_municipalities' => null,
|
||||
'show_zbe_2026_notice' => true,
|
||||
'delete_data_on_uninstall' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* Hook everything.
|
||||
*/
|
||||
public static function init(): void {
|
||||
add_action( 'init', array( __CLASS__, 'load_textdomain' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'register_assets' ) );
|
||||
|
||||
Fontdelbosc_Transit_Shortcode::init();
|
||||
add_action( 'widgets_init', array( __CLASS__, 'register_widget' ) );
|
||||
|
||||
if ( is_admin() ) {
|
||||
require_once FONTDELBOSC_TRANSIT_DIR . 'admin/class-fontdelbosc-transit-admin.php';
|
||||
Fontdelbosc_Transit_Admin::init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load translations.
|
||||
*/
|
||||
public static function load_textdomain(): void {
|
||||
load_plugin_textdomain( 'fontdelbosc-transit', false, dirname( plugin_basename( FONTDELBOSC_TRANSIT_DIR . 'fontdelbosc-transit.php' ) ) . '/languages' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the front-end stylesheet.
|
||||
*/
|
||||
public static function register_assets(): void {
|
||||
$css = FONTDELBOSC_TRANSIT_DIR . 'public/css/fdbt-transit.css';
|
||||
|
||||
wp_register_style(
|
||||
'fdbt-transit',
|
||||
plugins_url( 'public/css/fdbt-transit.css', FONTDELBOSC_TRANSIT_DIR . 'fontdelbosc-transit.php' ),
|
||||
array(),
|
||||
(string) filemtime( $css )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the widget.
|
||||
*/
|
||||
public static function register_widget(): void {
|
||||
register_widget( 'Fontdelbosc_Transit_Widget' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options merged with defaults.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function get_options(): array {
|
||||
$saved = get_option( self::OPTION_NAME, array() );
|
||||
$saved = is_array( $saved ) ? $saved : array();
|
||||
$options = array();
|
||||
|
||||
foreach ( self::$defaults as $key => $default ) {
|
||||
$options[ $key ] = array_key_exists( $key, $saved ) ? $saved[ $key ] : $default;
|
||||
}
|
||||
|
||||
if ( null === $options['zbe_municipalities'] ) {
|
||||
$options['zbe_municipalities'] = Fontdelbosc_Transit_Api_Zbe::DEFAULT_CATALAN_ZONES;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the options entry.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function option_name(): string {
|
||||
return self::OPTION_NAME;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue