-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimply-bootstrap-carousel.php
110 lines (92 loc) · 4.64 KB
/
simply-bootstrap-carousel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
namespace alexasto12\simplybootstrapcarousel;
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
// Define a more unique plugin path constant
if (!defined('SIMPBOCA_PLUGIN_DIR')) {
define('SIMPBOCA_PLUGIN_DIR', plugin_dir_path(__FILE__));
}
/*
Plugin Name: Simply Bootstrap Carousel
Description: A plugin to create a Bootstrap carousel using shortcodes.
Version: 1.3
Author: Alexasto12
Author URI: https://github.com/Alexasto12
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
/*
Changelog:
v1.3 - (05/02/2025)
- Updated function and constant prefixes to avoid naming conflicts.
- Improved PHP 8.1 compatibility and error handling.
- Minor bug fixes and performance enhancements.
v1.2 - (04/02/2025)
- Renamed plugin to **Simply Bootstrap Carousel** to comply with WordPress naming policies.
- Added the **"License"** field in the plugin header to ensure GPLv2 compliance.
- Improved **Plugin Check validation** by setting explicit version numbers in `wp_enqueue_style()` and `wp_enqueue_script()` to prevent caching issues.
- Removed external Bootstrap CDN references and **replaced them with locally hosted files** for better performance and compliance with WordPress guidelines.
- Included Bootstrap **CSS and JS assets inside the plugin** (`assets/css/` and `assets/js/`).
- Improved **security and best practices** by ensuring proper escaping and validation of user inputs.
- Enhanced **readme.txt**:
- Added a **"Short Description"** section for better visibility in the WordPress plugin repository.
- Improved the **long description** with more detailed information about the plugin’s features and usage.
- Updated the FAQ section with additional details about **nested shortcodes, compatibility, and customization**.
- General **code cleanup** and optimization for better maintainability.
v1.1 - (10/01/2025)
- Added support for HTML content in the carousel.
- Improved compatibility with nested shortcodes.
- Adjusted carousel structure for better flexibility.
v1.0 - (03/01/2025)
- Initial release with image-based carousel functionality.
*/
function simpboca_carousel_shortcode($atts, $content = null) {
// Optional shortcode attributes
$atts = \shortcode_atts(
array(
'id' => 'customCarousel',
),
$atts,
'simpboca_carousel'
);
// Split content by delimiters (you can use `<!-- slide -->` as a delimiter between items)
$slides = explode('<!-- slide -->', $content);
if (empty($slides)) {
return '<p>No slides found for the carousel.</p>';
}
// Build the carousel
$output = '<div id="' . esc_attr($atts['id']) . '" class="carousel slide" data-bs-ride="carousel">';
$output .= '<div class="carousel-indicators">';
foreach ($slides as $index => $slide) {
$active = $index === 0 ? 'active' : '';
$output .= '<button type="button" data-bs-target="#' . esc_attr($atts['id']) . '" data-bs-slide-to="' . $index . '" class="' . $active . '" aria-current="' . $active . '" aria-label="Slide ' . ($index + 1) . '"></button>';
}
$output .= '</div>';
$output .= '<div class="carousel-inner">';
foreach ($slides as $index => $slide) {
$active = $index === 0 ? 'active' : '';
$output .= '<div class="carousel-item ' . $active . '">';
$output .= \do_shortcode($slide); // Render any shortcode within the content
$output .= '</div>';
}
$output .= '</div>';
$output .= '<button class="carousel-control-prev" type="button" data-bs-target="#' . esc_attr($atts['id']) . '" data-bs-slide="prev">';
$output .= '<span class="carousel-control-prev-icon" aria-hidden="true"></span>';
$output .= '<span class="visually-hidden">Previous</span>';
$output .= '</button>';
$output .= '<button class="carousel-control-next" type="button" data-bs-target="#' . esc_attr($atts['id']) . '" data-bs-slide="next">';
$output .= '<span class="carousel-control-next-icon" aria-hidden="true"></span>';
$output .= '<span class="visually-hidden">Next</span>';
$output .= '</button>';
$output .= '</div>';
return $output;
}
\add_shortcode('simpboca_carousel', __NAMESPACE__ . '\\simpboca_carousel_shortcode');
function simpboca_add_bootstrap_assets() {
$plugin_url = SIMPBOCA_PLUGIN_DIR;
// Enqueue Bootstrap from local files
\wp_enqueue_style('simpboca-bootstrap-css', plugin_dir_url(__FILE__) . 'assets/css/bootstrap.min.css', array(), '5.3.0');
\wp_enqueue_script('simpboca-bootstrap-js', plugin_dir_url(__FILE__) . 'assets/js/bootstrap.bundle.min.js', array('jquery'), '5.3.0', true);
}
\add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\simpboca_add_bootstrap_assets');