custom_font_post_type_callback(); add_action( 'add_meta_boxes', array( $this, 'init_metabox_callback' ) ); add_action( 'save_post', array( $this, 'metabox_save_data' ) ); add_filter( 'manage_ultp_custom_font_posts_columns', array( $this, 'templates_table_head' ) ); add_action( 'manage_ultp_custom_font_posts_custom_column', array( $this, 'templates_table_content' ), 10, 2 ); add_filter( 'upload_mimes', array( $this, 'add_file_types_to_uploads' ) ); add_filter( 'wp_check_filetype_and_ext', array( $this, 'font_correct_filetypes' ), 10, 5 ); add_filter( 'enter_title_here', array( $this, 'update_custom_font_title' ), 10, 2 ); } public function update_custom_font_title( $title, $post ) { if ( isset( $post->post_type ) && 'ultp_custom_font' === $post->post_type ) { return __( 'Add Font Family Name', 'ultimate-post' ); } return $title; } public function font_correct_filetypes( $data, $file, $filename, $mimes, $real_mime ) { if ( ! empty( $data['ext'] ) && ! empty( $data['type'] ) ) { return $data; } $wp_file_type = wp_check_filetype( $filename, $mimes ); if ( 'ttf' === $wp_file_type['ext'] ) { $data['ext'] = 'ttf'; $data['type'] = 'font/ttf'; } return $data; } public function add_file_types_to_uploads( $file_types ) { if ( 'ultp_custom_font' == get_post_type() || current_user_can( 'manage_options' ) ) { $new_filetypes = array(); $new_filetypes['woff'] = 'font/woff'; $new_filetypes['woff2'] = 'font/woff2'; $new_filetypes['ttf'] = 'font/ttf'; $new_filetypes['svg'] = 'image/svg+xml'; $new_filetypes['eot'] = 'font/ttf'; $file_types = array_merge( $file_types, $new_filetypes ); return $file_types; } else { return $file_types; } } // Template Heading Add public function templates_table_head( $defaults ) { $type_array = array( 'preview' => '' . __( 'Preview', 'ultimate-post' ) . '', 'woff' => __( 'WOFF', 'ultimate-post' ), 'woff2' => __( 'WOFF2', 'ultimate-post' ), 'ttf' => __( 'TTF', 'ultimate-post' ), 'svg' => __( 'SVG', 'ultimate-post' ), 'eot' => __( 'EOT', 'ultimate-post' ), ); $defaults['title'] = __( 'Font Family', 'ultimate-post' ); array_splice( $defaults, 2, 0, $type_array ); return $defaults; } // Get Font Face public function get_font_face( $settings, $font_name ) { $font_src = array(); if ( $settings['woff'] ) { array_push( $font_src, 'url(' . esc_url( $settings['woff'] ) . ') format("woff")' ); } if ( $settings['woff2'] ) { array_push( $font_src, 'url(' . esc_url( $settings['woff2'] ) . ') format("woff2")' ); } if ( $settings['ttf'] ) { array_push( $font_src, 'url(' . esc_url( $settings['ttf'] ) . ') format("TrueType")' ); } if ( $settings['svg'] ) { array_push( $font_src, 'url(' . esc_url( $settings['svg'] ) . ') format("svg")' ); } if ( $settings['eot'] ) { array_push( $font_src, 'url(' . esc_url( $settings['eot'] ) . ') format("eot")' ); } $font_face = '@font-face { font-family: "' . $font_name . '"; font-weight: ' . $settings['weight'] . '; src: ' . implode( ', ', $font_src ) . '; }'; return $font_face; } // Column Content public function templates_table_content( $column_id, $post_id ) { $woff = $woff2 = $ttf = $svg = $eot = false; $settings = get_post_meta( $post_id, '__font_settings', true ); if ( $settings ) { foreach ( $settings as $key => $value ) { if ( $value['woff'] ) { $woff = true; } if ( $value['woff2'] ) { $woff2 = true; } if ( $value['ttf'] ) { $ttf = true; } if ( $value['svg'] ) { $svg = true; } if ( $value['eot'] ) { $eot = true; } } $font_face = $this->get_font_face( $settings[0], get_the_title( $post_id ) ); echo ''; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped switch ( $column_id ) { case 0: echo '' . esc_html__( 'The quick brown fox jumps over the lazy dog.', 'ultimate-post' ) . ''; break; case 1: echo ''; break; case 2: echo ''; break; case 3: echo ''; break; case 4: echo ''; break; case 5: echo ''; break; default: break; } } } function init_metabox_callback() { add_meta_box( 'ultp-custom-font-id', __( 'Font Vaiations', 'ultimate-post' ), array( $this, 'custom_font_callback' ), 'ultp_custom_font', 'advanced' ); } function set_data( $arr = array(), $font_name = '' ) { ?>