Better Font Awesome - Version 1.0.5

Version Description

  • Add fa_force_fallback and bfa_show_errors filters.
  • Add hex icon values as $icon array indexes.
Download this release

Release Info

Developer McGuive7
Plugin Icon 128x128 Better Font Awesome
Version 1.0.5
Comparing to
See all releases

Code changes from version 1.0.4 to 1.0.5

better-font-awesome.php CHANGED
@@ -12,7 +12,7 @@
12
  * Plugin Name: Better Font Awesome
13
  * Plugin URI: http://wordpress.org/plugins/better-font-awesome
14
  * Description: The ultimate Font Awesome icon plugin for WordPress.
15
- * Version: 1.0.4
16
  * Author: MIGHTYminnow & Mickey Kay
17
  * Author URI: mickey@mickeykaycreative.com
18
  * License: GPLv2+
12
  * Plugin Name: Better Font Awesome
13
  * Plugin URI: http://wordpress.org/plugins/better-font-awesome
14
  * Description: The ultimate Font Awesome icon plugin for WordPress.
15
+ * Version: 1.0.5
16
  * Author: MIGHTYminnow & Mickey Kay
17
  * Author URI: mickey@mickeykaycreative.com
18
  * License: GPLv2+
lib/better-font-awesome-library/better-font-awesome-library.php CHANGED
@@ -287,7 +287,7 @@ class Better_Font_Awesome_Library {
287
  // Load TinyMCE functionality.
288
  if ( $this->args['load_tinymce_plugin'] ) {
289
 
290
- add_action( 'admin_head', array( $this, 'add_tinymce_components' ) );
291
  add_action( 'admin_head', array( $this, 'output_admin_head_variables' ) );
292
  add_action( 'admin_enqueue_scripts', array( $this, 'register_custom_admin_css' ), 15 );
293
 
@@ -577,15 +577,26 @@ class Better_Font_Awesome_Library {
577
  $response = $this->get_remote_css( $url, $version );
578
  }
579
 
 
 
 
 
 
 
 
 
 
580
  /**
581
  * Use the local fallback if both the transient and wp_remote_get()
582
- * methods fail.
583
  */
584
- if ( is_wp_error( $response ) ) {
585
 
586
  // Log the CSS fetch error.
587
- $this->set_error( 'css', $response->get_error_code(), $response->get_error_message() . " (URL: $url)" );
588
-
 
 
589
  // Use the local fallback CSS.
590
  $response = $this->fallback_data['css'];
591
 
@@ -711,23 +722,21 @@ class Better_Font_Awesome_Library {
711
  private function setup_icon_array( $css ) {
712
 
713
  $icons = array();
 
714
 
715
- // Get all CSS selectors that have a "content:" pseudo-element rule.
716
- preg_match_all( '/(\.[^}]*)\s*{\s*(content:)/s', $css, $matches );
717
- $selectors = $matches[1];
718
-
719
- // Select for all icon- and fa- selectors and split where there are commas.
720
- foreach ( $selectors as $selector ) {
721
- preg_match_all( '/\.(icon-|fa-)([^,]*)\s*:before/s', $selector, $matches );
722
- $clean_selectors = $matches[2];
723
 
724
- // Create an array of selectors (icon names).
725
- foreach ( $clean_selectors as $clean_selector )
726
- $icons[] = $clean_selector;
727
- }
728
 
729
- // Alphabetize the icons array.
730
- sort( $icons );
731
 
732
  /**
733
  * Filter the array of available icons.
@@ -1014,7 +1023,7 @@ class Better_Font_Awesome_Library {
1014
  */
1015
  public function do_admin_notice() {
1016
 
1017
- if ( ! empty( $this->errors ) ) :
1018
  ?>
1019
  <div class="error">
1020
  <p>
287
  // Load TinyMCE functionality.
288
  if ( $this->args['load_tinymce_plugin'] ) {
289
 
290
+ add_action( 'admin_init', array( $this, 'add_tinymce_components' ) );
291
  add_action( 'admin_head', array( $this, 'output_admin_head_variables' ) );
292
  add_action( 'admin_enqueue_scripts', array( $this, 'register_custom_admin_css' ), 15 );
293
 
577
  $response = $this->get_remote_css( $url, $version );
578
  }
579
 
580
+ /**
581
+ * Filter the force fallback flag.
582
+ *
583
+ * @since 1.0.4
584
+ *
585
+ * @param bool Whether or not to force the fallback CSS.
586
+ */
587
+ $force_fallback = apply_filters( 'bfa_force_fallback', false );
588
+
589
  /**
590
  * Use the local fallback if both the transient and wp_remote_get()
591
+ * methods fail, or if fallback is forced with bfa_force_fallback filter.
592
  */
593
+ if ( is_wp_error( $response ) || $force_fallback ) {
594
 
595
  // Log the CSS fetch error.
596
+ if ( ! $force_fallback ) {
597
+ $this->set_error( 'css', $response->get_error_code(), $response->get_error_message() . " (URL: $url)" );
598
+ }
599
+
600
  // Use the local fallback CSS.
601
  $response = $this->fallback_data['css'];
602
 
722
  private function setup_icon_array( $css ) {
723
 
724
  $icons = array();
725
+ $hex_codes = array();
726
 
727
+ /**
728
+ * Get all CSS selectors that have a "content:" pseudo-element rule,
729
+ * as well as all associated hex codes.
730
+ */
731
+ preg_match_all( '/\.(icon-|fa-)([^,}]*)\s*:before\s*{\s*(content:)\s*"(\\\\[^"]+)"/s', $css, $matches );
732
+ $icons = $matches[2];
733
+ $hex_codes = $matches[4];
 
734
 
735
+ // Add hex codes as icon array index.
736
+ $icons = array_combine( $hex_codes, $icons );
 
 
737
 
738
+ // Alphabetize the icons array by icon name.
739
+ asort( $icons );
740
 
741
  /**
742
  * Filter the array of available icons.
1023
  */
1024
  public function do_admin_notice() {
1025
 
1026
+ if ( ! empty( $this->errors ) && apply_filters( 'bfa_show_errors', true ) ) :
1027
  ?>
1028
  <div class="error">
1029
  <p>
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: McGuive7, MIGHTYminnow
3
  Tags: better, font, awesome, icon, icons, bootstrap, fontstrap, cdn, shortcode
4
  Donate link: http://mightyminnow.com
5
  Requires at least: 3.0
6
- Tested up to: 4.0
7
- Stable tag: 1.0.3
8
  License: GPLv2+
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -108,6 +108,13 @@ Better Font Awesome does it's best to load after any existing Font Awesome CSS,
108
 
109
  == Changelog ==
110
 
 
 
 
 
 
 
 
111
  = 1.0.3 =
112
  * Add French translation.
113
  * Correct text domain slug.
@@ -155,6 +162,13 @@ Better Font Awesome does it's best to load after any existing Font Awesome CSS,
155
 
156
  == Upgrade Notice ==
157
 
 
 
 
 
 
 
 
158
  = 1.0.3 =
159
  * Add French translation.
160
  * Correct text domain slug.
3
  Tags: better, font, awesome, icon, icons, bootstrap, fontstrap, cdn, shortcode
4
  Donate link: http://mightyminnow.com
5
  Requires at least: 3.0
6
+ Tested up to: 4.1
7
+ Stable tag: 1.0.5
8
  License: GPLv2+
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
108
 
109
  == Changelog ==
110
 
111
+ = 1.0.5 =
112
+ * Add fa_force_fallback and bfa_show_errors filters.
113
+ * Add hex icon values as $icon array indexes.
114
+
115
+ = 1.0.4 =
116
+ * Add missing isset() check that was causing intermittent warning.
117
+
118
  = 1.0.3 =
119
  * Add French translation.
120
  * Correct text domain slug.
162
 
163
  == Upgrade Notice ==
164
 
165
+ = 1.0.5 =
166
+ * Add fa_force_fallback and bfa_show_errors filters.
167
+ * Add hex icon values as $icon array indexes.
168
+
169
+ = 1.0.4 =
170
+ * Add missing isset() check that was causing intermittent warning.
171
+
172
  = 1.0.3 =
173
  * Add French translation.
174
  * Correct text domain slug.