romotions : array( $promotions ) ); } /** * Add new promotions. * * @param Array $new_promotions New promotions. */ private function add_new_promotions( $new_promotions ) { if ( isset( $this->promoter_core_instance ) ) { $this->promoter_core_instance->add_promotions( $new_promotions ); } } /** * Generate ajax endpoints. * * @return Array Generated ajax endpoints. */ private function generate_ajax_endpoints() { $blacklist_endpoint = new PromotionBlacklistAjaxEndpoint( $this->registry->get_config( 'ajax.promotion_black_list.action' ), $this->promotion_blacklist_manager ); $install_endpoint = new PromotionInstallAjaxEndpoint( $this->registry->get_config( 'ajax.promotion_install.action' ) ); return array( 'blacklist' => $blacklist_endpoint, 'install' => $install_endpoint, ); } /** * Initialize the library. * * @param string $plugin_file Path to the main plugin file. */ private function initialize_library( $plugin_file ) { $this->library_paths = $this->initialize_library_paths( $plugin_file ); $this->registry = $this->initialize_registry(); $this->asset_handler = $this->initialize_asset_handler(); $this->promotion_blacklist_manager = new PromotionBlacklistManager( $this->registry->get_config( 'ajax.promotion_black_list.option_id' ) ); } /** * Initialize the asset handler. * * This function will initialize the asset handler which will handle all js and css * files for frontend. */ private function initialize_asset_handler() { $editor_core_script_config = $this->registry->get_config( 'frontend.editor_script' ); $editor_core_script_relative_path = $editor_core_script_config['path']; $editor_core_script_deps = require $this->library_paths->dir_path( $editor_core_script_config['deps'] ); // Main editor script asset. $editor_core_script_asset = new PromoterAsset( $this->library_paths->dir_path( $editor_core_script_relative_path ), $this->library_paths->url_path( $editor_core_script_relative_path ), $editor_core_script_config['handle'], $editor_core_script_deps['dependencies'], $editor_core_script_deps['version'] ); $editor_core_style_config = $this->registry->get_config( 'frontend.editor_styles' ); $editor_core_style_asset = new PromoterAsset( $this->library_paths->dir_path( $editor_core_style_config['path'] ), $this->library_paths->url_path( $editor_core_style_config['path'] ), $editor_core_style_config['handle'], array() ); return new EditorAssetHandler( array( $editor_core_script_asset, $editor_core_style_asset ) ); } /** * Initialize the library paths. * * @param string $plugin_file Path to the main plugin file. * * @return LibraryPaths Initialized library paths. */ private function initialize_library_paths( $plugin_file ) { // Since our entry point is not in the root of the library, we need to calculate it. $library_abs_root_path = dirname( __DIR__ ); return new LibraryPaths( $plugin_file, $library_abs_root_path ); } /** * Initialize registry. * * @return Registry Initialized registry. */ private function initialize_registry() { $core_configs = require $this->library_paths->dir_path( 'inc/Config/config_core.php' ); return new Registry( new ArrayConfiguration( $core_configs ) ); } }