plugin = $plugin; $this->screens = $this->build_menu_item_array(); add_action( 'admin_init', array( $this, 'add_extra_screens' ) ); add_action( 'admin_menu', array( $this, 'add_menu_item' ) ); add_action( 'wp_loaded', array( $this, 'save' ) ); add_action( 'admin_notices', array( $this, 'display_fb_product_sets_removed_banner' ) ); } /** * Arranges the tabs. If the plugin is connected to FB, Advertise tab will be first, otherwise the Connection tab will be the first tab. * * @since 3.0.7 */ public function build_menu_item_array(): array { $screens = array( Settings_Screens\Product_Sync::ID => new Settings_Screens\Product_Sync(), Settings_Screens\Product_Attributes::ID => new Settings_Screens\Product_Attributes(), ); return $screens; } public function add_extra_screens(): void { $rollout_switches = $this->plugin->get_rollout_switches(); $is_connected = $this->plugin->get_connection_handler()->is_connected(); $is_woo_all_products_sync_enbaled = $this->plugin->get_rollout_switches()->is_switch_enabled( RolloutSwitches::SWITCH_WOO_ALL_PRODUCTS_SYNC_ENABLED ); /** * If all products sync is not enabled should show the Product sync tab */ if ( true === $is_connected && false === $is_woo_all_products_sync_enbaled ) { $this->screens[ Settings_Screens\Product_Sync::ID ] = new Settings_Screens\Product_Sync(); } } /** * Adds the Facebook menu item. * * @since 2.0.0 */ public function add_menu_item() { $root_menu_item = $this->root_menu_item(); add_submenu_page( $root_menu_item, __( 'Meta for WooCommerce', 'facebook-for-woocommerce' ), __( 'Facebook', 'facebook-for-woocommerce' ), 'manage_woocommerce', self::PAGE_ID, [ $this, 'render' ], 5 ); $this->connect_to_enhanced_admin( $this->is_marketing_enabled() ? 'marketing_page_wc-facebook' : 'woocommerce_page_wc-facebook' ); } /** * Get root menu item. * * @since 3.2.10 * return string Root menu item slug. */ public function root_menu_item() { if ( $this->is_marketing_enabled() ) { return 'woocommerce-marketing'; } return 'woocommerce'; } /** * Check if marketing feature is enabled. * * @since 3.2.10 * return bool Is marketing enabled. */ public function is_marketing_enabled() { if ( class_exists( WooAdminFeatures::class ) ) { return WooAdminFeatures::is_enabled( 'marketing' ); } return is_callable( '\Automattic\WooCommerce\Admin\Loader::is_feature_enabled' ) && \Automattic\WooCommerce\Admin\Loader::is_feature_enabled( 'marketing' ); } /** * Enables enhanced admin support for the main Facebook settings page. * * @since 2.2.0 * * @param string $screen_id the ID to connect to */ private function connect_to_enhanced_admin( $screen_id ) { $is_woo_all_products_sync_enbaled = $this->plugin->get_rollout_switches()->is_switch_enabled( RolloutSwitches::SWITCH_WOO_ALL_PRODUCTS_SYNC_ENABLED ); if ( is_callable( 'wc_admin_connect_page' ) ) { $crumbs = array( __( 'Meta for WooCommerce', 'facebook-for-woocommerce' ), ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! empty( $_GET['tab'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended switch ( $_GET['tab'] ) { case Settings_Screens\Product_Sync::ID: /** * If all proudcts sync not enabled * Show the product sync tab */ if ( ! $is_woo_all_products_sync_enbaled ) { $crumbs[] = __( 'Product sync', 'facebook-for-woocommerce' ); } break; } } wc_admin_connect_page( array( 'id' => self::PAGE_ID, 'screen_id' => $screen_id, 'path' => add_query_arg( 'page', self::PAGE_ID, 'admin.php' ), 'title' => $crumbs, ) ); } } /** * Renders the settings page. * * @since 2.0.0 */ public function render() { $current_tab = $this->get_current_tab(); $screen = $this->get_screen( $current_tab ); ?>
get_description() ); ?>
render(); ?>