v1.0.0
This commit is contained in:
commit
e1f5a47c96
22 changed files with 3155 additions and 0 deletions
73
includes/class-fontdelbosc-combustible-shortcode.php
Normal file
73
includes/class-fontdelbosc-combustible-shortcode.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/**
|
||||
* Shortcode [fontdelbosc_combustible] and shared view renderer.
|
||||
*
|
||||
* @package FontdelboscCombustible
|
||||
*/
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Renders the station list via the templates.
|
||||
*/
|
||||
final class Fontdelbosc_Combustible_Shortcode {
|
||||
|
||||
/**
|
||||
* Registers the shortcode.
|
||||
*/
|
||||
public static function init(): void {
|
||||
add_shortcode( 'fontdelbosc_combustible', array( self::class, 'render' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the shortcode.
|
||||
*
|
||||
* @param array<string> $atts Shortcode attributes.
|
||||
*/
|
||||
public static function render( $atts = array() ): string {
|
||||
$atts = shortcode_atts(
|
||||
array(
|
||||
'radius' => '',
|
||||
'max' => '',
|
||||
'fuel' => '',
|
||||
'sort' => '',
|
||||
),
|
||||
$atts,
|
||||
'fontdelbosc_combustible'
|
||||
);
|
||||
|
||||
wp_enqueue_style( 'fdbc-fuel' );
|
||||
|
||||
$data = Fontdelbosc_Combustible_Data_Manager::get_stations(
|
||||
array(
|
||||
'radius' => $atts['radius'],
|
||||
'max' => $atts['max'],
|
||||
'fuel' => $atts['fuel'],
|
||||
'sort' => $atts['sort'],
|
||||
)
|
||||
);
|
||||
|
||||
return self::view( 'station-list', $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a template by name with the given data.
|
||||
*
|
||||
* @param string $name Template name.
|
||||
* @param array<string,mixed> $fontdelbosc_data Template data.
|
||||
*/
|
||||
public static function view( string $name, array $fontdelbosc_data ): string {
|
||||
$file = FONTDELBOSC_COMBUSTIBLE_DIR . 'templates/' . $name . '.php';
|
||||
|
||||
if ( ! is_file( $file ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
include $file;
|
||||
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue