PluginProbe
Carousel Slider / 2.2.18
Carousel Slider v2.2.18
2.2.18 trunk 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17
carousel-slider / carousel-slider.php

carousel-slider.php in Carousel Slider 2.2.18, at carousel-slider.php

256 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Carousel Slider
4 * Plugin URI: https://github.com/sayful1/carousel-slider
5 * Description: <strong>Carousel Slider</strong> allows you to create beautiful, touch-enabled, responsive carousels and sliders. It lets you create SEO friendly Image carousel from Media Library or from custom URL, Video carousel using YouTube and Vimeo video, Post carousel, Hero banner slider and various types of WooCommerce products carousels.
6 * Version: 2.2.18
7 * Requires at least: 6.7
8 * Requires PHP: 7.0
9 * Author: Sayful Islam
10 * Author URI: https://github.com/sayful1/
11 *
12 * WC requires at least: 3.0
13 * WC tested up to: 11.0
14 *
15 * Text Domain: carousel-slider
16 *
17 * License: GPLv3
18 * License URI: https://www.gnu.org/licenses/gpl-3.0.txt
19 *
20 * @package Carousel_Slider
21 * @author Sayful Islam
22 */
23
24 // If this file is called directly, abort.
25 defined( 'ABSPATH' ) || exit;
26
27 if ( ! class_exists( 'Carousel_Slider' ) ) {
28 /**
29 * The core plugin class.
30 * This is used to define internationalization, admin-specific hooks, and public-facing site hooks.
31 * Also maintains the unique identifier of this plugin as well as the current version of the plugin.
32 */
33 final class Carousel_Slider {
34
35 /**
36 * Plugin name slug
37 *
38 * @var string
39 */
40 private $plugin_name = 'carousel-slider';
41
42 /**
43 * Plugin custom post type
44 *
45 * @var string
46 */
47 private $post_type = 'carousels';
48
49 /**
50 * Plugin version
51 *
52 * @var string
53 */
54 private $version = '2.2.18';
55
56 /**
57 * Minimum PHP version required
58 *
59 * @var string
60 */
61 private $min_php = '7.0';
62
63 /**
64 * The instance of the class
65 *
66 * @var self
67 */
68 private static $instance;
69
70 /**
71 * Main Carousel_Slider Instance
72 * Ensures only one instance of the class is loaded or can be loaded.
73 *
74 * @return Carousel_Slider - Main instance
75 * @since 1.6.0
76 */
77 public static function instance() {
78 if ( is_null( self::$instance ) ) {
79 self::$instance = new self();
80
81 // define plugin constants.
82 self::$instance->define_constants();
83
84 // Register autoloader.
85 self::$instance->register_autoloader();
86
87 // Check if the PHP version is supported for our plugin.
88 if ( ! self::$instance->is_supported_php() ) {
89 register_activation_hook( __FILE__, [ self::$instance, 'auto_deactivate' ] );
90 add_action( 'admin_notices', [ self::$instance, 'php_version_notice' ] );
91
92 return self::$instance;
93 }
94
95 do_action( 'carousel_slider/init' );
96
97 // bootstrap plugin main class.
98 self::$instance->bootstrap_plugin();
99
100 register_activation_hook( __FILE__, [ self::$instance, 'activation' ] );
101 register_deactivation_hook( __FILE__, [ self::$instance, 'deactivation' ] );
102
103 do_action( 'carousel_slider/loaded' );
104 }
105
106 return self::$instance;
107 }
108
109 /**
110 * Define plugin constants
111 */
112 public function define_constants() {
113 define( 'CAROUSEL_SLIDER', $this->plugin_name );
114 define( 'CAROUSEL_SLIDER_VERSION', $this->version );
115 define( 'CAROUSEL_SLIDER_POST_TYPE', $this->post_type );
116 define( 'CAROUSEL_SLIDER_FILE', __FILE__ );
117 define( 'CAROUSEL_SLIDER_PATH', dirname( CAROUSEL_SLIDER_FILE ) );
118 define( 'CAROUSEL_SLIDER_URL', plugins_url( '', CAROUSEL_SLIDER_FILE ) );
119 define( 'CAROUSEL_SLIDER_ASSETS', CAROUSEL_SLIDER_URL . '/assets' );
120 $this->define_constant( 'CAROUSEL_SLIDER_PRO_PROMOTION', false );
121 }
122
123 /**
124 * Define constant if not defined
125 *
126 * @param string $constant_name The constant name.
127 * @param mixed $value The constant value.
128 *
129 * @return void
130 */
131 public function define_constant( string $constant_name, $value ) {
132 if ( ! defined( $constant_name ) ) {
133 define( $constant_name, $value );
134 }
135 }
136
137 /**
138 * Load plugin classes
139 */
140 private function register_autoloader() {
141 if ( file_exists( CAROUSEL_SLIDER_PATH . '/vendor/autoload.php' ) ) {
142 include CAROUSEL_SLIDER_PATH . '/vendor/autoload.php';
143 } else {
144 include_once CAROUSEL_SLIDER_PATH . '/includes/Autoloader.php';
145
146 // instantiate the loader.
147 $loader = new CarouselSlider\Autoloader();
148
149 // register the base directories for the namespace prefix.
150 $loader->add_namespace( 'CarouselSlider', CAROUSEL_SLIDER_PATH . '/includes' );
151 $loader->add_namespace( 'CarouselSlider\Modules', CAROUSEL_SLIDER_PATH . '/modules' );
152
153 // register the autoloader.
154 $loader->register();
155 }
156 }
157
158 /**
159 * Instantiate the required classes
160 *
161 * @return void
162 */
163 public function bootstrap_plugin() {
164 CarouselSlider\Plugin::init();
165 }
166
167 /**
168 * To be run when the plugin is activated
169 *
170 * @return void
171 */
172 public function activation() {
173 do_action( 'carousel_slider/activation' );
174 }
175
176 /**
177 * To be run when the plugin is deactivated
178 *
179 * @return void
180 */
181 public function deactivation() {
182 do_action( 'carousel_slider/deactivation' );
183 }
184
185 /**
186 * Show notice about the PHP version
187 *
188 * @return void
189 */
190 public function php_version_notice() {
191
192 if ( $this->is_supported_php() || ! current_user_can( 'manage_options' ) ) {
193 return;
194 }
195
196 $error = __( 'Your installed PHP Version is: ', 'carousel-slider' ) . PHP_VERSION . '. ';
197 $error .= sprintf(
198 /* translators: 1: min php version requires */
199 __( 'The Carousel Slider plugin requires PHP version %s or greater.', 'carousel-slider' ),
200 $this->min_php
201 );
202 ?>
203 <div class="error">
204 <p><?php printf( esc_html( $error ) ); ?></p>
205 </div>
206 <?php
207 }
208
209 /**
210 * Bail out if the php version is lower than
211 *
212 * @return void
213 */
214 public function auto_deactivate() {
215 if ( $this->is_supported_php() ) {
216 return;
217 }
218
219 deactivate_plugins( plugin_basename( __FILE__ ) );
220
221 $error = '<h1>' . __( 'An Error Occurred', 'carousel-slider' ) . '</h1>';
222 $error .= '<h2>' . __( 'Your installed PHP Version is: ', 'carousel-slider' ) . PHP_VERSION . '</h2>';
223 /* translators: 1: min php version requires */
224 $error .= '<p>' . sprintf( __( 'The Carousel Slider plugin requires PHP version %s or greater', 'carousel-slider' ), $this->min_php ) . '</p>';
225 $error .= '<p>' . sprintf(
226 /* translators: 1: php doc page link start, 2: php doc page link end */
227 __( 'The version of your PHP is %1$s unsupported and old %2$s. ', 'carousel-slider' ),
228 '<a href="https://php.net/supported-versions.php" target="_blank"><strong>',
229 '</strong></a>'
230 );
231 $error .= __( 'You should update your PHP software or contact your host regarding this matter.', 'carousel-slider' ) . '</p>';
232
233 $title = __( 'Plugin Activation Error', 'carousel-slider' );
234 wp_die( wp_kses_post( $error ), esc_html( $title ), [ 'back_link' => true ] );
235 }
236
237 /**
238 * Check if the PHP version is supported
239 *
240 * @return bool
241 */
242 private function is_supported_php() {
243 return ! version_compare( PHP_VERSION, $this->min_php, '<=' );
244 }
245 }
246 }
247
248 /**
249 * Begins execution of the plugin.
250 *
251 * Since everything within the plugin is registered via hooks,
252 * then kicking off the plugin from this point in the file does
253 * not affect the page life cycle.
254 */
255 Carousel_Slider::instance();
256