Custom Fonts - Version 1.1.0

Version Description

  • New: Option to select font-display property.
Download this release

Release Info

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

Code changes from version 1.0.8 to 1.1.0

assets/css/bsf-custom-fonts.css CHANGED
@@ -6,4 +6,8 @@
6
  float: right;
7
  margin-right: 5%;
8
  margin-top: 2px;
 
 
 
 
9
  }
6
  float: right;
7
  margin-right: 5%;
8
  margin-top: 2px;
9
+ }
10
+
11
+ .bsf-custom-font-select-field {
12
+ width: 95%;
13
  }
classes/class-bsf-custom-fonts-render.php CHANGED
@@ -245,7 +245,9 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Render' ) ) :
245
  $arr[] = 'url(' . esc_url( $links['font_svg'] ) . '#' . esc_attr( strtolower( str_replace( ' ', '_', $font ) ) ) . ") format('svg')";
246
  }
247
  $css .= join( ', ', $arr );
248
- $css .= ';}';
 
 
249
  endforeach;
250
 
251
  $this->font_css .= $css;
245
  $arr[] = 'url(' . esc_url( $links['font_svg'] ) . '#' . esc_attr( strtolower( str_replace( ' ', '_', $font ) ) ) . ") format('svg')";
246
  }
247
  $css .= join( ', ', $arr );
248
+ $css .= ';';
249
+ $css .= 'font-display: ' . esc_attr( $links['font-display'] ) . ';';
250
+ $css .= '}';
251
  endforeach;
252
 
253
  $this->font_css .= $css;
custom-fonts.php CHANGED
@@ -6,7 +6,7 @@
6
  * Author: Brainstorm Force
7
  * Author URI: http://www.brainstormforce.com
8
  * Text Domain: custom-fonts
9
- * Version: 1.0.8
10
  *
11
  * @package Bsf_Custom_Fonts
12
  */
@@ -25,7 +25,7 @@ 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.8' );
29
 
30
  /**
31
  * BSF Custom Fonts
6
  * Author: Brainstorm Force
7
  * Author URI: http://www.brainstormforce.com
8
  * Text Domain: custom-fonts
9
+ * Version: 1.1.0
10
  *
11
  * @package Bsf_Custom_Fonts
12
  */
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.1.0' );
29
 
30
  /**
31
  * BSF Custom Fonts
includes/class-bsf-custom-fonts-admin.php CHANGED
@@ -118,7 +118,7 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
118
 
119
  $screen = get_current_screen();
120
  // If current screen is add new custom fonts screen.
121
- if ( 'edit-tags' == $screen->base ) {
122
 
123
  $old_columns = $columns;
124
  $columns = array(
@@ -142,6 +142,19 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
142
  $this->font_file_new_field( 'font_eot', __( 'Font .eot', 'custom-fonts' ), __( 'Upload the font\'s eot file or enter the URL.', 'custom-fonts' ) );
143
  $this->font_file_new_field( 'font_svg', __( 'Font .svg', 'custom-fonts' ), __( 'Upload the font\'s svg file or enter the URL.', 'custom-fonts' ) );
144
  $this->font_file_new_field( 'font_otf', __( 'Font .otf', 'custom-fonts' ), __( 'Upload the font\'s otf file or enter the URL.', 'custom-fonts' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  }
146
 
147
  /**
@@ -158,6 +171,20 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
158
  $this->font_file_edit_field( 'font_eot', __( 'Font .eot', 'custom-fonts' ), $data['font_eot'], __( 'Upload the font\'s eot file or enter the URL.', 'custom-fonts' ) );
159
  $this->font_file_edit_field( 'font_svg', __( 'Font .svg', 'custom-fonts' ), $data['font_svg'], __( 'Upload the font\'s svg file or enter the URL.', 'custom-fonts' ) );
160
  $this->font_file_edit_field( 'font_otf', __( 'Font .otf', 'custom-fonts' ), $data['font_otf'], __( 'Upload the font\'s otf file or enter the URL.', 'custom-fonts' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  }
162
 
163
  /**
@@ -181,6 +208,62 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
181
  <?php
182
  }
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  /**
185
  * Add Taxonomy data field
186
  *
118
 
119
  $screen = get_current_screen();
120
  // If current screen is add new custom fonts screen.
121
+ if ( isset( $screen->base ) && 'edit-tags' == $screen->base ) {
122
 
123
  $old_columns = $columns;
124
  $columns = array(
142
  $this->font_file_new_field( 'font_eot', __( 'Font .eot', 'custom-fonts' ), __( 'Upload the font\'s eot file or enter the URL.', 'custom-fonts' ) );
143
  $this->font_file_new_field( 'font_svg', __( 'Font .svg', 'custom-fonts' ), __( 'Upload the font\'s svg file or enter the URL.', 'custom-fonts' ) );
144
  $this->font_file_new_field( 'font_otf', __( 'Font .otf', 'custom-fonts' ), __( 'Upload the font\'s otf file or enter the URL.', 'custom-fonts' ) );
145
+
146
+ $this->select_new_field(
147
+ 'font-display',
148
+ __( 'Font Display', 'custom-fonts' ),
149
+ __( 'Select font-display property for this font', 'custom-fonts' ),
150
+ array(
151
+ 'auto' => 'auto',
152
+ 'block' => 'block',
153
+ 'swap' => 'swap',
154
+ 'fallback' => 'fallback',
155
+ 'optional' => 'optional',
156
+ )
157
+ );
158
  }
159
 
160
  /**
171
  $this->font_file_edit_field( 'font_eot', __( 'Font .eot', 'custom-fonts' ), $data['font_eot'], __( 'Upload the font\'s eot file or enter the URL.', 'custom-fonts' ) );
172
  $this->font_file_edit_field( 'font_svg', __( 'Font .svg', 'custom-fonts' ), $data['font_svg'], __( 'Upload the font\'s svg file or enter the URL.', 'custom-fonts' ) );
173
  $this->font_file_edit_field( 'font_otf', __( 'Font .otf', 'custom-fonts' ), $data['font_otf'], __( 'Upload the font\'s otf file or enter the URL.', 'custom-fonts' ) );
174
+
175
+ $this->select_edit_field(
176
+ 'font-display',
177
+ __( 'Font Display', 'custom-fonts' ),
178
+ $data['font-display'],
179
+ __( 'Select font-display property for this font', 'custom-fonts' ),
180
+ array(
181
+ 'auto' => 'Auto',
182
+ 'block' => 'Block',
183
+ 'swap' => 'Swap',
184
+ 'fallback' => 'Fallback',
185
+ 'optional' => 'Optional',
186
+ )
187
+ );
188
  }
189
 
190
  /**
208
  <?php
209
  }
210
 
211
+ /**
212
+ * Render select field for the new font screen.
213
+ *
214
+ * @param String $id Field ID.
215
+ * @param String $title Field Title.
216
+ * @param String $description Field Description.
217
+ * @param Array $select_fields Select fields as Array.
218
+ * @return void
219
+ */
220
+ protected function select_new_field( $id, $title, $description, $select_fields ) {
221
+ ?>
222
+ <div class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap" >
223
+ <label for="font-<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $title ); ?></label>
224
+ <select type="select" id="font-<?php echo esc_attr( $id ); ?>" class="bsf-custom-font-select-field <?php echo esc_attr( $id ); ?>" name="<?php echo Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug; ?>[<?php echo esc_attr( $id ); ?>]" />
225
+ <?php
226
+ foreach ( $select_fields as $key => $value ) {
227
+ ?>
228
+ <option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value ); ?></option>;
229
+ <?php } ?>
230
+ </select>
231
+ </div>
232
+ <?php
233
+ }
234
+
235
+ /**
236
+ * Render select field for the edit font screen.
237
+ *
238
+ * @param String $id Field ID.
239
+ * @param String $title Field Title.
240
+ * @param String $saved_val Field Value.
241
+ * @param String $description Field Description.
242
+ * @param Array $select_fields Select fields as Array.
243
+ * @return void
244
+ */
245
+ private function select_edit_field( $id, $title, $saved_val = '', $description, $select_fields ) {
246
+ ?>
247
+ <tr class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap ">
248
+ <th scope="row">
249
+ <label for="metadata-<?php echo esc_attr( $id ); ?>">
250
+ <?php echo esc_html( $title ); ?>
251
+ </label>
252
+ </th>
253
+ <td>
254
+ <select type="select" id="font-<?php echo esc_attr( $id ); ?>" class="bsf-custom-font-select-field <?php echo esc_attr( $id ); ?>" name="<?php echo Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug; ?>[<?php echo esc_attr( $id ); ?>]" />
255
+ <?php
256
+ foreach ( $select_fields as $key => $value ) {
257
+ ?>
258
+ <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $saved_val ); ?>><?php echo esc_html( $value ); ?></option>;
259
+ <?php } ?>
260
+ </select>
261
+ <p><?php echo esc_html( $description ); ?></p>
262
+ </td>
263
+ </tr>
264
+ <?php
265
+ }
266
+
267
  /**
268
  * Add Taxonomy data field
269
  *
includes/class-bsf-custom-fonts-taxonomy.php CHANGED
@@ -55,7 +55,7 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Taxonomy' ) ) :
55
  */
56
  public static function get_instance() {
57
  if ( ! isset( self::$_instance ) ) {
58
- self::$_instance = new self;
59
  }
60
 
61
  return self::$_instance;
@@ -120,12 +120,13 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Taxonomy' ) ) :
120
  return wp_parse_args(
121
  $fonts,
122
  array(
123
- 'font_woff_2' => '',
124
- 'font_woff' => '',
125
- 'font_ttf' => '',
126
- 'font_svg' => '',
127
- 'font_eot' => '',
128
- 'font_otf' => '',
 
129
  )
130
  );
131
  }
55
  */
56
  public static function get_instance() {
57
  if ( ! isset( self::$_instance ) ) {
58
+ self::$_instance = new self();
59
  }
60
 
61
  return self::$_instance;
120
  return wp_parse_args(
121
  $fonts,
122
  array(
123
+ 'font_woff_2' => '',
124
+ 'font_woff' => '',
125
+ 'font_ttf' => '',
126
+ 'font_svg' => '',
127
+ 'font_eot' => '',
128
+ 'font_otf' => '',
129
+ 'font-display' => 'swap',
130
  )
131
  );
132
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: brainstormforce
3
  Donate link: https://www.paypal.me/BrainstormForce
4
  Tags: Beaver Builder, Elementor, Astra, woff2, woff, ttf, svg, eot, otf, Custom Fonts, Font, Typography
5
  Requires at least: 4.4
6
- Tested up to: 5.1
7
- Stable tag: 1.0.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -43,6 +43,9 @@ If you're not using any of the supported plugins and theme, you can write the cu
43
 
44
  == Changelog ==
45
 
 
 
 
46
  = v1.0.8 =
47
  - New: Now you can also upload otf fonts.
48
  - Fix: ttf fonts not being uploaded in WordPress media library.
3
  Donate link: https://www.paypal.me/BrainstormForce
4
  Tags: Beaver Builder, Elementor, Astra, woff2, woff, ttf, svg, eot, otf, Custom Fonts, Font, Typography
5
  Requires at least: 4.4
6
+ Tested up to: 5.2
7
+ Stable tag: 1.1.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
43
 
44
  == Changelog ==
45
 
46
+ = 1.1.0 =
47
+ - New: Option to select font-display property.
48
+
49
  = v1.0.8 =
50
  - New: Now you can also upload otf fonts.
51
  - Fix: ttf fonts not being uploaded in WordPress media library.