| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Slideshow SE |
| 4 |
Plugin URI: http://wordpress.org/extend/plugins/slideshow-se/ |
| 5 |
Description: The slideshow plugin is easily deployable on your website. Add any image that has already been uploaded to add to your slideshow, add text slides, or even add a video. Options and styles are customizable for every single slideshow on your website. |
| 6 |
Version: 2.5.8 |
| 7 |
Requires at least: 5.0 |
| 8 |
Tested up to: 6.1.1 |
| 9 |
Requires PHP: 5.0 |
| 10 |
Author: John West |
| 11 |
License: GPLv2 |
| 12 |
Text Domain: slideshow-se |
| 13 |
*/ |
| 14 |
|
| 15 |
// Exit if accessed directly. |
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Class SlideshowSEPluginMain fires up the application on plugin load and provides some |
| 22 |
* methods for the other classes to use like the auto-includer and the |
| 23 |
* base path/url returning method. |
| 24 |
* |
| 25 |
* @since 1.0.0 |
| 26 |
* @author Stefan Boonstra |
| 27 |
*/ |
| 28 |
class SlideshowSEPluginMain |
| 29 |
{ |
| 30 |
/** @var string $version */ |
| 31 |
static $version = '2.5.0'; |
| 32 |
|
| 33 |
/** |
| 34 |
* Bootstraps the application by assigning the right functions to |
| 35 |
* the right action hooks. |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
*/ |
| 39 |
static function bootStrap() |
| 40 |
{ |
| 41 |
self::autoInclude(); |
| 42 |
|
| 43 |
// Initialize localization on init |
| 44 |
add_action('init', array(__CLASS__, 'localize')); |
| 45 |
// Initialize the Gutenberg block |
| 46 |
add_action( 'init', 'f1rehead_slideshow_block_init' ); |
| 47 |
|
| 48 |
// Enqueue hooks |
| 49 |
add_action('wp_enqueue_scripts' , array(__CLASS__, 'enqueueFrontendScripts')); |
| 50 |
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueueBackendScripts')); |
| 51 |
|
| 52 |
// Ajax requests |
| 53 |
SlideshowSEPluginAJAX::init(); |
| 54 |
|
| 55 |
// Register slideshow post type |
| 56 |
SlideshowSEPluginPostType::init(); |
| 57 |
|
| 58 |
// Add general settings page |
| 59 |
SlideshowSEPluginGeneralSettings::init(); |
| 60 |
|
| 61 |
// Initialize stylesheet builder |
| 62 |
SlideshowSEPluginSlideshowStylesheet::init(); |
| 63 |
|
| 64 |
// Deploy slideshow on do_action('slideshow_deploy'); hook. |
| 65 |
add_action('slideshow_deploy', array('SlideshowSEPlugin', 'deploy')); |
| 66 |
|
| 67 |
// Initialize shortcode |
| 68 |
SlideshowSEPluginShortcode::init(); |
| 69 |
|
| 70 |
// Register widget |
| 71 |
add_action('widgets_init', array('SlideshowSEPluginWidget', 'registerWidget')); |
| 72 |
|
| 73 |
// Initialize plugin updater |
| 74 |
SlideshowSEPluginInstaller::init(); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Enqueues frontend scripts and styles. |
| 79 |
* |
| 80 |
* Should always be called on the wp_enqueue_scripts hook. |
| 81 |
* |
| 82 |
* @since 2.3.0 |
| 83 |
*/ |
| 84 |
static function enqueueFrontendScripts() |
| 85 |
{ |
| 86 |
// Enqueue slideshow script if lazy loading is enabled |
| 87 |
if (SlideshowSEPluginGeneralSettings::getEnableLazyLoading()) |
| 88 |
{ |
| 89 |
wp_enqueue_script( |
| 90 |
'slideshow-jquery-image-gallery-script', |
| 91 |
self::getPluginUrl() . '/js/min/all.frontend.min.js', |
| 92 |
array('jquery'), |
| 93 |
self::$version |
| 94 |
); |
| 95 |
|
| 96 |
wp_localize_script( |
| 97 |
'slideshow-jquery-image-gallery-script', |
| 98 |
'slideshow_jquery_image_gallery_script_adminURL', |
| 99 |
admin_url() |
| 100 |
); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Enqueues backend scripts and styles. |
| 106 |
* |
| 107 |
* Should always be called on the admin_enqueue_scrips hook. |
| 108 |
* |
| 109 |
* @since 2.2.12 |
| 110 |
*/ |
| 111 |
static function enqueueBackendScripts() |
| 112 |
{ |
| 113 |
// Function get_current_screen() should be defined, as this method is expected to fire at 'admin_enqueue_scripts' |
| 114 |
if (!function_exists('get_current_screen')) |
| 115 |
{ |
| 116 |
return; |
| 117 |
} |
| 118 |
|
| 119 |
$currentScreen = get_current_screen(); |
| 120 |
|
| 121 |
// Enqueue 3.5 uploader |
| 122 |
if ($currentScreen->post_type === 'slideshow' && |
| 123 |
function_exists('wp_enqueue_media')) |
| 124 |
{ |
| 125 |
wp_enqueue_media(); |
| 126 |
} |
| 127 |
|
| 128 |
wp_enqueue_script( |
| 129 |
'slideshow-se-jquery-image-gallery-backend-script', |
| 130 |
self::getPluginUrl() . '/js/min/all.backend.min.js', |
| 131 |
array( |
| 132 |
'jquery', |
| 133 |
'jquery-ui-sortable', |
| 134 |
'wp-color-picker' |
| 135 |
), |
| 136 |
SlideshowSEPluginMain::$version |
| 137 |
); |
| 138 |
|
| 139 |
wp_enqueue_style( |
| 140 |
'slideshow-se-jquery-image-gallery-backend-style', |
| 141 |
self::getPluginUrl() . '/css/all.backend.css', |
| 142 |
array( |
| 143 |
'wp-color-picker' |
| 144 |
), |
| 145 |
SlideshowSEPluginMain::$version |
| 146 |
); |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* Translates the plugin |
| 151 |
* |
| 152 |
* @since 1.0.0 |
| 153 |
*/ |
| 154 |
static function localize() |
| 155 |
{ |
| 156 |
load_plugin_textdomain( |
| 157 |
'slideshow-se', |
| 158 |
false, |
| 159 |
dirname(plugin_basename(__FILE__)) . '/languages/' |
| 160 |
); |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Returns url to the base directory of this plugin. |
| 165 |
* |
| 166 |
* @since 1.0.0 |
| 167 |
* @return string pluginUrl |
| 168 |
*/ |
| 169 |
static function getPluginUrl() |
| 170 |
{ |
| 171 |
return plugins_url('', __FILE__); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Returns path to the base directory of this plugin |
| 176 |
* |
| 177 |
* @since 1.0.0 |
| 178 |
* @return string pluginPath |
| 179 |
*/ |
| 180 |
static function getPluginPath() |
| 181 |
{ |
| 182 |
return dirname(__FILE__); |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* Outputs the passed view. It's good practice to pass an object like an stdClass to the $data variable, as it can |
| 187 |
* be easily checked for validity in the view itself using "instanceof". |
| 188 |
* |
| 189 |
* @since 2.3.0 |
| 190 |
* @param string $view |
| 191 |
* @param stdClass $data (Optional, defaults to stdClass) |
| 192 |
*/ |
| 193 |
static function outputView($view, $data = null) |
| 194 |
{ |
| 195 |
if (!($data instanceof stdClass)) |
| 196 |
{ |
| 197 |
$data = new stdClass(); |
| 198 |
} |
| 199 |
|
| 200 |
$file = self::getPluginPath() . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $view; |
| 201 |
|
| 202 |
if (file_exists($file)) |
| 203 |
{ |
| 204 |
include $file; |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
/** |
| 209 |
* Uses self::outputView to render the passed view. Returns the rendered view instead of outputting it. |
| 210 |
* |
| 211 |
* @since 2.3.0 |
| 212 |
* @param string $view |
| 213 |
* @param stdClass $data (Optional, defaults to null) |
| 214 |
* @return string |
| 215 |
*/ |
| 216 |
static function getView($view, $data = null) |
| 217 |
{ |
| 218 |
ob_start(); |
| 219 |
self::outputView($view, $data); |
| 220 |
return ob_get_clean(); |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* This function will load classes automatically on-call. |
| 225 |
* |
| 226 |
* @since 1.0.0 |
| 227 |
*/ |
| 228 |
static function autoInclude() |
| 229 |
{ |
| 230 |
if (!function_exists('spl_autoload_register')) |
| 231 |
{ |
| 232 |
return; |
| 233 |
} |
| 234 |
|
| 235 |
function SlideshowSEPluginAutoLoader($name) |
| 236 |
{ |
| 237 |
$name = str_replace('\\', DIRECTORY_SEPARATOR, $name); |
| 238 |
$file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $name . '.php'; |
| 239 |
|
| 240 |
if (is_file($file)) |
| 241 |
{ |
| 242 |
require_once $file; |
| 243 |
} |
| 244 |
} |
| 245 |
// Don't forget the render callback for the Gutenberg block |
| 246 |
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'block.php'; |
| 247 |
spl_autoload_register('SlideshowSEPluginAutoLoader'); |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
/** |
| 252 |
* Registers all block assets so that they can be enqueued through the block editor |
| 253 |
* in the corresponding context. |
| 254 |
* |
| 255 |
* @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/ |
| 256 |
*/ |
| 257 |
function f1rehead_slideshow_block_init() { |
| 258 |
$dir = dirname( __FILE__ ); |
| 259 |
|
| 260 |
$script_asset_path = "$dir/block/index.asset.php"; |
| 261 |
if ( ! file_exists( $script_asset_path ) ) { |
| 262 |
throw new Error( |
| 263 |
'You need to run `npm start` or `npm run build` for the "f1rehead/slideshow" block first.' |
| 264 |
); |
| 265 |
} |
| 266 |
$index_js = 'block/index.js'; |
| 267 |
$script_asset = require( $script_asset_path ); |
| 268 |
wp_register_script( |
| 269 |
'f1rehead-slideshow-block-editor', |
| 270 |
plugins_url( $index_js, __FILE__ ), |
| 271 |
$script_asset['dependencies'], |
| 272 |
$script_asset['version'] |
| 273 |
); |
| 274 |
|
| 275 |
$editor_css = 'block/index.css'; |
| 276 |
wp_register_style( |
| 277 |
'f1rehead-slideshow-block-editor', |
| 278 |
plugins_url( $editor_css, __FILE__ ), |
| 279 |
array(), |
| 280 |
filemtime( "$dir/$editor_css" ) |
| 281 |
); |
| 282 |
|
| 283 |
$style_css = 'block/style-index.css'; |
| 284 |
wp_register_style( |
| 285 |
'f1rehead-slideshow-block', |
| 286 |
plugins_url( $style_css, __FILE__ ), |
| 287 |
array(), |
| 288 |
filemtime( "$dir/$style_css" ) |
| 289 |
); |
| 290 |
|
| 291 |
// WP Localized globals. Use dynamic PHP stuff in JavaScript via `globals` object. |
| 292 |
wp_localize_script( |
| 293 |
'f1rehead-slideshow-block-editor', |
| 294 |
'globals', // Array containing dynamic data for a JS Global. |
| 295 |
[ |
| 296 |
'pluginDirPath' => plugin_dir_path( __DIR__ ), |
| 297 |
'pluginDirUrl' => plugin_dir_url( __DIR__ ), |
| 298 |
// Add data here to access from `globals` object. |
| 299 |
'slideshows' => get_posts(['posts_per_page' => -1, 'post_type' => 'slideshow']), |
| 300 |
] |
| 301 |
); |
| 302 |
|
| 303 |
register_block_type( 'f1rehead/slideshow', array( |
| 304 |
'editor_script' => 'f1rehead-slideshow-block-editor', |
| 305 |
'editor_style' => 'f1rehead-slideshow-block-editor', |
| 306 |
'style' => 'f1rehead-slideshow-block', |
| 307 |
'render_callback' => 'f1rehead_slideshow_render_slideshow_block', |
| 308 |
) ); |
| 309 |
} |
| 310 |
|
| 311 |
/** |
| 312 |
* Activate plugin |
| 313 |
*/ |
| 314 |
SlideShowSEPluginMain::bootStrap(); |
| 315 |
|