Custom Fonts - Version 1.0.0

Version Description

Download this release

Release Info

Developer Nikschavan
Plugin Icon 128x128 Custom Fonts
Version 1.0.0
Comparing to
See all releases

Version 1.0.0

assets/css/bsf-custom-fonts.css ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ .bsf-custom-fonts-upload.button {
2
+ position:absolute
3
+ }
4
+ .bsf-custom-fonts-link{
5
+ padding-left:80px;
6
+ }
assets/js/bsf-custom-fonts.js ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($){
2
+
3
+ /**
4
+ * Bsf Custom Fonts
5
+ *
6
+ * @class BsfCustomFonts
7
+ * @since 1.0.0
8
+ */
9
+
10
+ BsfCustomFonts = {
11
+
12
+ /**
13
+ * Initializes a Bsf Custom Fonts.
14
+ *
15
+ * @since 1.0
16
+ * @method init
17
+ */
18
+ init: function()
19
+ {
20
+ // Init.
21
+ this._fileUploads();
22
+ },
23
+ /**
24
+ * Font File Uploads
25
+ * parallax.
26
+ *
27
+ * @since 1.0.0
28
+ * @access private
29
+ * @method _fileUploads
30
+ */
31
+ _fileUploads: function()
32
+ {
33
+ var file_frame;
34
+ window.inputWrapper = '';
35
+ $( document.body ).on('click', '.bsf-custom-fonts-upload', function(e) {
36
+ event.preventDefault();
37
+ var button = $(this),
38
+ button_type = button.data('upload-type');
39
+ window.inputWrapper = $(this).closest('.bsf-custom-fonts-file-wrap');
40
+
41
+ // If the media frame already exists, reopen it.
42
+ if ( file_frame ) {
43
+ file_frame.open();
44
+ return;
45
+ }
46
+
47
+ // Create a new media frame
48
+ file_frame = wp.media.frames.file_frame = wp.media({
49
+ multiple: false // Set to true to allow multiple files to be selected
50
+ });
51
+
52
+ // When an image is selected in the media frame...
53
+ file_frame.on( 'select', function() {
54
+
55
+ // Get media attachment details from the frame state
56
+ var attachment = file_frame.state().get('selection').first().toJSON();
57
+ window.inputWrapper.find( '.bsf-custom-fonts-link' ).val(attachment.url);
58
+ });
59
+ // Finally, open the modal
60
+ file_frame.open();
61
+ });
62
+ var file_frame;
63
+ window.inputWrapper = '';
64
+ },
65
+ }
66
+
67
+ /* Initializes the Bsf Custom Fonts. */
68
+ $(function(){
69
+ BsfCustomFonts.init();
70
+ });
71
+
72
+ })(jQuery);
classes/class-bsf-custom-fonts-render.php ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bsf Custom Fonts Admin Ui
4
+ *
5
+ * @since 1.0.0
6
+ * @package Bsf_Custom_Fonts
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ if ( ! class_exists( 'Bsf_Custom_Fonts_Render' ) ) :
12
+
13
+ /**
14
+ * Bsf_Custom_Fonts_Render
15
+ */
16
+ class Bsf_Custom_Fonts_Render {
17
+
18
+ /**
19
+ * Instance of Bsf_Custom_Fonts_Render
20
+ *
21
+ * @since 1.0.0
22
+ * @var (Object) Bsf_Custom_Fonts_Render
23
+ */
24
+ private static $_instance = null;
25
+
26
+ /**
27
+ * Member Varible
28
+ *
29
+ * @var string $font_css
30
+ */
31
+ protected $font_css;
32
+
33
+ /**
34
+ * Instance of Bsf_Custom_Fonts_Admin.
35
+ *
36
+ * @since 1.0.0
37
+ *
38
+ * @return object Class object.
39
+ */
40
+ public static function get_instance() {
41
+ if ( ! isset( self::$_instance ) ) {
42
+ self::$_instance = new self;
43
+ }
44
+
45
+ return self::$_instance;
46
+ }
47
+
48
+ /**
49
+ * Constructor.
50
+ *
51
+ * @since 1.0.0
52
+ */
53
+ public function __construct() {
54
+
55
+ add_action( 'admin_enqueue_scripts', array( $this , 'enqueue_scripts') );
56
+
57
+ add_action( 'admin_notices', array( $this , 'theme_update_notice' ) );
58
+
59
+ // Enqueue the custom fonts
60
+ add_action( 'astra_render_fonts', array( $this, 'render_fonts' ) );
61
+
62
+ // Delete custom fonts action
63
+ add_action( 'delete_term', array($this , 'delete_custom_fonts_fallback_astra' ), 10, 5);
64
+
65
+ add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
66
+
67
+ // add Custom Font list into Astra customizer.
68
+ add_action( 'astra_customizer_font_list', array( $this, 'add_customizer_font_list') );
69
+ }
70
+
71
+ /**
72
+ * Add Custom Font list into Astra customizer.
73
+ *
74
+ * @since 1.0.0
75
+ * @param string $value selected font family.
76
+ */
77
+ public function add_customizer_font_list( $value ) {
78
+
79
+ $fonts = Bsf_Custom_Fonts_Taxonomy::get_fonts();
80
+
81
+ echo '<optgroup label="Custom">';
82
+
83
+ foreach ( $fonts as $font => $links ) {
84
+ echo '<option value="' . esc_attr( $font ) . '" ' . selected( $font, $value , false ) . '>' . esc_attr( $font ) . '</option>';
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Enqueue Admin Scripts
90
+ *
91
+ * @since 1.0.0
92
+ */
93
+ public function enqueue_scripts(){
94
+
95
+ wp_enqueue_style( 'bsf-custom-fonts-css', BSF_CUSTOM_FONTS_URI . 'assets/css/bsf-custom-fonts.css', array(), BSF_CUSTOM_FONTS_VER );
96
+ wp_enqueue_media();
97
+ wp_enqueue_script( 'bsf-custom-fonts-js', BSF_CUSTOM_FONTS_URI . 'assets/js/bsf-custom-fonts.js', array(), BSF_CUSTOM_FONTS_VER );
98
+
99
+ }
100
+
101
+ /**
102
+ * Enqueue Render Fonts
103
+ *
104
+ * @since 1.0.0
105
+ * @param array $load_fonts astra fonts.
106
+ */
107
+ public function render_fonts( $load_fonts ) {
108
+
109
+ $fonts = Bsf_Custom_Fonts_Taxonomy::get_fonts();
110
+
111
+ foreach ( $load_fonts as $load_font_name => $load_font ) {
112
+ if ( array_key_exists( $load_font_name , $fonts ) ) {
113
+ $this->render_font_css( $load_font_name );
114
+ unset( $load_fonts[ $load_font_name ] );
115
+ }
116
+ }
117
+ // Add Astra inline css for custom Fonys.
118
+ wp_add_inline_style( 'astra-theme-css', $this->font_css );
119
+ return $load_fonts;
120
+ }
121
+
122
+ /**
123
+ * Create css for font-face
124
+ *
125
+ * @since 1.0.0
126
+ * @param array $font selected font from custom font list.
127
+ */
128
+ private function render_font_css( $font ) {
129
+ $fonts = Bsf_Custom_Fonts_Taxonomy::get_links_by_name( $font );
130
+
131
+ foreach ( $fonts as $font => $links ) :
132
+ $css = '@font-face { font-family:' . esc_attr( $font ) .';';
133
+ $css .= 'src:';
134
+ $arr = array();
135
+ if ( $links['font_woff_2'] ) {
136
+ $arr[] = "url(" . esc_url( $links['font_woff_2'] ) . ") format('woff2')";
137
+ }
138
+ if ( $links['font_woff'] ) {
139
+ $arr[] = "url(" . esc_url( $links['font_woff'] ) . ") format('woff')";
140
+ }
141
+ if ( $links['font_ttf'] ) {
142
+ $arr[] = "url(" . esc_url( $links['font_ttf'] ) . ") format('truetype')";
143
+ }
144
+ if ( $links['font_svg'] ) {
145
+ $arr[] = "url(" . esc_url( $links['font_svg'] ) . "#". esc_attr( strtolower( str_replace( ' ', '_', $font ) ) ) .") format('svg')";
146
+ }
147
+ $css .= join( ', ', $arr );
148
+ $css .= ';}' ;
149
+ endforeach;
150
+
151
+ $this->font_css = $css;
152
+ }
153
+
154
+ /**
155
+ * Set default 'inherit' if custom font is selected in customizer if this is deleted.
156
+ *
157
+ * @since 1.0.0
158
+ * @param int $term Term ID.
159
+ * @param int $tt_id Term taxonomy ID.
160
+ * @param string $taxonomy Taxonomy slug.
161
+ * @param mixed $deleted_term deleted term.
162
+ * @param object $object_ids objects ids.
163
+ */
164
+ function delete_custom_fonts_fallback_astra( $term, $tt_id, $taxonomy, $deleted_term, $object_ids ) {
165
+
166
+ if ( defined( 'ASTRA_THEME_SETTINGS' ) ) {
167
+ // get astra options.
168
+ $options = get_option( ASTRA_THEME_SETTINGS );
169
+ foreach ( $options as $key => $value ) {
170
+ if ( $value == $deleted_term->name ) {
171
+ // set default inherit if custom font is deleted.
172
+ $options[$key] = 'inherit';
173
+ }
174
+ }
175
+ // update astra options.
176
+ update_option( ASTRA_THEME_SETTINGS, $options );
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Theme update notice.
182
+ *
183
+ * @since 1.0.0
184
+ */
185
+ function theme_update_notice() {
186
+ if ( defined('ASTRA_THEME_VERSION')) {
187
+ if ( version_compare( ASTRA_THEME_VERSION, '1.0.16', '<') ) {
188
+ ?>
189
+ <div class="notice notice-error is-dismissible">
190
+ <p>
191
+ <?php
192
+ printf(
193
+ /* translators: 1: Astra theme from wordpress.org*/
194
+ __( 'Custom Fonts Plugin requires minimum 1.0.16 version of the Astra Theme.', 'bsf-custom-fonts' ),
195
+ esc_url( 'https://downloads.wordpress.org/theme/astra.zip' )
196
+ );
197
+ ?>
198
+ </p>
199
+ </div>
200
+ <?php
201
+ }
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Loads textdomain for the plugin.
207
+ *
208
+ * @since 1.0.0
209
+ */
210
+ function load_textdomain() {
211
+ load_plugin_textdomain( 'bsf-custom-fonts' );
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Kicking this off by calling 'get_instance()' method
217
+ */
218
+ Bsf_Custom_Fonts_Render::get_instance();
219
+
220
+ endif;
221
+
222
+
223
+
224
+
225
+
classes/class-bsf-custom-fonts.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bsf Custom fonts - Init
4
+ *
5
+ * @package Bsf_Custom_Fonts
6
+ */
7
+
8
+ if ( ! class_exists( 'Bsf_Custom_Fonts' ) ) {
9
+
10
+ /**
11
+ * Bsf Custom fonts
12
+ *
13
+ * @since 1.0.0
14
+ */
15
+ class Bsf_Custom_Fonts {
16
+
17
+ /**
18
+ * Member Varible
19
+ *
20
+ * @var object instance
21
+ */
22
+ private static $instance;
23
+
24
+ /**
25
+ * Initiator
26
+ */
27
+ public static function get_instance() {
28
+ if ( ! isset( self::$instance ) ) {
29
+ self::$instance = new self;
30
+ }
31
+ return self::$instance;
32
+ }
33
+
34
+ /**
35
+ * Constructor function that initializes required actions and hooks
36
+ */
37
+ public function __construct() {
38
+ require_once BSF_CUSTOM_FONTS_DIR . 'includes/class-bsf-custom-fonts-taxonomy.php';
39
+ require_once BSF_CUSTOM_FONTS_DIR . 'includes/class-bsf-custom-fonts-admin.php';
40
+
41
+ require_once BSF_CUSTOM_FONTS_DIR . 'classes/class-bsf-custom-fonts-render.php';
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Kicking this off by calling 'get_instance()' method
47
+ */
48
+ Bsf_Custom_Fonts::get_instance();
49
+ }// End if().
custom-fonts.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: Custom Fonts
4
+ * Plugin URI: http://www.wpastra.com/
5
+ * Description: Custom Fonts allows you to add more fonts that extend formatting options in your site.
6
+ * Author: Brainstorm Force
7
+ * Author URI: http://www.brainstormforce.com
8
+ * Text Domain: bsf-custom-fonts
9
+ * Version: 1.0.0
10
+ *
11
+ * @package Bsf_Custom_Fonts
12
+ */
13
+
14
+ /**
15
+ * Exit if accessed directly.
16
+ */
17
+ if ( ! defined( 'ABSPATH' ) ) {
18
+ exit();
19
+ }
20
+
21
+ /**
22
+ * Set constants.
23
+ */
24
+ define( 'BSF_CUSTOM_FONTS_FILE', __FILE__ );
25
+ define( 'BSF_CUSTOM_FONTS_BASE', plugin_basename( BSF_CUSTOM_FONTS_FILE ) );
26
+ define( 'BSF_CUSTOM_FONTS_DIR', plugin_dir_path( BSF_CUSTOM_FONTS_FILE ) );
27
+ define( 'BSF_CUSTOM_FONTS_URI', plugins_url( '/', BSF_CUSTOM_FONTS_FILE ) );
28
+ define( 'BSF_CUSTOM_FONTS_VER', '1.0.0' );
29
+
30
+ /**
31
+ * BSF Custom Fonts
32
+ */
33
+ require_once BSF_CUSTOM_FONTS_DIR . 'classes/class-bsf-custom-fonts.php';
includes/class-bsf-custom-fonts-admin.php ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bsf Custom Fonts Admin Ui
4
+ *
5
+ * @since 1.0.0
6
+ * @package Bsf_Custom_Fonts
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
12
+
13
+ /**
14
+ * Bsf_Custom_Fonts_Admin
15
+ */
16
+ class Bsf_Custom_Fonts_Admin {
17
+
18
+ /**
19
+ * Instance of Bsf_Custom_Fonts_Admin
20
+ *
21
+ * @since 1.0.0
22
+ * @var (Object) Bsf_Custom_Fonts_Admin
23
+ */
24
+ private static $_instance = null;
25
+
26
+ /**
27
+ * Parent Menu Slug
28
+ *
29
+ * @since 1.0.0
30
+ * @var (string) $parent_menu_slug
31
+ */
32
+ protected $parent_menu_slug = 'themes.php';
33
+
34
+ /**
35
+ * Instance of Bsf_Custom_Fonts_Admin.
36
+ *
37
+ * @since 1.0.0
38
+ *
39
+ * @return object Class object.
40
+ */
41
+ public static function get_instance() {
42
+ if ( ! isset( self::$_instance ) ) {
43
+ self::$_instance = new self;
44
+ }
45
+
46
+ return self::$_instance;
47
+ }
48
+
49
+ /**
50
+ * Constructor.
51
+ *
52
+ * @since 1.0.0
53
+ */
54
+ public function __construct() {
55
+ add_action( 'admin_menu', array( $this, 'register_custom_fonts_menu' ) );
56
+ add_action( 'admin_head', array( $this, 'custom_fonts_menu_highlight' ) );
57
+
58
+ add_filter( 'manage_edit-' . Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug . '_columns', array( $this, 'manage_columns' ) );
59
+
60
+ add_action( Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug . '_add_form_fields', array( $this, 'add_new_taxonomy_data' ) );
61
+ add_action( Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug . '_edit_form_fields', array( $this, 'edit_taxonomy_data' ) );
62
+
63
+ add_action( 'edited_' . Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug, array( $this, 'save_metadata' ) );
64
+ add_action( 'create_' . Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug, array( $this, 'save_metadata' ) );
65
+
66
+ add_filter( 'upload_mimes', array( $this, 'add_fonts_to_allowed_mimes' ) );
67
+
68
+ }
69
+
70
+ /**
71
+ * Register custom font menu
72
+ *
73
+ * @since 1.0.0
74
+ */
75
+ public function register_custom_fonts_menu() {
76
+ add_submenu_page(
77
+ $this->parent_menu_slug,
78
+ __( 'BSF Custom Fonts', 'bsf-custom-fonts' ),
79
+ __( 'BSF Custom Fonts', 'bsf-custom-fonts' ),
80
+ Bsf_Custom_Fonts_Taxonomy::$capability,
81
+ 'edit-tags.php?taxonomy=' . Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug
82
+ );
83
+ }
84
+
85
+ /**
86
+ * Highlight custom font menu
87
+ *
88
+ * @since 1.0.0
89
+ */
90
+ public function custom_fonts_menu_highlight() {
91
+ global $parent_file, $submenu_file;
92
+
93
+ if ( 'edit-tags.php?taxonomy=' . Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug === $submenu_file ) {
94
+ $parent_file = $this->parent_menu_slug;
95
+ }
96
+ if ( 'edit-' . Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug !== get_current_screen()->id ) {
97
+ return;
98
+ }
99
+
100
+ ?><style>#addtag div.form-field.term-slug-wrap, #edittag tr.form-field.term-slug-wrap { display: none; }
101
+ #addtag div.form-field.term-description-wrap, #edittag tr.form-field.term-description-wrap { display: none; }</style><script>jQuery( document ).ready( function( $ ) {
102
+ var $wrapper = $( '#addtag, #edittag' );
103
+ $wrapper.find( 'tr.form-field.term-name-wrap p, div.form-field.term-name-wrap > p' ).text( '<?php esc_html_e( 'The name of the font as it appears in the attached CSS file.', 'bsf-custom-fonts' ); ?>' );
104
+ } );</script><?php
105
+ }
106
+
107
+ /**
108
+ * Manage Columns
109
+ *
110
+ * @since 1.0.0
111
+ * @param array $columns default columns.
112
+ * @return array $columns updated columns.
113
+ */
114
+ public function manage_columns( $columns ) {
115
+ $old_columns = $columns;
116
+ $columns = array(
117
+ 'cb' => $old_columns['cb'],
118
+ 'name' => $old_columns['name'],
119
+ );
120
+
121
+ return $columns;
122
+ }
123
+
124
+ /**
125
+ * Add new Taxonomy data
126
+ *
127
+ * @since 1.0.0
128
+ */
129
+ public function add_new_taxonomy_data() {
130
+ $this->font_file_new_field( 'font_woff_2', __( 'Font .woff2', 'bsf-custom-fonts' ) );
131
+ $this->font_file_new_field( 'font_woff', __( 'Font .woff', 'bsf-custom-fonts' ) );
132
+ $this->font_file_new_field( 'font_ttf', __( 'Font .ttf', 'bsf-custom-fonts' ) );
133
+ $this->font_file_new_field( 'font_eot', __( 'Font .eot', 'bsf-custom-fonts' ) );
134
+ $this->font_file_new_field( 'font_svg', __( 'Font .svg', 'bsf-custom-fonts' ) );
135
+ }
136
+
137
+ /**
138
+ * Edit Taxonomy data
139
+ *
140
+ * @since 1.0.0
141
+ */
142
+ public function edit_taxonomy_data( $term ) {
143
+ $data = Bsf_Custom_Fonts_Taxonomy::get_font_links( $term->term_id );
144
+ $this->font_file_edit_field( 'font_woff_2', __( 'Font .woff2', 'bsf-custom-fonts' ), $data['font_woff_2'] );
145
+ $this->font_file_edit_field( 'font_woff', __( 'Font .woff', 'bsf-custom-fonts' ), $data['font_woff'] );
146
+ $this->font_file_edit_field( 'font_ttf', __( 'Font .ttf', 'bsf-custom-fonts' ), $data['font_ttf'] );
147
+ $this->font_file_edit_field( 'font_eot', __( 'Font .eot', 'bsf-custom-fonts' ), $data['font_eot'] );
148
+ $this->font_file_edit_field( 'font_svg', __( 'Font .svg', 'bsf-custom-fonts' ), $data['font_svg'] );
149
+ }
150
+
151
+ /**
152
+ * Add Taxonomy data field
153
+ *
154
+ * @since 1.0.0
155
+ */
156
+ protected function font_file_new_field( $id, $title, $value = '' ) {
157
+ ?>
158
+ <div class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap" >
159
+
160
+ <label><?php echo esc_html( $title ); ?></label>
161
+ <a href="javascript:void(0);" class="bsf-custom-fonts-upload button" data-upload-type="<?php echo esc_attr( $id );?>"><?php esc_html_e( 'Upload', 'bsf-custom-fonts' ); ?></a>
162
+ <input type="text" class="bsf-custom-fonts-link <?php echo esc_attr( $id );?>" name="<?php echo Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug; ?>[<?php echo esc_attr( $id ); ?>]" placeholder="<?php esc_html_e( 'Upload or enter the file URL', 'bsf-custom-fonts' ); ?>" value="<?php echo esc_attr( $value ); ?>" />
163
+ </div>
164
+ <?php
165
+ }
166
+
167
+ /**
168
+ * Add Taxonomy data field
169
+ *
170
+ * @since 1.0.0
171
+ */
172
+ protected function font_file_edit_field( $id, $title, $value = '' ) {
173
+ ?>
174
+ <tr class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap ">
175
+ <th scope="row">
176
+ <label for="metadata-<?php echo esc_attr( $id ); ?>">
177
+ <?php echo esc_html( $title ); ?>
178
+ </label>
179
+ </th>
180
+ <td>
181
+ <a href="javascript:void(0);" class="bsf-custom-fonts-upload button" data-upload-type="<?php echo esc_attr( $id );?>"><?php esc_html_e( 'Upload', 'bsf-custom-fonts' ); ?></a>
182
+ <input id="metadata-<?php echo esc_attr( $id ); ?>" type="text" class="bsf-custom-fonts-link <?php echo esc_attr( $id );?>" name="<?php echo Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug; ?>[<?php echo esc_attr( $id ); ?>]" placeholder="<?php esc_html_e( 'Upload or enter the file URL', 'bsf-custom-fonts' ); ?>" value="<?php echo esc_attr( $value ); ?>" />
183
+ </td>
184
+ </tr>
185
+ <?php
186
+ }
187
+
188
+ public function save_metadata( $term_id ) {
189
+
190
+ if ( isset( $_POST[ Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug ] ) ) {
191
+ $value = array_map( 'esc_attr', $_POST[ Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug ] );
192
+ Bsf_Custom_Fonts_Taxonomy::update_font_links( $value, $term_id );
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Allowed mime types and file extensions
198
+ *
199
+ * @since 1.0.0
200
+ * @param array $mimes Current array of mime types.
201
+ * @return array $mimes Updated array of mime types.
202
+ */
203
+ public function add_fonts_to_allowed_mimes( $mimes ) {
204
+ $mimes['woff'] = 'application/x-font-woff';
205
+ $mimes['woff2'] = 'application/x-font-woff2';
206
+ $mimes['ttf'] = 'application/x-font-ttf';
207
+ $mimes['svg'] = 'image/svg+xml';
208
+ $mimes['eot'] = 'application/vnd.ms-fontobject';
209
+ return $mimes;
210
+ }
211
+
212
+ }
213
+
214
+
215
+
216
+ /**
217
+ * Kicking this off by calling 'get_instance()' method
218
+ */
219
+ Bsf_Custom_Fonts_Admin::get_instance();
220
+
221
+ endif;
includes/class-bsf-custom-fonts-taxonomy.php ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Bsf Custom Fonts Taxonomy
4
+ *
5
+ * @since 1.0.0
6
+ * @package Bsf_Custom_Fonts
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ if ( ! class_exists( 'Bsf_Custom_Fonts_Taxonomy' ) ) :
12
+
13
+ /**
14
+ * Bsf_Custom_Fonts_Taxonomy
15
+ */
16
+ class Bsf_Custom_Fonts_Taxonomy {
17
+ /**
18
+ * Instance of Bsf_Custom_Fonts_Taxonomy
19
+ *
20
+ * @since 1.0.0
21
+ * @var (Object) Bsf_Custom_Fonts_Taxonomy
22
+ */
23
+ private static $_instance = null;
24
+
25
+ /**
26
+ * Fonts
27
+ *
28
+ * @since 1.0.0
29
+ * @var (string) $fonts
30
+ */
31
+ public static $fonts = null;
32
+
33
+ /**
34
+ * Capability required for this menu to be displayed
35
+ *
36
+ * @since 1.0.0
37
+ * @var (string) $capability
38
+ */
39
+ public static $capability = 'edit_theme_options';
40
+
41
+ /**
42
+ * Register Taxonomy
43
+ *
44
+ * @since 1.0.0
45
+ * @var (string) $register_taxonomy
46
+ */
47
+ public static $register_taxonomy_slug = 'bsf_custom_fonts';
48
+
49
+ /**
50
+ * Instance of Bsf_Custom_Fonts_Admin.
51
+ *
52
+ * @since 1.0.0
53
+ *
54
+ * @return object Class object.
55
+ */
56
+ public static function get_instance() {
57
+ if ( ! isset( self::$_instance ) ) {
58
+ self::$_instance = new self;
59
+ }
60
+
61
+ return self::$_instance;
62
+ }
63
+
64
+ /**
65
+ * Constructor.
66
+ *
67
+ * @since 1.0.0
68
+ */
69
+ public function __construct() {
70
+ add_action( 'init', array( $this, 'create_custom_fonts_taxonomies' ) );
71
+ }
72
+
73
+ /**
74
+ * Register custom font taxonomy
75
+ *
76
+ * @since 1.0.0
77
+ */
78
+ public function create_custom_fonts_taxonomies() {
79
+ // Taxonomy: bsf_custom_fonts.
80
+ $labels = array(
81
+ 'name' => __( 'BSF Custom Fonts', 'bsf-custom-fonts' ),
82
+ 'singular_name' => __( 'Font', 'bsf-custom-fonts' ),
83
+ 'menu_name' => _x( 'BSF Custom Fonts', 'Admin menu name', 'bsf-custom-fonts' ),
84
+ 'search_items' => __( 'Search Fonts', 'bsf-custom-fonts' ),
85
+ 'all_items' => __( 'All Fonts', 'bsf-custom-fonts' ),
86
+ 'parent_item' => __( 'Parent Font', 'bsf-custom-fonts' ),
87
+ 'parent_item_colon' => __( 'Parent Font:', 'bsf-custom-fonts' ),
88
+ 'edit_item' => __( 'Edit Font', 'bsf-custom-fonts' ),
89
+ 'update_item' => __( 'Update Font', 'bsf-custom-fonts' ),
90
+ 'add_new_item' => __( 'Add New Font', 'bsf-custom-fonts' ),
91
+ 'new_item_name' => __( 'New Font Name', 'bsf-custom-fonts' ),
92
+ );
93
+
94
+ $args = array(
95
+ 'hierarchical' => false,
96
+ 'labels' => $labels,
97
+ 'public' => false,
98
+ 'show_in_nav_menus' => false,
99
+ 'show_ui' => true,
100
+ 'capabilities' => array( self::$capability ),
101
+ 'query_var' => false,
102
+ 'rewrite' => false,
103
+ );
104
+
105
+ register_taxonomy(
106
+ self::$register_taxonomy_slug,
107
+ apply_filters( 'bsf_taxonomy_objects_custom_fonts', array() ),
108
+ apply_filters( 'bsf_taxonomy_args_custom_fonts', $args )
109
+ );
110
+ }
111
+
112
+ /**
113
+ * Default fonts
114
+ *
115
+ * @since 1.0.0
116
+ * @param array fonts array of fonts.
117
+ */
118
+ protected static function default_args( $fonts ) {
119
+ return wp_parse_args(
120
+ $fonts,
121
+ array(
122
+ 'font_woff_2'=> '',
123
+ 'font_woff' => '',
124
+ 'font_ttf' => '',
125
+ 'font_svg' => '',
126
+ 'font_eot' => '',
127
+ )
128
+ );
129
+ }
130
+
131
+ /**
132
+ * Get fonts
133
+ *
134
+ * @since 1.0.0
135
+ * @return array fonts array of fonts.
136
+ */
137
+ public static function get_fonts() {
138
+
139
+ if ( is_null( self::$fonts ) ) {
140
+ self::$fonts = array();
141
+
142
+ $terms = get_terms(
143
+ self::$register_taxonomy_slug,
144
+ array(
145
+ 'hide_empty' => false,
146
+ )
147
+ );
148
+
149
+ if ( ! empty( $terms ) ) {
150
+ foreach ( $terms as $term ) {
151
+ self::$fonts[ $term->name ] = self::get_font_links( $term->term_id );
152
+ }
153
+ }
154
+ }
155
+ return self::$fonts;
156
+ }
157
+
158
+
159
+ public static function get_links_by_name( $name ){
160
+
161
+ $terms = get_terms(
162
+ self::$register_taxonomy_slug,
163
+ array(
164
+ 'hide_empty' => false,
165
+ )
166
+ );
167
+ $font_links = array();
168
+ if ( ! empty( $terms ) ) {
169
+
170
+ foreach ( $terms as $term ) {
171
+ if ( $term->name == $name ) {
172
+ $font_links[ $term->name ] = self::get_font_links( $term->term_id );
173
+ }
174
+ }
175
+ }
176
+
177
+ return $font_links;
178
+
179
+ }
180
+
181
+ public static function has_fonts() {
182
+ $fonts = self::get_fonts();
183
+ return ! empty( $fonts );
184
+ }
185
+
186
+ public static function get_font_links( $term_id ) {
187
+ $links = get_option( "taxonomy_" . self::$register_taxonomy_slug . "_{$term_id}", array() );
188
+ return self::default_args( $links );
189
+ }
190
+
191
+ public static function update_font_links( $posted, $term_id ) {
192
+
193
+ $links = self::get_font_links( $term_id );
194
+ foreach ( array_keys( $links ) as $key ) {
195
+ if ( isset( $posted[ $key ] ) ) {
196
+ $links[ $key ] = $posted[ $key ];
197
+ } else {
198
+ $links[ $key ] = '';
199
+ }
200
+ }
201
+ update_option( "taxonomy_" . self::$register_taxonomy_slug . "_{$term_id}", $links );
202
+ }
203
+
204
+ }
205
+
206
+
207
+
208
+ /**
209
+ * Kicking this off by calling 'get_instance()' method
210
+ */
211
+ Bsf_Custom_Fonts_Taxonomy::get_instance();
212
+
213
+ endif;
languages/bsf-custom-fonts.pot ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2017 Brainstorm Force
2
+ # This file is distributed under the same license as the Custom Fonts package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Custom Fonts 1.0.0\n"
6
+ "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/bsf-custom-fonts\n"
7
+ "POT-Creation-Date: 2017-08-11 11:44:17+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=utf-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2017-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "X-Generator: grunt-wp-i18n 0.5.4\n"
15
+ "X-Poedit-KeywordsList: "
16
+ "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_"
17
+ "attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
18
+ "Language: en\n"
19
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
20
+ "X-Poedit-Country: United States\n"
21
+ "X-Poedit-SourceCharset: UTF-8\n"
22
+ "X-Poedit-Basepath: ../\n"
23
+ "X-Poedit-SearchPath-0: .\n"
24
+ "X-Poedit-Bookmarks: \n"
25
+ "X-Textdomain-Support: yes\n"
26
+
27
+ #: classes/class-bsf-custom-fonts-render.php:194
28
+ #. translators: 1: Astra theme from wordpress.org
29
+ msgid "Custom Fonts Plugin requires minimum 1.0.16 version of the Astra Theme."
30
+ msgstr ""
31
+
32
+ #: includes/class-bsf-custom-fonts-admin.php:78
33
+ #: includes/class-bsf-custom-fonts-admin.php:79
34
+ #: includes/class-bsf-custom-fonts-taxonomy.php:81
35
+ msgid "BSF Custom Fonts"
36
+ msgstr ""
37
+
38
+ #: includes/class-bsf-custom-fonts-admin.php:103
39
+ msgid "The name of the font as it appears in the attached CSS file."
40
+ msgstr ""
41
+
42
+ #: includes/class-bsf-custom-fonts-admin.php:130
43
+ #: includes/class-bsf-custom-fonts-admin.php:144
44
+ msgid "Font .woff2"
45
+ msgstr ""
46
+
47
+ #: includes/class-bsf-custom-fonts-admin.php:131
48
+ #: includes/class-bsf-custom-fonts-admin.php:145
49
+ msgid "Font .woff"
50
+ msgstr ""
51
+
52
+ #: includes/class-bsf-custom-fonts-admin.php:132
53
+ #: includes/class-bsf-custom-fonts-admin.php:146
54
+ msgid "Font .ttf"
55
+ msgstr ""
56
+
57
+ #: includes/class-bsf-custom-fonts-admin.php:133
58
+ #: includes/class-bsf-custom-fonts-admin.php:147
59
+ msgid "Font .eot"
60
+ msgstr ""
61
+
62
+ #: includes/class-bsf-custom-fonts-admin.php:134
63
+ #: includes/class-bsf-custom-fonts-admin.php:148
64
+ msgid "Font .svg"
65
+ msgstr ""
66
+
67
+ #: includes/class-bsf-custom-fonts-admin.php:161
68
+ #: includes/class-bsf-custom-fonts-admin.php:181
69
+ msgid "Upload"
70
+ msgstr ""
71
+
72
+ #: includes/class-bsf-custom-fonts-admin.php:162
73
+ #: includes/class-bsf-custom-fonts-admin.php:182
74
+ msgid "Upload or enter the file URL"
75
+ msgstr ""
76
+
77
+ #: includes/class-bsf-custom-fonts-taxonomy.php:82
78
+ msgid "Font"
79
+ msgstr ""
80
+
81
+ #: includes/class-bsf-custom-fonts-taxonomy.php:84
82
+ msgid "Search Fonts"
83
+ msgstr ""
84
+
85
+ #: includes/class-bsf-custom-fonts-taxonomy.php:85
86
+ msgid "All Fonts"
87
+ msgstr ""
88
+
89
+ #: includes/class-bsf-custom-fonts-taxonomy.php:86
90
+ msgid "Parent Font"
91
+ msgstr ""
92
+
93
+ #: includes/class-bsf-custom-fonts-taxonomy.php:87
94
+ msgid "Parent Font:"
95
+ msgstr ""
96
+
97
+ #: includes/class-bsf-custom-fonts-taxonomy.php:88
98
+ msgid "Edit Font"
99
+ msgstr ""
100
+
101
+ #: includes/class-bsf-custom-fonts-taxonomy.php:89
102
+ msgid "Update Font"
103
+ msgstr ""
104
+
105
+ #: includes/class-bsf-custom-fonts-taxonomy.php:90
106
+ msgid "Add New Font"
107
+ msgstr ""
108
+
109
+ #: includes/class-bsf-custom-fonts-taxonomy.php:91
110
+ msgid "New Font Name"
111
+ msgstr ""
112
+
113
+ #. Plugin Name of the plugin/theme
114
+ msgid "Custom Fonts"
115
+ msgstr ""
116
+
117
+ #. Plugin URI of the plugin/theme
118
+ msgid "http://www.wpastra.com/"
119
+ msgstr ""
120
+
121
+ #. Description of the plugin/theme
122
+ msgid ""
123
+ "Custom Fonts allows you to add more fonts that extend formatting options in "
124
+ "your site."
125
+ msgstr ""
126
+
127
+ #. Author of the plugin/theme
128
+ msgid "Brainstorm Force"
129
+ msgstr ""
130
+
131
+ #. Author URI of the plugin/theme
132
+ msgid "http://www.brainstormforce.com"
133
+ msgstr ""
134
+
135
+ #: includes/class-bsf-custom-fonts-taxonomy.php:83
136
+ msgctxt "Admin menu name"
137
+ msgid "BSF Custom Fonts"
138
+ msgstr ""
readme.txt ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Custom Fonts ===
2
+ Contributors: brainstormforce
3
+ Donate link: https://wpastra.com/
4
+ Tags: custom fonts, theme custom fonts, unlimited custom fonts
5
+ Requires at least: 4.4
6
+ Tested up to: 4.8.1
7
+ Stable tag: 1.0.0
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Custom Fonts allows you to add more fonts that extend formatting options in your site.
12
+
13
+ == Description ==
14
+
15
+ Custom Fonts allows you to add more fonts that extend formatting options in your site.
16
+
17
+ Upload your desired fonts and start using it without knowing any CSS.
18
+
19
+ == Installation ==
20
+
21
+ 1. Upload the plugin files to the `/wp-content/plugins/custom-fonts` directory, or install the plugin through the WordPress plugins screen directly.
22
+ 2. Activate the plugin through the 'Plugins' screen in WordPress
23
+ 3. Use the Appearance->BSF Custom Fonts -> Add Custom Fonts name, woff2, woff, ttf, eot and svg files.
24
+
25
+ == Changelog ==
26
+
27
+ v1.0.0
28
+ * Initial release