| 1 |
<?php |
| 2 |
|
| 3 |
namespace ISC\Settings\Sections; |
| 4 |
|
| 5 |
use ISC\Settings; |
| 6 |
|
| 7 |
/** |
| 8 |
* Compatibility checks for known third-party integrations. |
| 9 |
*/ |
| 10 |
class Compatibility extends Settings\Section { |
| 11 |
|
| 12 |
/** |
| 13 |
* Compatibility notices for the current request. |
| 14 |
* |
| 15 |
* @var array<int,array<string,mixed>>|null |
| 16 |
*/ |
| 17 |
private $notices = null; |
| 18 |
|
| 19 |
/** |
| 20 |
* Add settings section when needed. |
| 21 |
*/ |
| 22 |
public function add_settings_section() { |
| 23 |
if ( [] === $this->get_notices() ) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
add_settings_section( |
| 28 |
'isc_settings_section_compatibility', |
| 29 |
__( 'Compatibility', 'image-source-control-isc' ), |
| 30 |
[ $this, 'render_settings_section' ], |
| 31 |
'isc_settings_page' |
| 32 |
); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Return all compatibility notices for the current site. |
| 37 |
* |
| 38 |
* @return array<int,array<string,mixed>> |
| 39 |
*/ |
| 40 |
public function get_notices(): array { |
| 41 |
if ( null !== $this->notices ) { |
| 42 |
return $this->notices; |
| 43 |
} |
| 44 |
|
| 45 |
$notices = []; |
| 46 |
|
| 47 |
foreach ( $this->get_checks() as $check ) { |
| 48 |
$notice = $this->{$check}(); |
| 49 |
|
| 50 |
if ( is_array( $notice ) ) { |
| 51 |
$notices[] = wp_parse_args( |
| 52 |
$notice, |
| 53 |
[ |
| 54 |
'name' => '', |
| 55 |
'description' => '', |
| 56 |
'manual_url' => '', |
| 57 |
'show_pro_link' => false, |
| 58 |
] |
| 59 |
); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
$this->notices = $notices; |
| 64 |
|
| 65 |
return $this->notices; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Render the compatibility settings section. |
| 70 |
*/ |
| 71 |
public function render_settings_section() { |
| 72 |
$notices = $this->get_notices(); |
| 73 |
|
| 74 |
require ISCPATH . '/admin/templates/settings/compatibility.php'; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Return the compatibility check method names. |
| 79 |
* |
| 80 |
* @return string[] |
| 81 |
*/ |
| 82 |
protected function get_checks(): array { |
| 83 |
return [ |
| 84 |
'check_advanced_custom_fields_unused_images', |
| 85 |
'check_avada_builder', |
| 86 |
'check_blocksy_theme', |
| 87 |
'check_divi', |
| 88 |
'check_elementor', |
| 89 |
'check_flatsome_unused_images', |
| 90 |
'check_gallery_block_lightbox', |
| 91 |
'check_jet_engine', |
| 92 |
'check_kadence_carousel', |
| 93 |
'check_kadence_blocks', |
| 94 |
'check_kadence_shop_kit_unused_images', |
| 95 |
'check_kadence_theme_kit_pro_unused_images', |
| 96 |
'check_newsletter_unused_images', |
| 97 |
'check_polylang', |
| 98 |
'check_soledad', |
| 99 |
'check_woocommerce_unused_images', |
| 100 |
'check_wp_bakery', |
| 101 |
'check_wp_all_import', |
| 102 |
'check_wpml', |
| 103 |
]; |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Check if Advanced Custom Fields is active in combination with the Unused Images module. |
| 108 |
* |
| 109 |
* @return array|null |
| 110 |
*/ |
| 111 |
public function check_advanced_custom_fields_unused_images() { |
| 112 |
if ( ! class_exists( 'ACF' ) || ! \ISC\Plugin::is_module_enabled( 'unused_images' ) ) { |
| 113 |
return null; |
| 114 |
} |
| 115 |
|
| 116 |
return [ |
| 117 |
'name' => 'Advanced Custom Fields', |
| 118 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#Advanced_Custom_Fields', |
| 119 |
'show_pro_link' => true, |
| 120 |
]; |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Check if Avada Builder is active. |
| 125 |
* |
| 126 |
* @return array|null |
| 127 |
*/ |
| 128 |
public function check_avada_builder() { |
| 129 |
if ( ! defined( 'FUSION_BUILDER_VERSION' ) || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) ) { |
| 130 |
return null; |
| 131 |
} |
| 132 |
|
| 133 |
return [ |
| 134 |
'name' => 'Avada Builder', |
| 135 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#Avada_Builder', |
| 136 |
'show_pro_link' => true, |
| 137 |
]; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Check if Blocksy theme is active. |
| 142 |
* |
| 143 |
* @return array|null |
| 144 |
*/ |
| 145 |
public function check_blocksy_theme() { |
| 146 |
if ( ! $this->is_current_theme( 'blocksy' ) || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) ) { |
| 147 |
return null; |
| 148 |
} |
| 149 |
|
| 150 |
return [ |
| 151 |
'name' => 'Blocksy', |
| 152 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#Blocksy', |
| 153 |
'show_pro_link' => true, |
| 154 |
]; |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Check if Divi Builder is active. |
| 159 |
* |
| 160 |
* @return array|null |
| 161 |
*/ |
| 162 |
public function check_divi() { |
| 163 |
if ( ! defined( 'ET_SHORTCODES_VERSION' ) || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) ) { |
| 164 |
return null; |
| 165 |
} |
| 166 |
|
| 167 |
return [ |
| 168 |
'name' => 'Divi Builder', |
| 169 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#Divi', |
| 170 |
'show_pro_link' => true, |
| 171 |
]; |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Check if Elementor is active. |
| 176 |
* |
| 177 |
* @return array|null |
| 178 |
*/ |
| 179 |
public function check_elementor() { |
| 180 |
if ( ! defined( 'ELEMENTOR_VERSION' ) || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) ) { |
| 181 |
return null; |
| 182 |
} |
| 183 |
|
| 184 |
return [ |
| 185 |
'name' => 'Elementor', |
| 186 |
'description' => sprintf( |
| 187 |
// translators: %s is the name of the theme or page builder, e.g. Divi. |
| 188 |
__( 'Enable support for %s background images.', 'image-source-control-isc' ), |
| 189 |
'Elementor' |
| 190 |
), |
| 191 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#Elementor', |
| 192 |
'show_pro_link' => true, |
| 193 |
]; |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* Check if Flatsome UX Builder is active in combination with the Unused Images module and Pro is not. |
| 198 |
* |
| 199 |
* @return array|null |
| 200 |
*/ |
| 201 |
public function check_flatsome_unused_images() { |
| 202 |
if ( ! defined( 'UX_BUILDER_VERSION' ) || \ISC\Plugin::is_pro() || ! \ISC\Plugin::is_module_enabled( 'unused_images' ) ) { |
| 203 |
return null; |
| 204 |
} |
| 205 |
|
| 206 |
return [ |
| 207 |
'name' => 'Flatsome UX Builder', |
| 208 |
'show_pro_link' => true, |
| 209 |
]; |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* Check if the Gallery Block Lightbox plugin is active. |
| 214 |
* No notice when Pro is enabled since it resolves the issue automatically. |
| 215 |
* |
| 216 |
* @return array|null |
| 217 |
*/ |
| 218 |
public function check_gallery_block_lightbox() { |
| 219 |
if ( ! function_exists( '\Gallery_Block_Lightbox\register_assets' ) || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) || \ISC\Plugin::is_pro() ) { |
| 220 |
return null; |
| 221 |
} |
| 222 |
|
| 223 |
return [ |
| 224 |
'name' => 'Gallery Block Lightbox', |
| 225 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#Gallery_Block_Lightbox', |
| 226 |
'show_pro_link' => true, |
| 227 |
]; |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Check if JetEngine is active. |
| 232 |
* |
| 233 |
* @return array|null |
| 234 |
*/ |
| 235 |
public function check_jet_engine() { |
| 236 |
if ( ! class_exists( 'Jet_Engine', false ) || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) ) { |
| 237 |
return null; |
| 238 |
} |
| 239 |
|
| 240 |
return [ |
| 241 |
'name' => 'JetEngine', |
| 242 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#JetEngine', |
| 243 |
'show_pro_link' => true, |
| 244 |
]; |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* Check if Kadence Related Content Carousel is active and Pro is not |
| 249 |
* |
| 250 |
* @return array|null |
| 251 |
*/ |
| 252 |
public function check_kadence_carousel() { |
| 253 |
if ( ! defined( 'KTRC_VERSION' ) || \ISC\Plugin::is_pro() || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) ) { |
| 254 |
return null; |
| 255 |
} |
| 256 |
|
| 257 |
return [ |
| 258 |
'name' => 'Kadence Related Content Carousel', |
| 259 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#Kadence', |
| 260 |
'show_pro_link' => true, |
| 261 |
]; |
| 262 |
} |
| 263 |
|
| 264 |
/** |
| 265 |
* Check if Kadence Blocks is active and Pro is not |
| 266 |
* |
| 267 |
* @return array|null |
| 268 |
*/ |
| 269 |
public function check_kadence_blocks() { |
| 270 |
if ( ! defined( 'KADENCE_BLOCKS_VERSION' ) || \ISC\Plugin::is_pro() || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) ) { |
| 271 |
return null; |
| 272 |
} |
| 273 |
|
| 274 |
return [ |
| 275 |
'name' => 'Kadence Blocks', |
| 276 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#Kadence', |
| 277 |
'show_pro_link' => true, |
| 278 |
]; |
| 279 |
} |
| 280 |
|
| 281 |
/** |
| 282 |
* Check if Kadence Shop Kit is active in combination with the Unused Images module and Pro is not. |
| 283 |
* |
| 284 |
* @return array|null |
| 285 |
*/ |
| 286 |
public function check_kadence_shop_kit_unused_images() { |
| 287 |
if ( ! defined( 'KADENCE_WOO_EXTRAS_VERSION' ) || \ISC\Plugin::is_pro() || ! \ISC\Plugin::is_module_enabled( 'unused_images' ) ) { |
| 288 |
return null; |
| 289 |
} |
| 290 |
|
| 291 |
return [ |
| 292 |
'name' => 'Kadence Shop Kit', |
| 293 |
'show_pro_link' => true, |
| 294 |
]; |
| 295 |
} |
| 296 |
|
| 297 |
/** |
| 298 |
* Check if Kadence Theme Kit Pro is active in combination with the Unused Images module and Pro is not. |
| 299 |
* |
| 300 |
* @return array|null |
| 301 |
*/ |
| 302 |
public function check_kadence_theme_kit_pro_unused_images() { |
| 303 |
if ( ! defined( 'KTP_VERSION' ) || \ISC\Plugin::is_pro() || ! \ISC\Plugin::is_module_enabled( 'unused_images' ) ) { |
| 304 |
return null; |
| 305 |
} |
| 306 |
|
| 307 |
return [ |
| 308 |
'name' => 'Kadence Theme Kit Pro', |
| 309 |
'show_pro_link' => true, |
| 310 |
]; |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Check if Newsletter plugin is active in combination with the Unused Images module and Pro is not. |
| 315 |
* |
| 316 |
* @return array|null |
| 317 |
*/ |
| 318 |
public function check_newsletter_unused_images() { |
| 319 |
if ( ! defined( 'NEWSLETTER_VERSION' ) || \ISC\Plugin::is_pro() || ! \ISC\Plugin::is_module_enabled( 'unused_images' ) ) { |
| 320 |
return null; |
| 321 |
} |
| 322 |
|
| 323 |
return [ |
| 324 |
'name' => 'Newsletter', |
| 325 |
'show_pro_link' => true, |
| 326 |
]; |
| 327 |
} |
| 328 |
|
| 329 |
/** |
| 330 |
* Check if Polylang and the Image Source module are active. |
| 331 |
* |
| 332 |
* @return array|null |
| 333 |
*/ |
| 334 |
public function check_polylang() { |
| 335 |
if ( ! defined( 'POLYLANG_VERSION' ) || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) ) { |
| 336 |
return null; |
| 337 |
} |
| 338 |
|
| 339 |
return [ |
| 340 |
'name' => 'Polylang', |
| 341 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#Polylang', |
| 342 |
'show_pro_link' => false, |
| 343 |
]; |
| 344 |
} |
| 345 |
|
| 346 |
/** |
| 347 |
* Check if Soledad theme is active and Pro is not. |
| 348 |
* |
| 349 |
* @return array|null |
| 350 |
*/ |
| 351 |
public function check_soledad() { |
| 352 |
if ( ! defined( 'PENCI_SOLEDAD_VERSION' ) || \ISC\Plugin::is_pro() || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) ) { |
| 353 |
return null; |
| 354 |
} |
| 355 |
|
| 356 |
return [ |
| 357 |
'name' => 'Soledad', |
| 358 |
'show_pro_link' => true, |
| 359 |
]; |
| 360 |
} |
| 361 |
|
| 362 |
/** |
| 363 |
* Check if WooCommerce is active in combination with the Unused Images module and Pro is not. |
| 364 |
* |
| 365 |
* @return array|null |
| 366 |
*/ |
| 367 |
public function check_woocommerce_unused_images() { |
| 368 |
if ( ! class_exists( 'WooCommerce' ) || \ISC\Plugin::is_pro() || ! \ISC\Plugin::is_module_enabled( 'unused_images' ) ) { |
| 369 |
return null; |
| 370 |
} |
| 371 |
|
| 372 |
return [ |
| 373 |
'name' => 'WooCommerce', |
| 374 |
'show_pro_link' => true, |
| 375 |
]; |
| 376 |
} |
| 377 |
|
| 378 |
/** |
| 379 |
* Check if WPBakery is active and Pro is not. |
| 380 |
* |
| 381 |
* @return array|null |
| 382 |
*/ |
| 383 |
public function check_wp_bakery() { |
| 384 |
if ( ! defined( 'WPB_VC_VERSION' ) || \ISC\Plugin::is_pro() || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) ) { |
| 385 |
return null; |
| 386 |
} |
| 387 |
|
| 388 |
return [ |
| 389 |
'name' => 'WPBakery Page Builder (formerly Visual Composer)', |
| 390 |
'description' => sprintf( |
| 391 |
// translators: %s is the name of the theme or page builder, e.g. Divi. |
| 392 |
__( 'Enable support for %s background images.', 'image-source-control-isc' ), |
| 393 |
'WPBakery Page Builder' |
| 394 |
), |
| 395 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#WPBakery_Page_Builder', |
| 396 |
'show_pro_link' => true, |
| 397 |
]; |
| 398 |
} |
| 399 |
|
| 400 |
/** |
| 401 |
* Check if WP All Import and the Image Source module are active. |
| 402 |
* |
| 403 |
* @return array|null |
| 404 |
*/ |
| 405 |
public function check_wp_all_import() { |
| 406 |
if ( ! defined( 'PMXI_VERSION' ) || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) ) { |
| 407 |
return null; |
| 408 |
} |
| 409 |
|
| 410 |
return [ |
| 411 |
'name' => 'WP All Import', |
| 412 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#WP_All_Import', |
| 413 |
'show_pro_link' => false, |
| 414 |
]; |
| 415 |
} |
| 416 |
|
| 417 |
/** |
| 418 |
* Check if WPML is active. |
| 419 |
* |
| 420 |
* @return array|null |
| 421 |
*/ |
| 422 |
public function check_wpml() { |
| 423 |
if ( ! defined( 'ICL_SITEPRESS_VERSION' ) || ! \ISC\Plugin::is_module_enabled( 'image_sources' ) ) { |
| 424 |
return null; |
| 425 |
} |
| 426 |
|
| 427 |
return [ |
| 428 |
'name' => 'WPML', |
| 429 |
'manual_url' => 'https://imagesourcecontrol.com/documentation/compatibility/#WPML', |
| 430 |
'show_pro_link' => false, |
| 431 |
]; |
| 432 |
} |
| 433 |
|
| 434 |
/** |
| 435 |
* Helper function to check if the current theme (parent or child) is a specific theme. |
| 436 |
* |
| 437 |
* @param string $theme_slug The slug of the theme to check for. |
| 438 |
* @return bool True if the current theme matches the specified theme slug, false otherwise. |
| 439 |
*/ |
| 440 |
public function is_current_theme( string $theme_slug ): bool { |
| 441 |
$current_theme = wp_get_theme(); |
| 442 |
|
| 443 |
if ( strcasecmp( $current_theme->get_stylesheet(), $theme_slug ) === 0 || strcasecmp( $current_theme->get_template(), $theme_slug ) === 0 ) { |
| 444 |
return true; |
| 445 |
} |
| 446 |
|
| 447 |
if ( $current_theme->parent() && ( strcasecmp( $current_theme->parent()->get_stylesheet(), $theme_slug ) === 0 || strcasecmp( $current_theme->parent()->get_template(), $theme_slug ) === 0 ) ) { |
| 448 |
return true; |
| 449 |
} |
| 450 |
|
| 451 |
return false; |
| 452 |
} |
| 453 |
} |
| 454 |
|