Initial commit of slide manager plugin
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* HSSM Slider Rendering Class
|
||||
*
|
||||
* Handles rendering of the slider HTML/CSS/JS based on provided slide data
|
||||
*
|
||||
* @package Hi_School_Slide_Manager
|
||||
* @since 1.1.0
|
||||
*/
|
||||
|
||||
// Prevent direct access
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit( 'Direct access forbidden.' );
|
||||
}
|
||||
|
||||
class HSSM_Slider {
|
||||
|
||||
/**
|
||||
* Render the slider
|
||||
*
|
||||
* @since 1.1.0
|
||||
* @param array $slides Array of slide data
|
||||
* @param array $atts Shortcode attributes or configuration
|
||||
* @return string Slider HTML
|
||||
*/
|
||||
public function render( $slides, $atts = array() ) {
|
||||
if ( empty( $slides ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Merge attributes
|
||||
$atts = shortcode_atts( array(
|
||||
'id' => 'hssm-slider-' . uniqid(),
|
||||
'class' => '',
|
||||
'autoplay' => 'true',
|
||||
'interval' => '5000',
|
||||
), $atts );
|
||||
|
||||
ob_start();
|
||||
$this->enqueue_assets();
|
||||
?>
|
||||
<div id="<?php echo esc_attr( $atts['id'] ); ?>" class="hssm-slider-container <?php echo esc_attr( $atts['class'] ); ?>" data-autoplay="<?php echo esc_attr( $atts['autoplay'] ); ?>" data-interval="<?php echo esc_attr( $atts['interval'] ); ?>">
|
||||
<div class="hssm-slider">
|
||||
<div class="hssm-viewport">
|
||||
<div class="hssm-track">
|
||||
<?php foreach ( $slides as $index => $slide ) : ?>
|
||||
<?php
|
||||
$bg_image = isset( $slide['background_image']['url'] ) ? $slide['background_image']['url'] : '';
|
||||
if ( empty( $bg_image ) && isset( $slide['featured_image'] ) ) {
|
||||
$bg_image = $slide['featured_image'];
|
||||
}
|
||||
|
||||
$hide_text = isset( $slide['hide_all_text'] ) && $slide['hide_all_text'];
|
||||
?>
|
||||
<div class="hssm-slide" data-index="<?php echo esc_attr( $index ); ?>">
|
||||
<div class="hssm-slide-inner <?php echo $hide_text ? 'hssm-hide-text' : ''; ?>" style="background-image: url('<?php echo esc_url( $bg_image ); ?>');">
|
||||
<div class="hssm-slide-content-wrapper">
|
||||
<div class="hssm-slide-content">
|
||||
<?php if ( ! empty( $slide['title'] ) ) : ?>
|
||||
<h1 class="hssm-slide-title"><span><?php echo esc_html( $slide['title'] ); ?></span></h1>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( ! empty( $slide['subtitle'] ) ) : ?>
|
||||
<h4 class="hssm-slide-subtitle"><span><?php echo esc_html( $slide['subtitle'] ); ?></span></h4>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( ! empty( $slide['content'] ) ) : ?>
|
||||
<div class="hssm-slide-description">
|
||||
<span><?php echo wp_kses_post( $slide['content'] ); ?></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( ! empty( $slide['buttons'] ) && is_array( $slide['buttons'] ) ) : ?>
|
||||
<?php
|
||||
// Filter out empty buttons
|
||||
$valid_buttons = array_filter($slide['buttons'], function($b) {
|
||||
return !empty($b['text']) && !empty($b['url']);
|
||||
});
|
||||
?>
|
||||
<?php if ( ! empty( $valid_buttons ) ) : ?>
|
||||
<div class="hssm-button-container">
|
||||
<?php foreach ( $valid_buttons as $button ) : ?>
|
||||
<a href="<?php echo esc_url( $button['url'] ); ?>" class="hssm-button">
|
||||
<?php echo esc_html( $button['text'] ); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ( count( $slides ) > 1 ) : ?>
|
||||
<button class="hssm-arrow hssm-arrow-prev" aria-label="<?php _e( 'Previous Slide', 'hi-school-slide-manager' ); ?>">
|
||||
<span class="hssm-arrow-icon"></span>
|
||||
</button>
|
||||
<button class="hssm-arrow hssm-arrow-next" aria-label="<?php _e( 'Next Slide', 'hi-school-slide-manager' ); ?>">
|
||||
<span class="hssm-arrow-icon"></span>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue slider assets
|
||||
*
|
||||
* @since 1.1.0
|
||||
*/
|
||||
private function enqueue_assets() {
|
||||
wp_enqueue_style(
|
||||
'hssm-slider',
|
||||
HSSM_PLUGIN_URL . 'assets/css/slider.css',
|
||||
array(),
|
||||
HSSM_VERSION
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'hssm-slider',
|
||||
HSSM_PLUGIN_URL . 'assets/js/slider.js',
|
||||
array( 'jquery' ),
|
||||
HSSM_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user