| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Ultimate Lightbox |
| 4 |
Plugin URI: http://www.EtoileWebDesign.com/plugins/ |
| 5 |
Description: A plugin that lets you add a lightbox to images on your site |
| 6 |
Author: Etoile Web Design |
| 7 |
Author URI: http://www.EtoileWebDesign.com/ |
| 8 |
Terms and Conditions: http://www.etoilewebdesign.com/plugin-terms-and-conditions/ |
| 9 |
Text Domain: ultimate-lightbox |
| 10 |
Version: 1.1.12 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) |
| 14 |
exit; |
| 15 |
|
| 16 |
if ( ! class_exists( 'ulbInit' ) ) { |
| 17 |
class ulbInit { |
| 18 |
|
| 19 |
// pointers to classes used by the plugin, where needed |
| 20 |
public $settings; |
| 21 |
|
| 22 |
/** |
| 23 |
* Initialize the plugin and register hooks |
| 24 |
*/ |
| 25 |
public function __construct() { |
| 26 |
|
| 27 |
self::constants(); |
| 28 |
self::includes(); |
| 29 |
self::instantiate(); |
| 30 |
self::wp_hooks(); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Define plugin constants. |
| 35 |
* |
| 36 |
* @since 1.0.0 |
| 37 |
* @access protected |
| 38 |
* @return void |
| 39 |
*/ |
| 40 |
protected function constants() { |
| 41 |
|
| 42 |
define( 'EWD_ULB_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
| 43 |
define( 'EWD_ULB_PLUGIN_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) ); |
| 44 |
define( 'EWD_ULB_PLUGIN_FNAME', plugin_basename( __FILE__ ) ); |
| 45 |
define( 'EWD_ULB_VERSION', '1.1.12' ); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Include necessary classes. |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* @access protected |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
protected function includes() { |
| 56 |
|
| 57 |
require_once( EWD_ULB_PLUGIN_DIR . '/includes/AboutUs.class.php' ); |
| 58 |
require_once( EWD_ULB_PLUGIN_DIR . '/includes/AttachmentOptions.class.php' ); |
| 59 |
require_once( EWD_ULB_PLUGIN_DIR . '/includes/DeactivationSurvey.class.php' ); |
| 60 |
require_once( EWD_ULB_PLUGIN_DIR . '/includes/Helper.class.php' ); |
| 61 |
require_once( EWD_ULB_PLUGIN_DIR . '/includes/InstallationWalkthrough.class.php' ); |
| 62 |
require_once( EWD_ULB_PLUGIN_DIR . '/includes/ReviewAsk.class.php' ); |
| 63 |
require_once( EWD_ULB_PLUGIN_DIR . '/includes/Settings.class.php' ); |
| 64 |
require_once( EWD_ULB_PLUGIN_DIR . '/includes/template-functions.php' ); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Spin up instances of our plugin classes. |
| 69 |
* |
| 70 |
* @since 1.0.0 |
| 71 |
* @access protected |
| 72 |
* @return void |
| 73 |
*/ |
| 74 |
protected function instantiate() { |
| 75 |
|
| 76 |
new ewdulbAttachmentOptions(); |
| 77 |
new ewdulbDeactivationSurvey(); |
| 78 |
new ewdulbInstallationWalkthrough(); |
| 79 |
new ewdulbReviewAsk(); |
| 80 |
|
| 81 |
$this->settings = new ewdulbSettings(); |
| 82 |
|
| 83 |
new ewdulbAboutUs(); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Run walk-through, load assets, add links to plugin listing, etc. |
| 88 |
* |
| 89 |
* @since 1.0.0 |
| 90 |
* @access protected |
| 91 |
* @return void |
| 92 |
*/ |
| 93 |
protected function wp_hooks() { |
| 94 |
|
| 95 |
register_activation_hook( __FILE__, array( $this, 'run_walkthrough' ) ); |
| 96 |
register_activation_hook( __FILE__, array( $this, 'convert_options' ) ); |
| 97 |
|
| 98 |
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); |
| 99 |
|
| 100 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ), 10, 1 ); |
| 101 |
add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ) ); |
| 102 |
add_action( 'wp_head', 'ewd_add_frontend_ajax_url' ); |
| 103 |
|
| 104 |
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Run the options conversion function on update if necessary |
| 109 |
* |
| 110 |
* @since 1.0.0 |
| 111 |
* @access protected |
| 112 |
* @return void |
| 113 |
*/ |
| 114 |
public function convert_options() { |
| 115 |
|
| 116 |
require_once( EWD_ULB_PLUGIN_DIR . '/includes/BackwardsCompatibility.class.php' ); |
| 117 |
new ewdulbBackwardsCompatibility(); |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Load the plugin textdomain for localisation |
| 122 |
* @since 1.0.0 |
| 123 |
*/ |
| 124 |
public function load_textdomain() { |
| 125 |
|
| 126 |
load_plugin_textdomain( 'ultimate-lightbox', false, EWD_ULB_PLUGIN_DIR . "/languages/" ); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Set a transient so that the walk-through gets run |
| 131 |
* @since 1.0.0 |
| 132 |
*/ |
| 133 |
public function run_walkthrough() { |
| 134 |
|
| 135 |
set_transient( 'ulb-getting-started', true, 30 ); |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Enqueue the admin-only CSS and Javascript |
| 140 |
* @since 1.0.0 |
| 141 |
*/ |
| 142 |
public function enqueue_admin_assets( $hook ) { |
| 143 |
global $ulb_controller; |
| 144 |
|
| 145 |
if ( $hook == 'upload.php' ) { |
| 146 |
|
| 147 |
wp_enqueue_script( 'ewd-ulb-admin', plugins_url('ultimate-lightbox/js/admin-upload-media.js'), array('jquery', 'media-editor'), true); |
| 148 |
} |
| 149 |
|
| 150 |
$image_upload_pages = array( |
| 151 |
'upload.php', |
| 152 |
'post-new.php', |
| 153 |
'post.php', |
| 154 |
); |
| 155 |
|
| 156 |
if ( in_array( $hook, $image_upload_pages ) ) { |
| 157 |
|
| 158 |
wp_enqueue_script( 'image-block-meta-js', EWD_ULB_PLUGIN_URL . '/assets/js/image-block-meta.js', array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-i18n' ), EWD_ULB_VERSION ); |
| 159 |
} |
| 160 |
|
| 161 |
$screen = get_current_screen(); |
| 162 |
if ( empty( $screen ) ) { |
| 163 |
|
| 164 |
return; |
| 165 |
} |
| 166 |
|
| 167 |
if ( $screen->base == 'toplevel_page_ulb-settings' || $screen->id == 'lightbox_page_ewd-ulb-about-us' ) { |
| 168 |
|
| 169 |
wp_enqueue_style( 'ewd-ulb-admin-css', EWD_ULB_PLUGIN_URL . '/assets/css/ewd-ulb-admin.css', array(), EWD_ULB_VERSION ); |
| 170 |
|
| 171 |
wp_enqueue_script( 'ewd-ulb-admin-js', EWD_ULB_PLUGIN_URL . '/assets/js/ewd-ulb-admin.js', array( 'jquery' ), EWD_ULB_VERSION ); |
| 172 |
} |
| 173 |
|
| 174 |
$settings = array( |
| 175 |
'nonce' => wp_create_nonce( 'ewd-ulb-admin-js' ), |
| 176 |
); |
| 177 |
|
| 178 |
wp_localize_script( 'ewd-ulb-admin-js', 'ewd_ulb_admin_php_data', $settings ); |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Register the front-end CSS and Javascript for the lightbox |
| 183 |
* @since 1.0.0 |
| 184 |
*/ |
| 185 |
function register_assets() { |
| 186 |
global $ulb_controller; |
| 187 |
|
| 188 |
if ( empty( $ulb_controller->settings->get_setting( 'add-lightbox' ) ) ) { return; } |
| 189 |
|
| 190 |
wp_enqueue_style( 'ewd-ulb-main', EWD_ULB_PLUGIN_URL . '/assets/css/ewd-ulb-main.css', EWD_ULB_VERSION ); |
| 191 |
wp_enqueue_style( 'ewd-ulb-twentytwenty', EWD_ULB_PLUGIN_URL . '/assets/css/twentytwenty.css', EWD_ULB_VERSION ); |
| 192 |
|
| 193 |
$deps = array( 'jquery' ); |
| 194 |
if ( in_array( 'woocommerce/woocommerce.php', (array) get_option( 'active_plugins', array() ), true ) ) { $deps[] = 'woocommerce'; } |
| 195 |
|
| 196 |
wp_enqueue_script( 'ewd-ulb', EWD_ULB_PLUGIN_URL . '/assets/js/ewd-ulb.js', $deps, EWD_ULB_VERSION ); |
| 197 |
|
| 198 |
$add_lightbox_data = array( |
| 199 |
'add_lightbox' => json_encode( $ulb_controller->settings->get_setting( 'add-lightbox' ) ), |
| 200 |
'image_class_list' => $ulb_controller->settings->get_setting( 'image-class-list' ), |
| 201 |
'image_selector_list' => $ulb_controller->settings->get_setting( 'image-selector-list' ), |
| 202 |
'min_height' => $ulb_controller->settings->get_setting( 'min-height' ), |
| 203 |
'min_width' => $ulb_controller->settings->get_setting( 'min-width' ), |
| 204 |
'overlay_text_source' => $ulb_controller->settings->get_setting( 'overlay-text-source' ) |
| 205 |
); |
| 206 |
|
| 207 |
wp_localize_script( 'ewd-ulb', 'ewd_ulb_php_add_data', $add_lightbox_data ); |
| 208 |
|
| 209 |
wp_enqueue_script( 'event-move', EWD_ULB_PLUGIN_URL . '/assets/js/jquery.event.move.js', array('jquery'), true ); |
| 210 |
wp_enqueue_script( 'twenty-twenty', EWD_ULB_PLUGIN_URL . '/assets/js/jquery.twentytwenty.js', array('jquery'), true ); |
| 211 |
wp_enqueue_script( 'ultimate-lightbox', EWD_ULB_PLUGIN_URL . '/assets/js/ultimate-lightbox.js', array('jquery', 'event-move', 'twenty-twenty'), EWD_ULB_VERSION ); |
| 212 |
wp_enqueue_script( 'jquery.mousewheel.min', EWD_ULB_PLUGIN_URL . '/assets/js/jquery.mousewheel.min.js', array('jquery', 'ultimate-lightbox'), true ); |
| 213 |
|
| 214 |
if ( $ulb_controller->settings->get_setting( 'disable-other-lightboxes' ) ) { |
| 215 |
wp_enqueue_script( 'ewd-ulb-disable-lightboxes', EWD_ULB_PLUGIN_URL . '/assets/js/ewd-ulb-disable-lightboxes.js', array('jquery'), true, true ); |
| 216 |
} |
| 217 |
|
| 218 |
$style_string = ulb_add_custom_styling(); |
| 219 |
|
| 220 |
$lightbox_controls = array( |
| 221 |
'top_right_controls' => $ulb_controller->settings->get_setting( 'top-right-controls' ), |
| 222 |
'top_left_controls' => $ulb_controller->settings->get_setting( 'top-left-controls' ), |
| 223 |
'bottom_right_controls' => $ulb_controller->settings->get_setting( 'bottom-right-controls' ), |
| 224 |
'bottom_left_controls' => $ulb_controller->settings->get_setting( 'bottom-left-controls' ) |
| 225 |
); |
| 226 |
|
| 227 |
$preset_style = $ulb_controller->settings->get_setting( 'preset-style' ); |
| 228 |
|
| 229 |
if ( $preset_style == 'matte' ) { |
| 230 |
$lightbox_class = ' ewd-ulb-style-matte'; |
| 231 |
$lightbox_background_class= ''; |
| 232 |
} |
| 233 |
elseif ( $preset_style == 'light' ) { |
| 234 |
$lightbox_class = ' ewd-ulb-style-matte ewd-ulb-style-light'; |
| 235 |
$lightbox_background_class= ' ewd-ulb-style-light'; |
| 236 |
} |
| 237 |
elseif ( $preset_style == 'contrast' ) { |
| 238 |
$lightbox_class = ' ewd-ulb-style-matte ewd-ulb-style-contrast'; |
| 239 |
$lightbox_background_class= ''; |
| 240 |
} |
| 241 |
elseif ( $preset_style == 'lightcontrast' ) { |
| 242 |
$lightbox_class = ' ewd-ulb-style-matte ewd-ulb-style-light ewd-ulb-style-contrast'; |
| 243 |
$lightbox_background_class= ' ewd-ulb-style-light'; |
| 244 |
} |
| 245 |
else { |
| 246 |
$lightbox_class = ''; |
| 247 |
$lightbox_background_class= ''; |
| 248 |
} |
| 249 |
|
| 250 |
$data_array = array( |
| 251 |
'custom_css' => $ulb_controller->settings->get_setting( 'custom-css' ), |
| 252 |
'styling_options' => $style_string, |
| 253 |
'background_close' => $ulb_controller->settings->get_setting( 'background-close' ), |
| 254 |
'gallery_loop' => $ulb_controller->settings->get_setting( 'gallery-loop' ), |
| 255 |
'show_thumbnails' => $ulb_controller->settings->get_setting( 'show-thumbnails' ), |
| 256 |
'show_thumbnail_toggle' => $ulb_controller->settings->get_setting( 'show-thumbnail-toggle' ), |
| 257 |
'show_progress_bar' => $ulb_controller->settings->get_setting( 'show-progress-bar' ), |
| 258 |
'autoplay' => $ulb_controller->settings->get_setting( 'start-autoplay' ), |
| 259 |
'autoplay_interval' => $ulb_controller->settings->get_setting( 'autoplay-interval' ), |
| 260 |
'transition_class' => $ulb_controller->settings->get_setting( 'transition-type' ), |
| 261 |
//'transition_speed' => $ulb_controller->settings->get_setting( 'transition-speed' ), |
| 262 |
'hide_elements' => $ulb_controller->settings->get_setting( 'mobile-hide-elements' ), |
| 263 |
'controls' => $lightbox_controls, |
| 264 |
'ulb_arrow' => $ulb_controller->settings->get_setting( 'arrow' ), |
| 265 |
'ulb_icon_set' => $ulb_controller->settings->get_setting( 'icon-set' ), |
| 266 |
'curtain_slide' => $ulb_controller->settings->get_setting( 'curtain-slide' ), |
| 267 |
'mousewheel_navigation' => $ulb_controller->settings->get_setting( 'mousewheel-navigation' ), |
| 268 |
'lightbox_class' => $lightbox_class, |
| 269 |
'lightbox_background_class' => $lightbox_background_class, |
| 270 |
); |
| 271 |
|
| 272 |
wp_localize_script( 'ultimate-lightbox', 'ewd_ulb_php_data', $data_array ); |
| 273 |
} |
| 274 |
|
| 275 |
/** |
| 276 |
* Add links to the plugin listing on the installed plugins page |
| 277 |
* @since 1.0.0 |
| 278 |
*/ |
| 279 |
public function plugin_action_links( $links, $plugin ) { |
| 280 |
|
| 281 |
if ( $plugin == EWD_ULB_PLUGIN_FNAME ) { |
| 282 |
|
| 283 |
$links['settings'] = '<a href="admin.php?page=ulb-settings" title="' . __( 'Head to the settings page for Ultimate Lightbox', 'ultimate-lightbox' ) . '">' . __( 'Settings', 'ultimate-lightbox' ) . '</a>'; |
| 284 |
} |
| 285 |
|
| 286 |
return $links; |
| 287 |
|
| 288 |
} |
| 289 |
|
| 290 |
} |
| 291 |
} // endif; |
| 292 |
|
| 293 |
global $ulb_controller; |
| 294 |
$ulb_controller = new ulbInit(); |
| 295 |
|
| 296 |
do_action( 'ewd_ulb_initialized' ); |