class-settings-addons.php
4 months ago
class-settings-base.php
5 months ago
class-settings-builder.php
5 months ago
class-settings-capabilities.php
5 months ago
class-settings-folders.php
5 months ago
class-settings-galleries.php
5 months ago
class-settings-general.php
5 months ago
class-settings-licenses.php
5 months ago
class-settings-lightboxes.php
4 months ago
class-settings-remote-library.php
5 months ago
class-settings-general.php
251 lines
| 1 | <?php |
| 2 | // exit if accessed directly |
| 3 | if ( ! defined( 'ABSPATH' ) ) |
| 4 | exit; |
| 5 | |
| 6 | /** |
| 7 | * Responsive_Lightbox_Settings_General class. |
| 8 | * |
| 9 | * General settings tab for the new Settings API. |
| 10 | * Handles main plugin settings like lightbox script selection and general options. |
| 11 | * |
| 12 | * @class Responsive_Lightbox_Settings_General |
| 13 | */ |
| 14 | class Responsive_Lightbox_Settings_General extends Responsive_Lightbox_Settings_Base { |
| 15 | |
| 16 | /** |
| 17 | * Tab key identifier. |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | const TAB_KEY = 'settings'; |
| 22 | |
| 23 | /** |
| 24 | * Validate settings for General tab. |
| 25 | * |
| 26 | * Handles field sanitization, WooCommerce auto-enable rule, |
| 27 | * and system field preservation (update_notice, update_version). |
| 28 | * |
| 29 | * @param array $input Input data from form submission. |
| 30 | * @return array Validated data. |
| 31 | */ |
| 32 | public function validate( $input ) { |
| 33 | // check if this is a reset operation |
| 34 | if ( $this->is_reset_request() ) { |
| 35 | $input = $this->merge_with_defaults( [] ); |
| 36 | // preserve system fields even on reset |
| 37 | $input = $this->preserve_system_fields( $input, [ 'update_version', 'update_notice' ] ); |
| 38 | add_settings_error( 'reset_rl_settings', 'settings_restored', esc_html__( 'Settings restored to defaults.', 'responsive-lightbox' ), 'updated' ); |
| 39 | return $input; |
| 40 | } |
| 41 | |
| 42 | // sanitize all fields |
| 43 | $input = $this->sanitize_fields( $input, 'settings' ); |
| 44 | |
| 45 | // merge with saved options to preserve fields not in current form |
| 46 | $input = $this->merge_with_saved( $input ); |
| 47 | |
| 48 | // preserve system fields (version tracking, update notices) |
| 49 | $input = $this->preserve_system_fields( $input, [ 'update_notice' ] ); |
| 50 | |
| 51 | // business rule: WooCommerce lightbox must be enabled when using RL gallery |
| 52 | if ( isset( $input['default_woocommerce_gallery'] ) && $input['default_woocommerce_gallery'] !== 'default' ) { |
| 53 | $input['woocommerce_gallery_lightbox'] = true; |
| 54 | } |
| 55 | |
| 56 | return $input; |
| 57 | } |
| 58 | |
| 59 | /** * Provide settings data for the General settings tab. |
| 60 | * |
| 61 | * @param array $data Settings data. |
| 62 | * @return array |
| 63 | */ |
| 64 | public function settings_data( $data ) { |
| 65 | $rl = Responsive_Lightbox(); |
| 66 | |
| 67 | // get scripts from helper class |
| 68 | $scripts = []; |
| 69 | foreach ( Responsive_Lightbox_Settings_Data::get_scripts() as $key => $value ) { |
| 70 | $scripts[$key] = $value['name']; |
| 71 | } |
| 72 | |
| 73 | // get image sizes |
| 74 | $sizes = apply_filters( |
| 75 | 'image_size_names_choose', |
| 76 | [ |
| 77 | 'thumbnail' => __( 'Thumbnail', 'responsive-lightbox' ), |
| 78 | 'medium' => __( 'Medium', 'responsive-lightbox' ), |
| 79 | 'large' => __( 'Large', 'responsive-lightbox' ), |
| 80 | 'full' => __( 'Full Size', 'responsive-lightbox' ) |
| 81 | ] |
| 82 | ); |
| 83 | |
| 84 | // get gallery types |
| 85 | $gallery_types = $rl->get_data( 'gallery_types' ); |
| 86 | $galleries = $builder_galleries = wp_parse_args( apply_filters( 'rl_gallery_types', [] ), $gallery_types ); |
| 87 | unset( $builder_galleries['default'] ); |
| 88 | |
| 89 | // image title options from helper class |
| 90 | $image_titles = Responsive_Lightbox_Settings_Data::get_image_titles(); |
| 91 | |
| 92 | $data[self::TAB_KEY] = [ |
| 93 | 'option_name' => 'responsive_lightbox_settings', |
| 94 | 'option_group' => 'responsive_lightbox_settings', |
| 95 | 'validate' => [ $this, 'validate' ], |
| 96 | 'sections' => [ |
| 97 | 'responsive_lightbox_settings' => [ |
| 98 | 'title' => __( 'General Settings', 'responsive-lightbox' ), |
| 99 | 'description' => '', |
| 100 | 'fields' => [ |
| 101 | 'tour' => [ |
| 102 | 'title' => __( 'Introduction Tour', 'responsive-lightbox' ), |
| 103 | 'type' => 'button', |
| 104 | 'label' => __( 'Start Tour', 'responsive-lightbox' ), |
| 105 | 'description' => __( 'Take this tour to quickly learn about the use of this plugin.', 'responsive-lightbox' ), |
| 106 | 'class' => 'button-primary button-hero', |
| 107 | 'url' => wp_nonce_url( admin_url( 'admin.php?page=responsive-lightbox-settings&tab=settings&rl_start_tour=1' ), 'rl-start-tour', 'rl_nonce' ) |
| 108 | ], |
| 109 | 'script' => [ |
| 110 | 'title' => __( 'Default Lightbox', 'responsive-lightbox' ), |
| 111 | 'type' => 'select', |
| 112 | 'description' => sprintf( __( 'Select your preferred ligthbox effect script or get one from our <a href="%s">premium extensions</a>.', 'responsive-lightbox' ), wp_nonce_url( add_query_arg( [ 'action' => 'rl-hide-notice' ], admin_url( 'admin.php?page=responsive-lightbox-settings&tab=addons' ) ), 'rl_action', 'rl_nonce' ) ), |
| 113 | 'options' => $scripts |
| 114 | ], |
| 115 | 'selector' => [ |
| 116 | 'title' => __( 'Selector', 'responsive-lightbox' ), |
| 117 | 'type' => 'text', |
| 118 | 'description' => __( 'Enter the rel selector lightbox effect will be applied to.', 'responsive-lightbox' ) |
| 119 | ], |
| 120 | 'image_links' => [ |
| 121 | 'title' => __( 'Images', 'responsive-lightbox' ), |
| 122 | 'type' => 'boolean', |
| 123 | 'label' => __( 'Enable lightbox for WordPress image links.', 'responsive-lightbox' ) |
| 124 | ], |
| 125 | 'image_title' => [ |
| 126 | 'title' => __( 'Single Image Title', 'responsive-lightbox' ), |
| 127 | 'type' => 'select', |
| 128 | 'description' => __( 'Select title for single images.', 'responsive-lightbox' ), |
| 129 | 'options' => $image_titles |
| 130 | ], |
| 131 | 'image_caption' => [ |
| 132 | 'title' => __( 'Single Image Caption', 'responsive-lightbox' ), |
| 133 | 'type' => 'select', |
| 134 | 'description' => __( 'Select caption for single images (if supported by selected lightbox and/or gallery).', 'responsive-lightbox' ), |
| 135 | 'options' => $image_titles |
| 136 | ], |
| 137 | 'images_as_gallery' => [ |
| 138 | 'title' => __( 'Single Images as Gallery', 'responsive-lightbox' ), |
| 139 | 'type' => 'boolean', |
| 140 | 'label' => __( 'Display single post images as a gallery.', 'responsive-lightbox' ) |
| 141 | ], |
| 142 | 'galleries' => [ |
| 143 | 'title' => __( 'Galleries', 'responsive-lightbox' ), |
| 144 | 'type' => 'boolean', |
| 145 | 'label' => __( 'Enable lightbox for WordPress image galleries.', 'responsive-lightbox' ) |
| 146 | ], |
| 147 | 'default_gallery' => [ |
| 148 | 'title' => __( 'Default Gallery', 'responsive-lightbox' ), |
| 149 | 'type' => 'select', |
| 150 | 'description' => sprintf( __( 'Select your preferred default gallery style or get one from our <a href="%s">premium extensions</a>.', 'responsive-lightbox' ), wp_nonce_url( add_query_arg( [ 'action' => 'rl-hide-notice' ], admin_url( 'admin.php?page=responsive-lightbox-settings&tab=addons' ) ), 'rl_action', 'rl_nonce' ) ), |
| 151 | 'options' => $galleries |
| 152 | ], |
| 153 | 'builder_gallery' => [ |
| 154 | 'title' => __( 'Builder Gallery', 'responsive-lightbox' ), |
| 155 | 'type' => 'select', |
| 156 | 'description' => __( 'Select your preferred default builder gallery style.', 'responsive-lightbox' ), |
| 157 | 'options' => $builder_galleries |
| 158 | ], |
| 159 | 'default_woocommerce_gallery' => [ |
| 160 | 'title' => __( 'WooCommerce Gallery', 'responsive-lightbox' ), |
| 161 | 'type' => 'select', |
| 162 | 'disabled' => ! class_exists( 'WooCommerce' ), |
| 163 | 'description' => __( 'Select your preferred gallery style for WooCommerce product gallery.', 'responsive-lightbox' ), |
| 164 | 'options' => $galleries |
| 165 | ], |
| 166 | 'gallery_image_size' => [ |
| 167 | 'title' => __( 'Gallery Image Size', 'responsive-lightbox' ), |
| 168 | 'type' => 'select', |
| 169 | 'description' => __( 'Select image size for gallery image links.', 'responsive-lightbox' ), |
| 170 | 'options' => $sizes |
| 171 | ], |
| 172 | 'gallery_image_title' => [ |
| 173 | 'title' => __( 'Gallery Image Title', 'responsive-lightbox' ), |
| 174 | 'type' => 'select', |
| 175 | 'description' => __( 'Select title for the gallery images.', 'responsive-lightbox' ), |
| 176 | 'options' => $image_titles |
| 177 | ], |
| 178 | 'gallery_image_caption' => [ |
| 179 | 'title' => __( 'Gallery Image Caption', 'responsive-lightbox' ), |
| 180 | 'type' => 'select', |
| 181 | 'description' => __( 'Select caption for the gallery images (if supported by selected lightbox and/or gallery).', 'responsive-lightbox' ), |
| 182 | 'options' => $image_titles |
| 183 | ], |
| 184 | 'videos' => [ |
| 185 | 'title' => __( 'Videos', 'responsive-lightbox' ), |
| 186 | 'type' => 'boolean', |
| 187 | 'label' => __( 'Enable lightbox for YouTube and Vimeo video links.', 'responsive-lightbox' ) |
| 188 | ], |
| 189 | 'widgets' => [ |
| 190 | 'title' => __( 'Widgets', 'responsive-lightbox' ), |
| 191 | 'type' => 'boolean', |
| 192 | 'label' => __( 'Enable lightbox for widgets content.', 'responsive-lightbox' ) |
| 193 | ], |
| 194 | 'comments' => [ |
| 195 | 'title' => __( 'Comments', 'responsive-lightbox' ), |
| 196 | 'type' => 'boolean', |
| 197 | 'label' => __( 'Enable lightbox for comments content.', 'responsive-lightbox' ) |
| 198 | ], |
| 199 | 'force_custom_gallery' => [ |
| 200 | 'title' => __( 'Force Lightbox', 'responsive-lightbox' ), |
| 201 | 'type' => 'boolean', |
| 202 | 'label' => __( 'Try to force lightbox for custom WP gallery replacements, like Jetpack or Visual Composer galleries.', 'responsive-lightbox' ) |
| 203 | ], |
| 204 | 'woocommerce_gallery_lightbox' => [ |
| 205 | 'title' => __( 'WooCommerce Lightbox', 'responsive-lightbox' ), |
| 206 | 'type' => 'boolean', |
| 207 | 'label' => __( 'Replace WooCommerce product gallery lightbox.', 'responsive-lightbox' ), |
| 208 | 'disabled' => ! class_exists( 'WooCommerce' ) || Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] !== 'default' |
| 209 | ], |
| 210 | 'enable_custom_events' => [ |
| 211 | 'title' => __( 'Custom Events', 'responsive-lightbox' ), |
| 212 | 'type' => 'boolean', |
| 213 | 'label' => __( 'Enable triggering lightbox on custom jQuery events.', 'responsive-lightbox' ) |
| 214 | ], |
| 215 | 'custom_events' => [ |
| 216 | 'title' => '', |
| 217 | 'type' => 'text', |
| 218 | 'description' => __( 'Enter a space separated list of custom jQuery events.', 'responsive-lightbox' ), |
| 219 | 'logic' => [ 'field' => 'enable_custom_events', 'operator' => 'is', 'value' => 'true' ], |
| 220 | 'animation' => 'slide' |
| 221 | ], |
| 222 | 'loading_place' => [ |
| 223 | 'title' => __( 'Loading Place', 'responsive-lightbox' ), |
| 224 | 'type' => 'radio', |
| 225 | 'description' => __( 'Select where all the lightbox scripts should be placed.', 'responsive-lightbox' ), |
| 226 | 'options' => [ |
| 227 | 'header' => __( 'Header', 'responsive-lightbox' ), |
| 228 | 'footer' => __( 'Footer', 'responsive-lightbox' ) |
| 229 | ] |
| 230 | ], |
| 231 | 'conditional_loading' => [ |
| 232 | 'title' => __( 'Conditional Loading', 'responsive-lightbox' ), |
| 233 | 'type' => 'boolean', |
| 234 | 'label' => __( 'Enable to load scripts and styles only on pages that have images or galleries in post content.', 'responsive-lightbox' ) |
| 235 | ], |
| 236 | 'deactivation_delete' => [ |
| 237 | 'title' => __( 'Delete Data', 'responsive-lightbox' ), |
| 238 | 'type' => 'boolean', |
| 239 | 'label' => __( 'Delete all plugin settings on deactivation.', 'responsive-lightbox' ), |
| 240 | 'description' => __( 'Enable this to delete all plugin settings and also delete all plugin capabilities from all users on deactivation.', 'responsive-lightbox' ) |
| 241 | ] |
| 242 | ] |
| 243 | ] |
| 244 | ] |
| 245 | ]; |
| 246 | |
| 247 | return $data; |
| 248 | } |
| 249 | |
| 250 | } |
| 251 |