SupportPage.php
85 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDesk\FCF\Free\Marketing; |
| 4 | |
| 5 | use WPDesk\FCF\Free\Settings\Menu; |
| 6 | use WPDesk\FCF\Free\Settings\Page; |
| 7 | use WPDesk\FCF\Free\Service\TemplateLoader; |
| 8 | use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 9 | use FcfVendor\WPDesk\Library\Marketing\Boxes\Assets; |
| 10 | use FcfVendor\WPDesk\Library\Marketing\Boxes\MarketingBoxes; |
| 11 | |
| 12 | /** |
| 13 | * Add remote page with support and marketing content. This will be overwritten by the PRO version |
| 14 | * of the plugin. |
| 15 | */ |
| 16 | class SupportPage implements Hookable { |
| 17 | |
| 18 | /** @var TemplateLoader */ |
| 19 | private $template; |
| 20 | |
| 21 | public function __construct( TemplateLoader $template ) { |
| 22 | $this->template = $template; |
| 23 | } |
| 24 | |
| 25 | public function hooks(): void { |
| 26 | add_action( 'flexible_checkout_fields/after_settings', [ $this, 'render_marketing_page' ] ); |
| 27 | add_action( 'admin_enqueue_scripts', [ $this, 'load_assets_for_marketing_page' ] ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Check if the page should be rendered. |
| 32 | * |
| 33 | * @return bool |
| 34 | */ |
| 35 | private function should_render_page(): bool { |
| 36 | if ( ! isset( $_GET['page'] ) || ( $_GET['page'] !== Page::SETTINGS_PAGE ) ) { // phpcs:ignore |
| 37 | return false; |
| 38 | } |
| 39 | $current_tab = $_GET['tab'] ?? Menu::MENU_TAB_SECTIONS; // phpcs:ignore |
| 40 | |
| 41 | return Menu::MENU_TAB_MARKETING === $current_tab; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * A function to render the marketing page. |
| 46 | */ |
| 47 | public function render_marketing_page(): void { |
| 48 | if ( ! $this->should_render_page() ) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | $local = \get_locale(); |
| 53 | if ( $local === 'en_US' ) { |
| 54 | $local = 'en'; |
| 55 | } |
| 56 | $plugin_slug = $this->is_pro_active() ? 'flexible-checkout-fields-pro' : 'flexible-checkout-fields'; |
| 57 | |
| 58 | echo $this->template->load_template( // phpcs:ignore |
| 59 | 'marketing-page', |
| 60 | [ |
| 61 | 'boxes' => new MarketingBoxes( $plugin_slug, $local ), // phpcs:ignore |
| 62 | ] |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Loads the assets for the marketing page. |
| 68 | * |
| 69 | * @return void |
| 70 | */ |
| 71 | public function load_assets_for_marketing_page(): void { |
| 72 | Assets::enqueue_assets(); |
| 73 | Assets::enqueue_owl_assets(); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * A function to check if the pro version is active. |
| 78 | * |
| 79 | * @return bool |
| 80 | */ |
| 81 | private function is_pro_active(): bool { |
| 82 | return \is_plugin_active( 'flexible-checkout-fields-pro/flexible-checkout-fields-pro.php' ); |
| 83 | } |
| 84 | } |
| 85 |