Custom Fonts - Version 1.3.0

Version Description

  • New: Add multiple font weight to the Custom Fonts.
Download this release

Release Info

Developer brainstormworg
Plugin Icon 128x128 Custom Fonts
Version 1.3.0
Comparing to
See all releases

Code changes from version 1.2.6 to 1.3.0

assets/css/bsf-custom-fonts.css CHANGED
@@ -4,10 +4,48 @@
4
  }
5
  .bsf-custom-fonts-upload.button {
6
  float: right;
7
- margin-right: 5%;
8
  margin-top: 2px;
9
  }
10
 
11
  .bsf-custom-font-select-field {
12
  width: 95%;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  }
4
  }
5
  .bsf-custom-fonts-upload.button {
6
  float: right;
 
7
  margin-top: 2px;
8
  }
9
 
10
  .bsf-custom-font-select-field {
11
  width: 95%;
12
+ }
13
+
14
+ #repeater .bsf-custom-font-select-field,
15
+ #repeater .bsf-custom-fonts-link {
16
+ width: 100%;
17
+ }
18
+
19
+ .col-wrap #repeater + p.submit {
20
+ text-align: center;
21
+ margin-top: 0;
22
+ max-width: 540px;
23
+ }
24
+ #repeater {
25
+ background-color: #f7f7f7;
26
+ padding: 10px;
27
+ box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.2), 0 1px 4px 0 rgba(0, 0, 0, 0.19);
28
+ border-radius: 2px;
29
+ max-width: 540px;
30
+ }
31
+ .cf-bsf-items {
32
+ border-bottom: 1px solid #414b41;
33
+ padding-bottom: 40px;
34
+ margin-bottom: 34px;
35
+ border-bottom-style: dotted;
36
+ }
37
+ .cf-bsf-items:last-of-type {
38
+ border-bottom: 0;
39
+ margin-bottom: 0;
40
+ }
41
+
42
+ .cf-addbutton-wrapper{
43
+ text-align: center;
44
+ padding: 10px;
45
+ background-color: #f7f7f7;
46
+ padding: 10px;
47
+ box-shadow: 0 1px 10px 0px rgba(0, 0, 0, 0.19);
48
+ border-radius: 2px;
49
+ max-width: 540px;
50
+ margin-bottom: 10px;
51
  }
assets/js/bsf-custom-fonts.js CHANGED
@@ -1,20 +1,20 @@
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.
@@ -27,9 +27,9 @@
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(event) {
@@ -51,7 +51,7 @@
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);
@@ -64,9 +64,129 @@
64
  },
65
  }
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  /* Initializes the Bsf Custom Fonts. */
68
  $(function(){
69
  BsfCustomFonts.init();
 
70
  });
71
 
72
- })(jQuery);
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.
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(event) {
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);
64
  },
65
  }
66
 
67
+ function remove_button_disable(){
68
+ if (1 === $('.repeater-remove-btn .remove-btn').length ){
69
+ $('.repeater-remove-btn .remove-btn').addClass('disabled');
70
+ }else{
71
+ $('.repeater-remove-btn .remove-btn').removeClass('disabled');
72
+ }
73
+ }
74
+
75
+ var addButton = $('.repeater-add-btn:last');
76
+
77
+ addButton.on('click', function () {
78
+ var repeaterFieldCount = $('input[name=repeater-field-count]').val();
79
+ var item = $('#repeater .cf-bsf-items').first().clone().prop('id', 'item-' + ( parseInt( repeaterFieldCount ) ) );
80
+
81
+ item.appendTo('#repeater');
82
+ var newItem = $('#item-' + parseInt( repeaterFieldCount ) );
83
+ var input = newItem.find('input,select');
84
+ input.each(function (index, el) {
85
+ var clonedElement = newItem.find(el);
86
+ var attrName = clonedElement.data('name');
87
+ if( attrName == '[font-weight-0]' ) {
88
+ clonedElement.attr('name', 'bsf_custom_fonts[font-weight-' + ( parseInt( repeaterFieldCount ) ) + ']');
89
+ }
90
+ if( attrName == '[font_woff_2-0]' ) {
91
+ clonedElement.attr('name', 'bsf_custom_fonts[font_woff_2-' + ( parseInt( repeaterFieldCount ) ) + ']');
92
+ clonedElement.attr('value', '');
93
+ }
94
+ if( attrName == '[font_woff-0]' ) {
95
+ clonedElement.attr('name', 'bsf_custom_fonts[font_woff-' + ( parseInt( repeaterFieldCount ) ) + ']');
96
+ clonedElement.attr('value', '');
97
+ }
98
+ if( attrName == '[font_ttf-0]' ) {
99
+ clonedElement.attr('name', 'bsf_custom_fonts[font_ttf-' + ( parseInt( repeaterFieldCount ) ) + ']');
100
+ clonedElement.attr('value', '');
101
+ }
102
+ if( attrName == '[font_eot-0]' ) {
103
+ clonedElement.attr('name', 'bsf_custom_fonts[font_eot-' + ( parseInt( repeaterFieldCount ) ) + ']');
104
+ clonedElement.attr('value', '');
105
+ }
106
+ if( attrName == '[font_svg-0]' ) {
107
+ clonedElement.attr('name', 'bsf_custom_fonts[font_svg-' + ( parseInt( repeaterFieldCount ) ) + ']');
108
+ clonedElement.attr('value', '');
109
+ }
110
+ if( attrName == '[font_otf-0]' ) {
111
+ clonedElement.attr('name', 'bsf_custom_fonts[font_otf-' + ( parseInt( repeaterFieldCount ) ) + ']');
112
+ clonedElement.attr('value', '');
113
+ }
114
+ });
115
+ $('input[name=repeater-field-count]').val( parseInt( repeaterFieldCount ) + 1 );
116
+
117
+ remove_button_disable();
118
+ $('html, body').animate({
119
+ scrollTop: newItem.offset().top
120
+ }, 500);
121
+ });
122
+
123
+ var editAddButton = $('.edit-repeater-add-btn:last');
124
+
125
+ editAddButton.on('click', function () {
126
+ var repeaterFieldCount = $('input[name=repeater-field-count]').val();
127
+ var item = $('#repeater .cf-bsf-items').first().clone().prop('id', 'item-' + ( parseInt( repeaterFieldCount ) ) );
128
+ item.appendTo('#repeater');
129
+ var newItem = $('#item-' + repeaterFieldCount);
130
+ var newItemId = $('#repeater .cf-bsf-items').first().find('select').attr('id').replace( /^\D+/g, '');
131
+ var input = newItem.find('input,select');
132
+ input.each(function (index, el) {
133
+ var clonedElement = newItem.find(el);
134
+ var attrName = clonedElement.attr('name');
135
+ if( attrName == 'bsf_custom_fonts[font-weight-' + newItemId + ']' ) {
136
+ clonedElement.attr('name', 'bsf_custom_fonts[font-weight-' + ( parseInt( repeaterFieldCount ) ) + ']');
137
+ }
138
+ if( attrName == 'bsf_custom_fonts[font_woff_2-' + newItemId + ']' ) {
139
+ clonedElement.attr('name', 'bsf_custom_fonts[font_woff_2-' + ( parseInt( repeaterFieldCount ) ) + ']');
140
+ clonedElement.attr('value', '');
141
+ }
142
+ if( attrName == 'bsf_custom_fonts[font_woff-' + newItemId + ']' ) {
143
+ clonedElement.attr('name', 'bsf_custom_fonts[font_woff-' + ( parseInt( repeaterFieldCount ) ) + ']');
144
+ clonedElement.attr('value', '');
145
+ }
146
+ if( attrName == 'bsf_custom_fonts[font_ttf-' + newItemId + ']' ) {
147
+ clonedElement.attr('name', 'bsf_custom_fonts[font_ttf-' + ( parseInt( repeaterFieldCount ) ) + ']');
148
+ clonedElement.attr('value', '');
149
+ }
150
+ if( attrName == 'bsf_custom_fonts[font_eot-' + newItemId + ']' ) {
151
+ clonedElement.attr('name', 'bsf_custom_fonts[font_eot-' + ( parseInt( repeaterFieldCount ) ) + ']');
152
+ clonedElement.attr('value', '');
153
+ }
154
+ if( attrName == 'bsf_custom_fonts[font_svg-' + newItemId + ']' ) {
155
+ clonedElement.attr('name', 'bsf_custom_fonts[font_svg-' + ( parseInt( repeaterFieldCount ) ) + ']');
156
+ clonedElement.attr('value', '');
157
+ }
158
+ if( attrName == 'bsf_custom_fonts[font_otf-' + newItemId + ']' ) {
159
+ clonedElement.attr('name', 'bsf_custom_fonts[font_otf-' + ( parseInt( repeaterFieldCount ) ) + ']');
160
+ clonedElement.attr('value', '');
161
+ }
162
+ });
163
+ $('input[name=repeater-field-count]').val( parseInt( repeaterFieldCount ) + 1 );
164
+
165
+ remove_button_disable();
166
+ $('html, body').animate({
167
+ scrollTop: newItem.offset().top
168
+ }, 500);
169
+ });
170
+
171
+ $(document).on('click', '.remove-btn', function () {
172
+ $this = $(this)
173
+ if ( $this.hasClass( 'disabled' ) ) {
174
+ return false;
175
+ }
176
+ $this.parents('.cf-bsf-items').remove();
177
+ remove_button_disable();
178
+ });
179
+
180
+ $( document ).ajaxComplete(function( event, request, settings ) {
181
+ if( "action=add-tag" === settings.data.split("&")[0]){
182
+ location.reload();
183
+ }
184
+ });
185
+
186
  /* Initializes the Bsf Custom Fonts. */
187
  $(function(){
188
  BsfCustomFonts.init();
189
+ remove_button_disable();
190
  });
191
 
192
+ })(jQuery);
classes/class-bsf-custom-fonts-render.php CHANGED
@@ -35,6 +35,46 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Render' ) ) :
35
  */
36
  private static $font_base = 'bsf-custom-fonts';
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  /**
39
  * Member Varible
40
  *
@@ -77,7 +117,7 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Render' ) ) :
77
  add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
78
 
79
  // add Custom Font list into Astra customizer.
80
- add_action( 'astra_customizer_font_list', array( $this, 'add_customizer_font_list' ) );
81
 
82
  // Beaver builder theme customizer, beaver buidler page builder.
83
  add_filter( 'fl_theme_system_fonts', array( $this, 'bb_custom_fonts' ) );
@@ -91,6 +131,8 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Render' ) ) :
91
 
92
  add_filter( 'elementor/fonts/groups', array( $this, 'elementor_group' ) );
93
  add_filter( 'elementor/fonts/additional_fonts', array( $this, 'add_elementor_fonts' ) );
 
 
94
  }
95
 
96
  /**
@@ -109,6 +151,31 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Render' ) ) :
109
  return $font_groups;
110
  }
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  /**
113
  * Add Custom Fonts to the Elementor Page builder's font param.
114
  *
@@ -173,18 +240,41 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Render' ) ) :
173
  /**
174
  * Add Custom Font list into Astra customizer.
175
  *
176
- * @since 1.0.0
177
- * @param string $value selected font family.
 
178
  */
179
- public function add_customizer_font_list( $value ) {
180
 
181
  $fonts = Bsf_Custom_Fonts_Taxonomy::get_fonts();
182
 
183
- echo '<optgroup label="' . esc_attr( 'Custom' ) . '">';
184
-
185
- foreach ( $fonts as $font => $links ) {
186
- echo '<option value="' . esc_attr( $font ) . '" ' . selected( $font, $value, false ) . '>' . esc_attr( $font ) . '</option>';
 
 
 
 
 
 
 
187
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  }
189
 
190
  /**
@@ -193,11 +283,9 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Render' ) ) :
193
  * @since 1.0.0
194
  */
195
  public function enqueue_admin_scripts() {
196
-
197
  wp_enqueue_style( 'bsf-custom-fonts-css', BSF_CUSTOM_FONTS_URI . 'assets/css/bsf-custom-fonts.css', array(), BSF_CUSTOM_FONTS_VER );
198
  wp_enqueue_media();
199
- wp_enqueue_script( 'bsf-custom-fonts-js', BSF_CUSTOM_FONTS_URI . 'assets/js/bsf-custom-fonts.js', array(), BSF_CUSTOM_FONTS_VER, false );
200
-
201
  }
202
 
203
  /**
@@ -225,34 +313,55 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Render' ) ) :
225
  * @param array $font selected font from custom font list.
226
  */
227
  private function render_font_css( $font ) {
228
- $fonts = Bsf_Custom_Fonts_Taxonomy::get_links_by_name( $font );
229
-
230
- foreach ( $fonts as $font => $links ) :
231
- $css = '@font-face { font-family:' . esc_attr( $font ) . ';';
232
- $css .= 'src:';
233
- $arr = array();
234
- if ( $links['font_woff_2'] ) {
235
- $arr[] = 'url(' . esc_url( $links['font_woff_2'] ) . ") format('woff2')";
236
- }
237
- if ( $links['font_woff'] ) {
238
- $arr[] = 'url(' . esc_url( $links['font_woff'] ) . ") format('woff')";
239
- }
240
- if ( $links['font_ttf'] ) {
241
- $arr[] = 'url(' . esc_url( $links['font_ttf'] ) . ") format('truetype')";
242
- }
243
- if ( $links['font_otf'] ) {
244
- $arr[] = 'url(' . esc_url( $links['font_otf'] ) . ") format('opentype')";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  }
246
- if ( $links['font_svg'] ) {
247
- $arr[] = 'url(' . esc_url( $links['font_svg'] ) . '#' . esc_attr( strtolower( str_replace( ' ', '_', $font ) ) ) . ") format('svg')";
 
 
 
 
 
 
 
 
248
  }
249
- $css .= join( ', ', $arr );
250
- $css .= ';';
251
- $css .= 'font-display: ' . esc_attr( $links['font-display'] ) . ';';
252
- $css .= '}';
253
- endforeach;
254
-
255
- $this->font_css .= $css;
256
  }
257
 
258
  /**
35
  */
36
  private static $font_base = 'bsf-custom-fonts';
37
 
38
+ /**
39
+ * Font Weight.
40
+ *
41
+ * Store the Font Weight from DB to be use for frontend rendering.
42
+ *
43
+ * @since x.x.x
44
+ * @var string
45
+ */
46
+ private static $font_weight = '';
47
+
48
+ /**
49
+ * Font Display.
50
+ *
51
+ * Store the Font Display from DB to be use for frontend rendering.
52
+ *
53
+ * @since x.x.x
54
+ * @var string
55
+ */
56
+ private static $font_display = '';
57
+
58
+ /**
59
+ * Font Family.
60
+ *
61
+ * Store the Font Family from DB to be use for frontend rendering.
62
+ *
63
+ * @since x.x.x
64
+ * @var string
65
+ */
66
+ private static $font_family = '';
67
+
68
+ /**
69
+ * Font Fallback.
70
+ *
71
+ * Store the Font Fallback from DB to be use for frontend rendering.
72
+ *
73
+ * @since x.x.x
74
+ * @var string
75
+ */
76
+ private static $font_fallback = '';
77
+
78
  /**
79
  * Member Varible
80
  *
117
  add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
118
 
119
  // add Custom Font list into Astra customizer.
120
+ add_filter( 'astra_system_fonts', array( $this, 'add_custom_fonts_astra_customizer' ) );
121
 
122
  // Beaver builder theme customizer, beaver buidler page builder.
123
  add_filter( 'fl_theme_system_fonts', array( $this, 'bb_custom_fonts' ) );
131
 
132
  add_filter( 'elementor/fonts/groups', array( $this, 'elementor_group' ) );
133
  add_filter( 'elementor/fonts/additional_fonts', array( $this, 'add_elementor_fonts' ) );
134
+ // Astra filter before creating google fonts URL.
135
+ add_filter( 'astra_google_fonts_selected', array( $this, 'remove_custom_font_google_url' ) );
136
  }
137
 
138
  /**
151
  return $font_groups;
152
  }
153
 
154
+ /**
155
+ * Remove Custom Font from Google Font URL.
156
+ *
157
+ * @param Array $fonts Selected Google Fonts in the Astra Customizer Settings.
158
+ * @return Array Google fonts array which do not contain same fonts as the custom fonts.
159
+ *
160
+ * @since x.x.x
161
+ */
162
+ public function remove_custom_font_google_url( $fonts ) {
163
+ $custom_fonts = Bsf_Custom_Fonts_Taxonomy::get_fonts();
164
+ if ( ! empty( $custom_fonts ) ) {
165
+ foreach ( $custom_fonts as $key => $value ) {
166
+ if ( $value['font_fallback'] ) {
167
+ $font_key = "'" . $key . "'" . ', ' . $value['font_fallback'];
168
+ } else {
169
+ $font_key = "'" . $key . "'";
170
+ }
171
+ if ( array_key_exists( $font_key, $fonts ) ) {
172
+ unset( $fonts[ $font_key ] );
173
+ }
174
+ }
175
+ }
176
+ return $fonts;
177
+ }
178
+
179
  /**
180
  * Add Custom Fonts to the Elementor Page builder's font param.
181
  *
240
  /**
241
  * Add Custom Font list into Astra customizer.
242
  *
243
+ * @since x.x.x
244
+ * @param string $fonts_arr Array of System Fonts.
245
+ * @return array $fonts_arr modified array with Custom Fonts.
246
  */
247
+ public function add_custom_fonts_astra_customizer( $fonts_arr ) {
248
 
249
  $fonts = Bsf_Custom_Fonts_Taxonomy::get_fonts();
250
 
251
+ foreach ( $fonts as $font => $values ) {
252
+ $custom_fonts_weights = array();
253
+ foreach ( $values as $key => $value ) {
254
+ if ( strpos( $key, 'weight' ) !== false ) {
255
+ array_push( $custom_fonts_weights, $value );
256
+ }
257
+ }
258
+ $fonts_arr[ $font ] = array(
259
+ 'fallback' => $values['font_fallback'] ? $values['font_fallback'] : 'Helvetica, Arial, sans-serif',
260
+ 'weights' => $custom_fonts_weights,
261
+ );
262
  }
263
+
264
+ return $fonts_arr;
265
+ }
266
+
267
+ /**
268
+ * Get fonts
269
+ *
270
+ * @since x.x.x
271
+ * @param array $font font.
272
+ * @param array $font_fallback fallback fonts.
273
+ */
274
+ public static function get_font_values( $font, $font_fallback ) {
275
+
276
+ $font .= ( isset( $font_fallback ) ) ? ', ' . trim( $font_fallback ) : '';
277
+ return $font;
278
  }
279
 
280
  /**
283
  * @since 1.0.0
284
  */
285
  public function enqueue_admin_scripts() {
 
286
  wp_enqueue_style( 'bsf-custom-fonts-css', BSF_CUSTOM_FONTS_URI . 'assets/css/bsf-custom-fonts.css', array(), BSF_CUSTOM_FONTS_VER );
287
  wp_enqueue_media();
288
+ wp_enqueue_script( 'bsf-custom-fonts-js', BSF_CUSTOM_FONTS_URI . 'assets/js/bsf-custom-fonts.js', array( 'jquery' ), BSF_CUSTOM_FONTS_VER, true );
 
289
  }
290
 
291
  /**
313
  * @param array $font selected font from custom font list.
314
  */
315
  private function render_font_css( $font ) {
316
+ $fonts = Bsf_Custom_Fonts_Taxonomy::get_links_by_name( $font );
317
+ $arr_font = array();
318
+
319
+ foreach ( $fonts as $font_key => $font_value ) {
320
+ self::$font_family = $font_key;
321
+ foreach ( $font_value as $key => $value ) {
322
+ if ( strpos( $key, 'display' ) !== false ) {
323
+ self::$font_display = $value;
324
+ }
325
+ if ( strpos( $key, 'fallback' ) !== false ) {
326
+ self::$font_fallback = $value;
327
+ }
328
+ if ( strpos( $key, 'weight' ) !== false ) {
329
+ self::$font_weight = $value;
330
+ $arr_font[ $value ] = array();
331
+ }
332
+ if ( strpos( $key, 'font_woff_2' ) !== false && $value ) {
333
+ $arr_font[ self::$font_weight ][0] = 'url(' . esc_url( $value ) . ") format('woff2')";
334
+ }
335
+ if ( strpos( $key, 'font_woff-' ) !== false && $value ) {
336
+ $arr_font[ self::$font_weight ][1] = 'url(' . esc_url( $value ) . ") format('woff')";
337
+ }
338
+ if ( strpos( $key, 'font_ttf-' ) !== false && $value ) {
339
+ $arr_font[ self::$font_weight ][2] = 'url(' . esc_url( $value ) . ") format('TrueType')";
340
+ }
341
+ if ( strpos( $key, 'font_eot-' ) !== false && $value ) {
342
+ $arr_font[ self::$font_weight ][3] = 'url(' . esc_url( $value ) . ") format('eot')";
343
+ }
344
+ if ( strpos( $key, 'font_svg-' ) !== false && $value ) {
345
+ $arr_font[ self::$font_weight ][4] = 'url(' . esc_url( $value ) . ") format('svg')";
346
+ }
347
+ if ( strpos( $key, 'font_otf-' ) !== false && $value ) {
348
+ $arr_font[ self::$font_weight ][5] = 'url(' . esc_url( $value ) . ") format('OpenType')";
349
+ }
350
  }
351
+ }
352
+ $font_face_css = '';
353
+ foreach ( $arr_font as $key => $value ) {
354
+ $font_face_css .= '@font-face {';
355
+ $font_face_css .= 'font-family: "' . self::$font_family . '";';
356
+ $font_face_css .= 'font-display: ' . self::$font_display . ';';
357
+ $font_face_css .= 'font-fallback: ' . self::$font_fallback . ';';
358
+ $font_face_css .= 'font-weight: ' . $key . ';';
359
+ foreach ( $value as $font_file ) {
360
+ $font_face_css .= 'src: ' . $font_file . '; ';
361
  }
362
+ $font_face_css .= '} ';
363
+ }
364
+ $this->font_css .= $font_face_css;
 
 
 
 
365
  }
366
 
367
  /**
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.2.6
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.2.6' );
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.3.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.3.0' );
29
 
30
  /**
31
  * BSF Custom Fonts
includes/class-bsf-custom-fonts-admin.php CHANGED
@@ -33,6 +33,14 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
33
  */
34
  protected $parent_menu_slug = 'themes.php';
35
 
 
 
 
 
 
 
 
 
36
  /**
37
  * Instance of Bsf_Custom_Fonts_Admin.
38
  *
@@ -60,7 +68,7 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
60
  add_filter( 'manage_edit-' . Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug . '_columns', array( $this, 'manage_columns' ) );
61
 
62
  add_action( Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug . '_add_form_fields', array( $this, 'add_new_taxonomy_data' ) );
63
- add_action( Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug . '_edit_form_fields', array( $this, 'edit_taxonomy_data' ) );
64
 
65
  add_action( 'edited_' . Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug, array( $this, 'save_metadata' ) );
66
  add_action( 'create_' . Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug, array( $this, 'save_metadata' ) );
@@ -103,7 +111,8 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
103
  }
104
 
105
  ?><style>#addtag div.form-field.term-slug-wrap, #edittag tr.form-field.term-slug-wrap { display: none; }
106
- #addtag div.form-field.term-description-wrap, #edittag tr.form-field.term-description-wrap { display: none; }</style><script>jQuery( document ).ready( function( $ ) {
 
107
  var $wrapper = $( '#addtag, #edittag' );
108
  $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 customizer options.', 'custom-fonts' ); ?>' );
109
  } );</script>
@@ -133,20 +142,55 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
133
  return $columns;
134
  }
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  /**
137
  * Add new Taxonomy data
138
  *
139
  * @since 1.0.0
140
  */
141
- public function add_new_taxonomy_data() {
142
- $this->font_file_new_field( 'font_woff_2', __( 'Font .woff2', 'custom-fonts' ), __( 'Upload the font\'s woff2 file or enter the URL.', 'custom-fonts' ) );
143
- $this->font_file_new_field( 'font_woff', __( 'Font .woff', 'custom-fonts' ), __( 'Upload the font\'s woff file or enter the URL.', 'custom-fonts' ) );
144
- $this->font_file_new_field( 'font_ttf', __( 'Font .ttf', 'custom-fonts' ), __( 'Upload the font\'s ttf file or enter the URL.', 'custom-fonts' ) );
145
- $this->font_file_new_field( 'font_eot', __( 'Font .eot', 'custom-fonts' ), __( 'Upload the font\'s eot file or enter the URL.', 'custom-fonts' ) );
146
- $this->font_file_new_field( 'font_svg', __( 'Font .svg', 'custom-fonts' ), __( 'Upload the font\'s svg file or enter the URL.', 'custom-fonts' ) );
147
- $this->font_file_new_field( 'font_otf', __( 'Font .otf', 'custom-fonts' ), __( 'Upload the font\'s otf file or enter the URL.', 'custom-fonts' ) );
148
 
149
- $this->select_new_field(
150
  'font-display',
151
  __( 'Font Display', 'custom-fonts' ),
152
  __( 'Select font-display property for this font', 'custom-fonts' ),
@@ -160,26 +204,83 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
160
  );
161
  }
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  /**
164
  * Edit Taxonomy data
165
  *
166
  * @since 1.0.0
167
  * @param object $term taxonomy terms.
168
  */
169
- public function edit_taxonomy_data( $term ) {
170
-
171
  $data = Bsf_Custom_Fonts_Taxonomy::get_font_links( $term->term_id );
172
- $this->font_file_edit_field( 'font_woff_2', __( 'Font .woff2', 'custom-fonts' ), $data['font_woff_2'], __( 'Upload the font\'s woff2 file or enter the URL.', 'custom-fonts' ) );
173
- $this->font_file_edit_field( 'font_woff', __( 'Font .woff', 'custom-fonts' ), $data['font_woff'], __( 'Upload the font\'s woff file or enter the URL.', 'custom-fonts' ) );
174
- $this->font_file_edit_field( 'font_ttf', __( 'Font .ttf', 'custom-fonts' ), $data['font_ttf'], __( 'Upload the font\'s ttf file or enter the URL.', 'custom-fonts' ) );
175
- $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' ) );
176
- $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' ) );
177
- $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' ) );
178
-
179
- $this->select_edit_field(
180
  'font-display',
181
  __( 'Font Display', 'custom-fonts' ),
182
- $data['font-display'],
183
  __( 'Select font-display property for this font', 'custom-fonts' ),
184
  array(
185
  'auto' => 'Auto',
@@ -187,8 +288,94 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
187
  'swap' => 'Swap',
188
  'fallback' => 'Fallback',
189
  'optional' => 'Optional',
190
- )
 
191
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  }
193
 
194
  /**
@@ -205,7 +392,7 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
205
  <div class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap" >
206
 
207
  <label for="font-<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $title ); ?></label>
208
- <input type="text" id="font-<?php echo esc_attr( $id ); ?>" class="bsf-custom-fonts-link <?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug ); ?>[<?php echo esc_attr( $id ); ?>]" value="<?php echo esc_attr( $value ); ?>" />
209
  <a href="#" class="bsf-custom-fonts-upload button" data-upload-type="<?php echo esc_attr( $id ); ?>"><?php esc_html_e( 'Upload', 'custom-fonts' ); ?></a>
210
  <p><?php echo esc_html( $description ); ?></p>
211
  </div>
@@ -221,7 +408,7 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
221
  * @param Array $select_fields Select fields as Array.
222
  * @return void
223
  */
224
- protected function select_new_field( $id, $title, $description, $select_fields ) {
225
  ?>
226
  <div class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap" >
227
  <label for="font-<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $title ); ?></label>
@@ -236,17 +423,70 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
236
  <?php
237
  }
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  /**
240
  * Render select field for the edit font screen.
241
  *
242
  * @param String $id Field ID.
243
  * @param String $title Field Title.
244
- * @param String $saved_val Field Value.
245
  * @param String $description Field Description.
246
  * @param Array $select_fields Select fields as Array.
 
247
  * @return void
248
  */
249
- private function select_edit_field( $id, $title, $saved_val, $description, $select_fields ) {
250
  ?>
251
  <tr class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap ">
252
  <th scope="row">
@@ -274,10 +514,10 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
274
  * @since 1.0.0
275
  * @param int $id current term id.
276
  * @param string $title font type title.
277
- * @param string $value title font type meta values.
278
  * @param string $description title font type description.
 
279
  */
280
- protected function font_file_edit_field( $id, $title, $value, $description ) {
281
  ?>
282
  <tr class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap ">
283
  <th scope="row">
@@ -287,13 +527,39 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
287
  </th>
288
  <td>
289
  <input id="metadata-<?php echo esc_attr( $id ); ?>" type="text" class="bsf-custom-fonts-link <?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug ); ?>[<?php echo esc_attr( $id ); ?>]" value="<?php echo esc_attr( $value ); ?>" />
290
- <a href="#" class="bsf-custom-fonts-upload button" data-upload-type="<?php echo esc_attr( $id ); ?>"><?php esc_html_e( 'Upload', 'custom-fonts' ); ?></a>
291
  <p><?php echo esc_html( $description ); ?></p>
292
  </td>
293
  </tr>
294
  <?php
295
  }
296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  /**
298
  * Save Taxonomy meta data value
299
  *
@@ -301,13 +567,13 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
301
  * @param int $term_id current term id.
302
  */
303
  public function save_metadata( $term_id ) {
304
-
305
- if ( ! current_user_can( 'manage_options' ) ) {
306
  return;
307
  }
308
 
309
- if ( isset( $_POST[ Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug ] ) ) {// phpcs:ignore WordPress.Security.NonceVerification.Missing
310
- $value = array_map( 'esc_attr', $_POST[ Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
311
  Bsf_Custom_Fonts_Taxonomy::update_font_links( $value, $term_id );
312
  }
313
  }
@@ -356,8 +622,6 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Admin' ) ) :
356
 
357
  }
358
 
359
-
360
-
361
  /**
362
  * Kicking this off by calling 'get_instance()' method
363
  */
33
  */
34
  protected $parent_menu_slug = 'themes.php';
35
 
36
+ /**
37
+ * Edit repeater field initial count
38
+ *
39
+ * @since x.x.x
40
+ * @var (string) $edit_repeater_field_count
41
+ */
42
+ protected static $edit_repeater_field_count = 0;
43
+
44
  /**
45
  * Instance of Bsf_Custom_Fonts_Admin.
46
  *
68
  add_filter( 'manage_edit-' . Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug . '_columns', array( $this, 'manage_columns' ) );
69
 
70
  add_action( Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug . '_add_form_fields', array( $this, 'add_new_taxonomy_data' ) );
71
+ add_action( Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug . '_edit_form_fields', array( $this, 'edit_new_taxonomy_data' ) );
72
 
73
  add_action( 'edited_' . Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug, array( $this, 'save_metadata' ) );
74
  add_action( 'create_' . Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug, array( $this, 'save_metadata' ) );
111
  }
112
 
113
  ?><style>#addtag div.form-field.term-slug-wrap, #edittag tr.form-field.term-slug-wrap { display: none; }
114
+ #addtag div.form-field.term-description-wrap, #edittag tr.form-field.term-description-wrap { display: none; }</style>
115
+ <script>jQuery( document ).ready( function( $ ) {
116
  var $wrapper = $( '#addtag, #edittag' );
117
  $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 customizer options.', 'custom-fonts' ); ?>' );
118
  } );</script>
142
  return $columns;
143
  }
144
 
145
+ /**
146
+ * Add new taxonomy data.
147
+ */
148
+ public function add_new_taxonomy_data() {
149
+ $this->add_new_taxonomy_default_data();
150
+ ?>
151
+ <input type="hidden" name="repeater-field-count" value="1">
152
+ <?php
153
+ echo '
154
+ <div id="repeater">
155
+ <!-- Repeater Heading -->
156
+
157
+ <div class="clearfix"></div>
158
+ <!-- Repeater Items -->
159
+ <div id="item-0" class="cf-bsf-items" data-group="font-weight-type">
160
+ <!-- Repeater Content -->
161
+ <div class="item-content">
162
+ <div class="form-group">
163
+ <div class="weight-wrapper">';
164
+ $this->add_new_taxonomy_repeater_data();
165
+ wp_nonce_field( basename( __FILE__ ), 'bsf_custom_font_nonce' );
166
+ echo '</div>
167
+ </div>
168
+ </div>
169
+ <!-- Repeater Remove Btn -->
170
+ <div class="repeater-remove-btn">
171
+ <div class="button button-primary disabled remove-btn">
172
+ Remove
173
+ </div>
174
+ </div>
175
+ <div class="clearfix"></div>
176
+ </div>
177
+ </div>
178
+ <div class="cf-addbutton-wrapper">
179
+ <div class="button button-primary repeater-add-btn">
180
+ Add Font Variation
181
+ </div>
182
+ </div>';
183
+ }
184
+
185
  /**
186
  * Add new Taxonomy data
187
  *
188
  * @since 1.0.0
189
  */
190
+ public function add_new_taxonomy_default_data() {
191
+ $this->font_new_field( 'font_fallback', __( 'Font Fallback', 'custom-fonts' ), __( 'Add the font\'s fallback names with comma(,) separator. eg. Arial, Serif', 'custom-fonts' ) );
 
 
 
 
 
192
 
193
+ $this->select_default_new_field(
194
  'font-display',
195
  __( 'Font Display', 'custom-fonts' ),
196
  __( 'Select font-display property for this font', 'custom-fonts' ),
204
  );
205
  }
206
 
207
+ /**
208
+ * Add new Taxonomy data
209
+ *
210
+ * @since 1.0.0
211
+ */
212
+ public function add_new_taxonomy_repeater_data() {
213
+ $this->select_new_field(
214
+ 'font-weight-0',
215
+ __( 'Font weight', 'custom-fonts' ),
216
+ __( 'Select font-weight property for this font', 'custom-fonts' ),
217
+ array(
218
+ '100' => __( 'Thin 100', 'custom-fonts' ),
219
+ '200' => __( 'Extra-Light 200', 'custom-fonts' ),
220
+ '300' => __( 'Light 300', 'custom-fonts' ),
221
+ '400' => __( 'Normal 400', 'custom-fonts' ),
222
+ '500' => __( 'Medium 500', 'custom-fonts' ),
223
+ '600' => __( 'Semi-Bold 600', 'custom-fonts' ),
224
+ '700' => __( 'Bold 700', 'custom-fonts' ),
225
+ '800' => __( 'Extra-Bold 800', 'custom-fonts' ),
226
+ '900' => __( 'Ultra-Bold 900', 'custom-fonts' ),
227
+ )
228
+ );
229
+ $this->font_file_new_field( 'font_woff_2-0', __( 'Font .woff2', 'custom-fonts' ), __( 'Upload the font\'s woff2 file or enter the URL.', 'custom-fonts' ) );
230
+ $this->font_file_new_field( 'font_woff-0', __( 'Font .woff', 'custom-fonts' ), __( 'Upload the font\'s woff file or enter the URL.', 'custom-fonts' ) );
231
+ $this->font_file_new_field( 'font_ttf-0', __( 'Font .ttf', 'custom-fonts' ), __( 'Upload the font\'s ttf file or enter the URL.', 'custom-fonts' ) );
232
+ $this->font_file_new_field( 'font_eot-0', __( 'Font .eot', 'custom-fonts' ), __( 'Upload the font\'s eot file or enter the URL.', 'custom-fonts' ) );
233
+ $this->font_file_new_field( 'font_svg-0', __( 'Font .svg', 'custom-fonts' ), __( 'Upload the font\'s svg file or enter the URL.', 'custom-fonts' ) );
234
+ $this->font_file_new_field( 'font_otf-0', __( 'Font .otf', 'custom-fonts' ), __( 'Upload the font\'s otf file or enter the URL.', 'custom-fonts' ) );
235
+ }
236
+
237
+ /**
238
+ * Edit taxonomy data.
239
+ *
240
+ * @param object $term Term data.
241
+ */
242
+ public function edit_new_taxonomy_data( $term ) {
243
+
244
+ $data = Bsf_Custom_Fonts_Taxonomy::get_font_links( $term->term_id );
245
+ $this->edit_new_taxonomy_default_data( $term );
246
+ ?>
247
+ <tr>
248
+ <th></th>
249
+ <td>
250
+ <div id="repeater">
251
+ <!-- Repeater Heading -->
252
+ <div class="clearfix"></div>
253
+ <!-- Repeater Items -->
254
+ <?php foreach ( $data as $key => $value ) { ?>
255
+ <?php $this->edit_taxonomy_repeater_data( $key, $value ); ?>
256
+ <?php } ?>
257
+ <input type="hidden" name="repeater-field-count" value="<?php echo esc_attr( self::$edit_repeater_field_count ); ?>">
258
+ <?php wp_nonce_field( basename( __FILE__ ), 'bsf_custom_font_nonce' ); ?>
259
+ </div>
260
+ <div class="cf-addbutton-wrapper">
261
+ <div class="button button-primary edit-repeater-add-btn">
262
+ Add Font Variation
263
+ </div>
264
+ </div>
265
+ </td>
266
+ </tr>
267
+ <?php
268
+
269
+ }
270
+
271
  /**
272
  * Edit Taxonomy data
273
  *
274
  * @since 1.0.0
275
  * @param object $term taxonomy terms.
276
  */
277
+ public function edit_new_taxonomy_default_data( $term ) {
 
278
  $data = Bsf_Custom_Fonts_Taxonomy::get_font_links( $term->term_id );
279
+ $this->font_edit_field( 'font_fallback', __( 'Font Fallback', 'custom-fonts' ), __( 'Add the font\'s fallback names with comma(,) separator. eg. Arial, Serif', 'custom-fonts' ), $data['font_fallback'] );
280
+
281
+ $this->select_default_edit_field(
 
 
 
 
 
282
  'font-display',
283
  __( 'Font Display', 'custom-fonts' ),
 
284
  __( 'Select font-display property for this font', 'custom-fonts' ),
285
  array(
286
  'auto' => 'Auto',
288
  'swap' => 'Swap',
289
  'fallback' => 'Fallback',
290
  'optional' => 'Optional',
291
+ ),
292
+ $data['font-display']
293
  );
294
+
295
+ }
296
+
297
+ /**
298
+ * Edit Taxonomy data
299
+ *
300
+ * @since x.x.x
301
+ * @param string $key Font array repeater fields key.
302
+ * @param string $value Font array repeater fields value.
303
+ */
304
+ public function edit_taxonomy_repeater_data( $key, $value ) {
305
+ if ( strpos( $key, 'font-weight' ) !== false ) {
306
+ ?>
307
+ <div id="<?php echo esc_attr( 'item-' . self::$edit_repeater_field_count ); ?>" class="cf-bsf-items" data-group="font-weight-type">
308
+ <!-- Repeater Content -->
309
+ <div class="item-content">
310
+ <div class="form-group">
311
+ <?php
312
+ $this->select_new_field(
313
+ $key,
314
+ __( 'Font weight', 'custom-fonts' ),
315
+ __( 'Select font-weight property for this font', 'custom-fonts' ),
316
+ array(
317
+ '100' => __( 'Thin 100', 'custom-fonts' ),
318
+ '200' => __( 'Extra-Light 200', 'custom-fonts' ),
319
+ '300' => __( 'Light 300', 'custom-fonts' ),
320
+ '400' => __( 'Normal 400', 'custom-fonts' ),
321
+ '500' => __( 'Medium 500', 'custom-fonts' ),
322
+ '600' => __( 'Semi-Bold 600', 'custom-fonts' ),
323
+ '700' => __( 'Bold 700', 'custom-fonts' ),
324
+ '800' => __( 'Extra-Bold 800', 'custom-fonts' ),
325
+ '900' => __( 'Ultra-Bold 900', 'custom-fonts' ),
326
+
327
+ ),
328
+ $value
329
+ );
330
+ self::$edit_repeater_field_count++;
331
+ } elseif ( strpos( $key, 'font_woff_2-' ) !== false ) {
332
+ $this->font_file_edit_field( 'font_woff_2', __( 'Font .woff2', 'custom-fonts' ), __( 'Upload the font\'s woff2 file or enter the URL.', 'custom-fonts' ), $value, $key );
333
+ } elseif ( strpos( $key, 'font_woff-' ) !== false ) {
334
+ $this->font_file_edit_field( 'font_woff', __( 'Font .woff', 'custom-fonts' ), __( 'Upload the font\'s woff file or enter the URL.', 'custom-fonts' ), $value, $key );
335
+ } elseif ( strpos( $key, 'font_ttf' ) !== false ) {
336
+ $this->font_file_edit_field( 'font_ttf', __( 'Font .ttf', 'custom-fonts' ), __( 'Upload the font\'s ttf file or enter the URL.', 'custom-fonts' ), $value, $key );
337
+ } elseif ( strpos( $key, 'font_eot' ) !== false ) {
338
+ $this->font_file_edit_field( 'font_eot', __( 'Font .eot', 'custom-fonts' ), __( 'Upload the font\'s eot file or enter the URL.', 'custom-fonts' ), $value, $key );
339
+ } elseif ( strpos( $key, 'font_svg' ) !== false ) {
340
+ $this->font_file_edit_field( 'font_svg', __( 'Font .svg', 'custom-fonts' ), __( 'Upload the font\'s svg file or enter the URL.', 'custom-fonts' ), $value, $key );
341
+ } elseif ( strpos( $key, 'font_otf' ) !== false ) {
342
+ $this->font_file_edit_field( 'font_otf', __( 'Font .otf', 'custom-fonts' ), __( 'Upload the font\'s otf file or enter the URL.', 'custom-fonts' ), $value, $key );
343
+ ?>
344
+
345
+ </div>
346
+ </div>
347
+ <!-- Repeater Remove Btn -->
348
+ <div class="repeater-remove-btn">
349
+ <div class="button button-primary remove-btn <?php echo esc_attr( 1 < self::$edit_repeater_field_count ? '' : 'disabled' ); ?>">
350
+ Remove
351
+ </div>
352
+ </div>
353
+ <div class="clearfix"></div>
354
+ </div>
355
+ <?php
356
+ } else {
357
+ return;
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Add font fallback field
363
+ *
364
+ * @since x.x.x
365
+ * @param int $id current term id.
366
+ * @param string $title font type title.
367
+ * @param string $description title font type description.
368
+ * @param string $value title font type meta values.
369
+ */
370
+ protected function font_new_field( $id, $title, $description, $value = '' ) {
371
+ ?>
372
+ <div class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap" >
373
+
374
+ <label for="font-<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $title ); ?></label>
375
+ <input type="text" id="font-<?php echo esc_attr( $id ); ?>" class="bsf-custom-fonts-link <?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug ); ?>[<?php echo esc_attr( $id ); ?>]" value="<?php echo esc_attr( $value ); ?>" />
376
+ <p><?php echo esc_html( $description ); ?></p>
377
+ </div>
378
+ <?php
379
  }
380
 
381
  /**
392
  <div class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap" >
393
 
394
  <label for="font-<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $title ); ?></label>
395
+ <input type="text" id="font-<?php echo esc_attr( $id ); ?>" class="bsf-custom-fonts-link <?php echo esc_attr( $id ); ?>" data-name="<?php echo '[' . esc_attr( $id ) . ']'; ?>" name="bsf_custom_fonts<?php echo '[' . esc_attr( $id ) . ']'; ?>" value="<?php echo esc_attr( $value ); ?>" />
396
  <a href="#" class="bsf-custom-fonts-upload button" data-upload-type="<?php echo esc_attr( $id ); ?>"><?php esc_html_e( 'Upload', 'custom-fonts' ); ?></a>
397
  <p><?php echo esc_html( $description ); ?></p>
398
  </div>
408
  * @param Array $select_fields Select fields as Array.
409
  * @return void
410
  */
411
+ protected function select_default_new_field( $id, $title, $description, $select_fields ) {
412
  ?>
413
  <div class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap" >
414
  <label for="font-<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $title ); ?></label>
423
  <?php
424
  }
425
 
426
+ /**
427
+ * Select default repeater edit field.
428
+ *
429
+ * @since x.x.x
430
+ *
431
+ * @param string $id Id of the field.
432
+ * @param string $title Title of the field.
433
+ * @param string $description Description of the field.
434
+ * @param array $select_fields Select - all options array.
435
+ * @param string $selected Key for selected field.
436
+ */
437
+ protected function select_default_edit_field( $id, $title, $description, $select_fields, $selected ) {
438
+ ?>
439
+ <tr class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap" >
440
+ <th><label for="font-<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $title ); ?></label></th>
441
+ <td>
442
+ <select type="select" id="font-<?php echo esc_attr( $id ); ?>" class="bsf-custom-font-select-field <?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug ); ?>[<?php echo esc_attr( $id ); ?>]" />
443
+ <?php
444
+ foreach ( $select_fields as $key => $value ) {
445
+ ?>
446
+ <option value="<?php echo esc_attr( $key ); ?>" <?php echo ( $key == $selected ) ? ' selected="selected"' : ''; ?> ><?php echo esc_html( $value ); ?></option>;
447
+ <?php } ?>
448
+ </select>
449
+ <td>
450
+ </tr>
451
+ <?php
452
+ }
453
+
454
+ /**
455
+ * Render select field for the new font screen.
456
+ *
457
+ * @param string $id Field ID.
458
+ * @param string $title Field Title.
459
+ * @param string $description Field Description.
460
+ * @param array $select_fields Select fields as Array.
461
+ * @param string $selected_value Selected field.
462
+ * @return void
463
+ */
464
+ protected function select_new_field( $id, $title, $description, $select_fields, $selected_value = '' ) {
465
+ ?>
466
+ <div class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap" >
467
+ <label for="font-<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $title ); ?></label>
468
+ <select type="select" id="font-<?php echo esc_attr( $id ); ?>" class="bsf-custom-font-select-field <?php echo esc_attr( $id ); ?>" data-name="<?php echo '[' . esc_attr( $id ) . ']'; ?>" name="bsf_custom_fonts<?php echo '[' . esc_attr( $id ) . ']'; ?>" />
469
+ <?php
470
+ foreach ( $select_fields as $key => $value ) {
471
+ ?>
472
+ <option value="<?php echo esc_attr( $key ); ?>" <?php echo $selected_value == $key ? 'selected="selected"' : ''; ?>><?php echo esc_html( $value ); ?></option>
473
+ <?php } ?>
474
+ </select>
475
+ </div>
476
+ <?php
477
+ }
478
+
479
  /**
480
  * Render select field for the edit font screen.
481
  *
482
  * @param String $id Field ID.
483
  * @param String $title Field Title.
 
484
  * @param String $description Field Description.
485
  * @param Array $select_fields Select fields as Array.
486
+ * @param String $saved_val Field Value.
487
  * @return void
488
  */
489
+ private function select_edit_field( $id, $title, $description, $select_fields, $saved_val = '' ) {
490
  ?>
491
  <tr class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap ">
492
  <th scope="row">
514
  * @since 1.0.0
515
  * @param int $id current term id.
516
  * @param string $title font type title.
 
517
  * @param string $description title font type description.
518
+ * @param string $value title font type meta values.
519
  */
520
+ protected function font_edit_field( $id, $title, $description, $value = '' ) {
521
  ?>
522
  <tr class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap ">
523
  <th scope="row">
527
  </th>
528
  <td>
529
  <input id="metadata-<?php echo esc_attr( $id ); ?>" type="text" class="bsf-custom-fonts-link <?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug ); ?>[<?php echo esc_attr( $id ); ?>]" value="<?php echo esc_attr( $value ); ?>" />
 
530
  <p><?php echo esc_html( $description ); ?></p>
531
  </td>
532
  </tr>
533
  <?php
534
  }
535
 
536
+ /**
537
+ * Add Taxonomy data field
538
+ *
539
+ * @since x.x.x
540
+ * @param int $id current term id.
541
+ * @param string $title font type title.
542
+ * @param string $description title font type description.
543
+ * @param string $value title font type meta values.
544
+ * @param string $key key as the part of name of the fields.
545
+ */
546
+ protected function font_file_edit_field( $id, $title, $description, $value, $key ) {
547
+ ?>
548
+ <div class="bsf-custom-fonts-file-wrap form-field term-<?php echo esc_attr( $id ); ?>-wrap ">
549
+ <div scope="row">
550
+ <label for="metadata-<?php echo esc_attr( $id ); ?>">
551
+ <?php echo esc_html( $title ); ?>
552
+ </label>
553
+ </div>
554
+ <div>
555
+ <input id="metadata-<?php echo esc_attr( $id ); ?>" type="text" class="bsf-custom-fonts-link <?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug ); ?>[<?php echo esc_attr( $key ); ?>]" value="<?php echo esc_attr( $value ); ?>" />
556
+ <a href="#" class="bsf-custom-fonts-upload button" data-upload-type="<?php echo esc_attr( $id ); ?>"><?php esc_html_e( 'Upload', 'custom-fonts' ); ?></a>
557
+ <p><?php echo esc_html( $description ); ?></p>
558
+ </div>
559
+ </div>
560
+ <?php
561
+ }
562
+
563
  /**
564
  * Save Taxonomy meta data value
565
  *
567
  * @param int $term_id current term id.
568
  */
569
  public function save_metadata( $term_id ) {
570
+ // Verify the nonce for both Add and Edit font save data.
571
+ if ( ! isset( $_POST['bsf_custom_font_nonce'] ) || ! wp_verify_nonce( $_POST['bsf_custom_font_nonce'], basename( __FILE__ ) ) ) {
572
  return;
573
  }
574
 
575
+ if ( isset( $_POST[ Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug ] ) ) {
576
+ $value = $_POST[ Bsf_Custom_Fonts_Taxonomy::$register_taxonomy_slug ];
577
  Bsf_Custom_Fonts_Taxonomy::update_font_links( $value, $term_id );
578
  }
579
  }
622
 
623
  }
624
 
 
 
625
  /**
626
  * Kicking this off by calling 'get_instance()' method
627
  */
includes/class-bsf-custom-fonts-taxonomy.php CHANGED
@@ -92,6 +92,7 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Taxonomy' ) ) :
92
  'add_new_item' => __( 'Add New Font', 'custom-fonts' ),
93
  'new_item_name' => __( 'New Font Name', 'custom-fonts' ),
94
  'not_found' => __( 'No fonts found', 'custom-fonts' ),
 
95
  );
96
 
97
  $args = array(
@@ -122,13 +123,18 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Taxonomy' ) ) :
122
  return wp_parse_args(
123
  $fonts,
124
  array(
125
- 'font_woff_2' => '',
126
- 'font_woff' => '',
127
- 'font_ttf' => '',
128
- 'font_svg' => '',
129
- 'font_eot' => '',
130
- 'font_otf' => '',
131
- 'font-display' => 'swap',
 
 
 
 
 
132
  )
133
  );
134
  }
@@ -198,7 +204,7 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Taxonomy' ) ) :
198
  */
199
  public static function get_font_links( $term_id ) {
200
  $links = get_option( 'taxonomy_' . self::$register_taxonomy_slug . "_{$term_id}", array() );
201
- return self::default_args( $links );
202
  }
203
 
204
  /**
@@ -209,15 +215,8 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Taxonomy' ) ) :
209
  * @param int $term_id custom font term id.
210
  */
211
  public static function update_font_links( $posted, $term_id ) {
212
-
213
  $links = self::get_font_links( $term_id );
214
- foreach ( array_keys( $links ) as $key ) {
215
- if ( isset( $posted[ $key ] ) ) {
216
- $links[ $key ] = $posted[ $key ];
217
- } else {
218
- $links[ $key ] = '';
219
- }
220
- }
221
  update_option( 'taxonomy_' . self::$register_taxonomy_slug . "_{$term_id}", $links );
222
  }
223
 
92
  'add_new_item' => __( 'Add New Font', 'custom-fonts' ),
93
  'new_item_name' => __( 'New Font Name', 'custom-fonts' ),
94
  'not_found' => __( 'No fonts found', 'custom-fonts' ),
95
+ 'back_to_items' => __( '← Go to Fonts', 'custom-fonts' ),
96
  );
97
 
98
  $args = array(
123
  return wp_parse_args(
124
  $fonts,
125
  array(
126
+ 'font_fallback' => '',
127
+ 'font-display' => 'swap',
128
+ 'repeater_fields' => array(
129
+ '400' => array(
130
+ 'font_woff_2' => '',
131
+ 'font_woff' => '',
132
+ 'font_ttf' => '',
133
+ 'font_svg' => '',
134
+ 'font_eot' => '',
135
+ 'font_otf' => '',
136
+ ),
137
+ ),
138
  )
139
  );
140
  }
204
  */
205
  public static function get_font_links( $term_id ) {
206
  $links = get_option( 'taxonomy_' . self::$register_taxonomy_slug . "_{$term_id}", array() );
207
+ return $links;
208
  }
209
 
210
  /**
215
  * @param int $term_id custom font term id.
216
  */
217
  public static function update_font_links( $posted, $term_id ) {
 
218
  $links = self::get_font_links( $term_id );
219
+ $links = $posted;
 
 
 
 
 
 
220
  update_option( 'taxonomy_' . self::$register_taxonomy_slug . "_{$term_id}", $links );
221
  }
222
 
includes/plugin-update/class-custom-fonts-update.php CHANGED
@@ -71,6 +71,10 @@ class Custom_Fonts_Update {
71
  $this->v_1_2_5();
72
  }
73
 
 
 
 
 
74
  $this->update_db_version();
75
 
76
  do_action( 'custom_fonts_update_after' );
@@ -102,6 +106,40 @@ class Custom_Fonts_Update {
102
 
103
  }
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  /**
106
  * Check if db upgrade is required.
107
  *
71
  $this->v_1_2_5();
72
  }
73
 
74
+ if ( version_compare( $db_version, '1.2.6', '<=' ) ) {
75
+ $this->v_1_3_0();
76
+ }
77
+
78
  $this->update_db_version();
79
 
80
  do_action( 'custom_fonts_update_after' );
106
 
107
  }
108
 
109
+ /**
110
+ * Update the font array according to new font weight repeater fields.
111
+ *
112
+ * @since x.x.x
113
+ */
114
+ public function v_1_3_0() {
115
+
116
+ $terms = get_terms(
117
+ 'bsf_custom_fonts',
118
+ array(
119
+ 'hide_empty' => false,
120
+ )
121
+ );
122
+
123
+ if ( ! empty( $terms ) ) {
124
+ foreach ( $terms as $term ) {
125
+ $font_links = Bsf_Custom_Fonts_Taxonomy::get_font_links( $term->term_id );
126
+
127
+ $new_font_arr = array();
128
+ $new_font_arr['font_fallback'] = '';
129
+ $new_font_arr['font-display'] = isset( $font_links['font-display'] ) ? $font_links['font-display'] : '';
130
+ $new_font_arr['font-weight-0'] = '400';
131
+ $new_font_arr['font_woff_2-0'] = isset( $font_links['font_woff_2'] ) ? $font_links['font_woff_2'] : '';
132
+ $new_font_arr['font_woff-0'] = isset( $font_links['font_woff'] ) ? $font_links['font_woff'] : '';
133
+ $new_font_arr['font_ttf-0'] = isset( $font_links['font_ttf'] ) ? $font_links['font_ttf'] : '';
134
+ $new_font_arr['font_eot-0'] = isset( $font_links['font_eot'] ) ? $font_links['font_eot'] : '';
135
+ $new_font_arr['font_svg-0'] = isset( $font_links['font_svg'] ) ? $font_links['font_svg'] : '';
136
+ $new_font_arr['font_otf-0'] = isset( $font_links['font_otf'] ) ? $font_links['font_otf'] : '';
137
+
138
+ Bsf_Custom_Fonts_Taxonomy::update_font_links( $new_font_arr, $term->term_id );
139
+ }
140
+ }
141
+ }
142
+
143
  /**
144
  * Check if db upgrade is required.
145
  *
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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.7
7
- Stable tag: 1.2.6
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
  = 1.2.6 =
47
  - Improvement: PHP 8.0 compatibility.
48
 
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.7
7
+ Stable tag: 1.3.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.3.0 =
47
+ - New: Add multiple font weight to the Custom Fonts.
48
+
49
  = 1.2.6 =
50
  - Improvement: PHP 8.0 compatibility.
51