get_fonts(); foreach ( $used_fonts as $font_family ) { $resolved = $this->resolve_font_data( $font_family ); if ( ! $resolved ) { continue; } $resolved['font_type']->enqueue_font( $font_family, $resolved['font_data'], $post_css ); $this->enqueued_fonts[] = $font_family; } } public function print_font_link( $font_family ) { $resolved = $this->resolve_font_data( $font_family ); if ( ! $resolved ) { return; } $font_face = isset( $resolved['font_data']['font_face'] ) ? $resolved['font_data']['font_face'] : ''; if ( empty( $font_face ) ) { return; } wp_add_inline_style( 'elementor-pro-custom-fonts', $font_face ); $this->enqueued_fonts[] = $font_family; } public function register_custom_font_styles( $fonts_to_enqueue ) { foreach ( $fonts_to_enqueue as $font_family ) { $this->print_font_link( $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' => esc_html__( 'Custom Fonts', 'elementor-pro' ), 'icon' => 'typography', 'url' => admin_url( static::MENU_SLUG ), 'keywords' => [ 'custom', 'fonts', 'elementor' ], ]; if ( ! $this->can_use_custom_fonts() ) { $lock = new Feature_Lock( [ 'type' => 'custom-font' ] ); $categories['settings']['items']['custom-fonts']['lock'] = $lock->get_config(); } return $categories; } public function admin_menu_make_open_on_subpage( $parent_file ) { if ( static::MENU_SLUG === $parent_file ) { $parent_file = Settings::PAGE_ID; } return $parent_file; } 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( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu_manager ) { if ( $this->is_editor_one_active() ) { return; } $this->register_admin_menu( $admin_menu_manager ); } ); // TODO: BC - Remove after `Admin_Menu_Manager` will be the standard. add_action( 'admin_menu', function () { if ( did_action( 'elementor/admin/menu/register' ) ) { return; } $menu_title = _x( 'Custom Fonts', 'Elementor Font', 'elementor-pro' ); add_submenu_page( Settings::PAGE_ID, $menu_title, $menu_title, self::CAPABILITY, static::MENU_SLUG ); }, 50 ); add_action( 'admin_head', [ $this, 'clean_admin_listing_page' ] ); add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { if ( $this->can_use_custom_fonts() ) { $menu_data_provider->register_menu( new Editor_One_Fonts_Menu_Item() ); } else { $menu_data_provider->register_menu( new Editor_One_Fonts_Promotion() ); } } ); } // TODO: Maybe just ignore all of those when the user can't use custom fonts? 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_action( 'elementor/fonts/register_styles', [ $this, 'register_custom_font_styles' ] ); add_action( 'elementor/fonts/print_font_links/custom', [ $this, 'print_font_link' ] ); add_action( 'elementor/fonts/print_font_links/variable', [ $this, 'print_font_link' ] ); add_action( 'wp_enqueue_scripts', function () { wp_register_style( 'elementor-pro-custom-fonts', false, [], ELEMENTOR_PRO_VERSION ); wp_enqueue_style( 'elementor-pro-custom-fonts' ); }, 15 ); add_filter( 'post_updated_messages', [ $this, 'post_updated_messages' ] ); add_filter( 'enter_title_here', [ $this, 'update_enter_title_here' ], 10, 2 ); add_filter( 'elementor/typography/font_variables', [ $this, 'get_font_variables' ] ); add_filter( 'elementor/typography/font_variable_ranges', [ $this, 'get_font_variable_ranges' ] ); add_filter( 'parent_file', [ $this, 'admin_menu_make_open_on_subpage' ] ); // Ajax. add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] ); add_filter( 'elementor/editor-one/admin-edit-post-types', function ( array $post_types ) { $post_types[] = self::CPT; return $post_types; } ); /** * 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() ); } }