if ( false !== $fonts && ! $force ) { return $fonts; } if ( $force ) { $fonts = $this->generate_fonts_list(); } $fonts = get_option( self::FONTS_OPTION_NAME, false ); return $fonts; } /** * Enqueue fonts css * * @param $post_css */ public function enqueue_fonts( $post_css ) { $used_fonts = $post_css->get_fonts(); $font_manager_fonts = $this->get_fonts(); $font_types = $this->get_font_types(); foreach ( $used_fonts as $font_family ) { if ( ! isset( $font_types[ $font_family ] ) || in_array( $font_family, $this->enqueued_fonts ) ) { continue; } $font_type = $this->get_font_type_object( $font_types[ $font_family ] ); if ( ! $font_type ) { continue; } $font_data = []; if ( isset( $font_manager_fonts[ $font_family ] ) ) { $font_data = $font_manager_fonts[ $font_family ]; } $font_type->enqueue_font( $font_family, $font_data, $post_css ); $this->enqueued_fonts[] = $font_family; } } public function register_ajax_actions( Ajax $ajax ) { $ajax->register_ajax_action( 'pro_assets_manager_panel_action_data', [ $this, 'assets_manager_panel_action_data' ] ); } public function add_finder_item( array $categories ) { $categories['settings']['items']['custom-fonts'] = [ 'title' => __( 'Custom Fonts', 'elementor-pro' ), 'icon' => 'typography', 'url' => admin_url( 'edit.php?post_type=' . self::CPT ), 'keywords' => [ 'custom', 'fonts', 'elementor' ], ]; return $categories; } /** * Register Font Manager action and filter hooks */ protected function actions() { add_action( 'init', [ $this, 'register_post_type_and_tax' ] ); if ( is_admin() ) { add_action( 'init', [ $this, 'redirect_admin_old_page_to_new' ] ); add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 50 ); add_action( 'admin_head', [ $this, 'clean_admin_listing_page' ] ); } add_filter( 'post_row_actions', [ $this, 'post_row_actions' ], 10, 2 ); add_filter( 'manage_' . self::CPT . '_posts_columns', [ $this, 'manage_columns' ], 100 ); add_action( 'save_post_' . self::CPT, [ $this, 'save_post_meta' ], 10, 3 ); add_action( 'save_post_' . self::CPT, [ $this, 'clear_fonts_list' ], 100 ); add_filter( 'elementor/fonts/groups', [ $this, 'register_fonts_groups' ] ); add_filter( 'elementor/fonts/additional_fonts', [ $this, 'register_fonts_in_control' ] ); add_filter( 'elementor/finder/categories', [ $this, 'add_finder_item' ] ); add_action( 'elementor/css-file/post/parse', [ $this, 'enqueue_fonts' ] ); add_action( 'elementor/css-file/global/parse', [ $this, 'enqueue_fonts' ] ); add_filter( 'post_updated_messages', [ $this, 'post_updated_messages' ] ); add_filter( 'enter_title_here', [ $this, 'update_enter_title_here' ], 10, 2 ); // Ajax. add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] ); /** * Elementor fonts manager loaded. * * Fires after the fonts manager was fully loaded and instantiated. * * @since 2.0.0 * * @param Fonts_Manager $this An instance of fonts manager. */ do_action( 'elementor_pro/fonts_manager_loaded', $this ); } /** * Fonts_Manager constructor. */ public function __construct() { $this->actions(); $this->add_font_type( 'custom', new Fonts\Custom_Fonts() ); $this->add_font_type( 'typekit', new Fonts\Typekit_Fonts() ); } }