| 1 |
<?php |
| 2 |
declare(strict_types=1); |
| 3 |
|
| 4 |
namespace Imagify\ThirdParty\Plugins; |
| 5 |
|
| 6 |
use GFForms; |
| 7 |
use Imagify\EventManagement\SubscriberInterface; |
| 8 |
|
| 9 |
/** |
| 10 |
* Subscriber for compatibility with GravityForms |
| 11 |
*/ |
| 12 |
class GravityForms implements SubscriberInterface { |
| 13 |
/** |
| 14 |
* Returns an array of events that this subscriber wants to listen to. |
| 15 |
* |
| 16 |
* @return array |
| 17 |
*/ |
| 18 |
public static function get_subscribed_events(): array { |
| 19 |
if ( ! class_exists( 'GFCommon' ) ) { |
| 20 |
return []; |
| 21 |
} |
| 22 |
|
| 23 |
return [ |
| 24 |
// @filter |
| 25 |
'gform_noconflict_styles' => 'imagify_gf_noconflict_styles', |
| 26 |
// @filter |
| 27 |
'gform_noconflict_scripts' => 'imagify_gf_noconflict_scripts', |
| 28 |
]; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Register imagify styles to gravity forms conflict styles |
| 33 |
* |
| 34 |
* @param array $styles Array fo registered styles. |
| 35 |
* |
| 36 |
* @return array |
| 37 |
*/ |
| 38 |
public function imagify_gf_noconflict_styles( $styles ): array { |
| 39 |
if ( ! $this->is_gravity_forms_no_conflict_mode_enabled() ) { |
| 40 |
return $styles; |
| 41 |
} |
| 42 |
|
| 43 |
$styles[] = 'imagify-admin-bar'; |
| 44 |
$styles[] = 'imagify-admin'; |
| 45 |
$styles[] = 'imagify-notices'; |
| 46 |
$styles[] = 'imagify-pricing-modal'; |
| 47 |
|
| 48 |
return $styles; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Register Imagify scripts to gravity forms conflict scripts |
| 53 |
* |
| 54 |
* @param array $scripts Array fo registered scripts. |
| 55 |
* |
| 56 |
* @return array |
| 57 |
*/ |
| 58 |
public function imagify_gf_noconflict_scripts( $scripts ): array { |
| 59 |
if ( ! $this->is_gravity_forms_no_conflict_mode_enabled() ) { |
| 60 |
return $scripts; |
| 61 |
} |
| 62 |
|
| 63 |
$scripts[] = 'imagify-admin-bar'; |
| 64 |
$scripts[] = 'imagify-sweetalert'; |
| 65 |
$scripts[] = 'imagify-admin'; |
| 66 |
$scripts[] = 'imagify-notices'; |
| 67 |
$scripts[] = 'imagify-pricing-modal'; |
| 68 |
|
| 69 |
return $scripts; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Check if gravity form is active and no_conflict mode is enabled. |
| 74 |
* |
| 75 |
* @return bool |
| 76 |
*/ |
| 77 |
private function is_gravity_forms_no_conflict_mode_enabled(): bool { |
| 78 |
return (bool) get_option( 'gform_enable_noconflict', false ); |
| 79 |
} |
| 80 |
} |
| 81 |
|