Skip to content

Instantly share code, notes, and snippets.

@Stiofan
Last active January 18, 2019 17:39
Show Gist options
  • Save Stiofan/53681e80adb4e421a46eb03cd510ae38 to your computer and use it in GitHub Desktop.
Save Stiofan/53681e80adb4e421a46eb03cd510ae38 to your computer and use it in GitHub Desktop.
Build Font awesome associative array
<?php
require_once( dirname( __FILE__ ) . '/wp-load.php' ); // get WP
$result = wp_remote_get( "https://fontawesome.com/cheatsheet" );
$out = $result['body'];
$start = "window.__inline_data__ = "; // start here
$end = "</script>";
$startsAt = strpos( $out, $start ) + strlen( $start );
$endsAt = strpos( $out, $end, $startsAt );
$result = substr( $out, $startsAt, $endsAt - $startsAt );
$result = json_decode( $result );
$icons = array();
foreach ( $result[2]->data as $data ) {
if ( $data->type == 'icon' ) {
// skip pro only icons
if ( empty( $data->attributes->membership->free ) ) {
continue;
}
$types = $data->attributes->membership->free;
foreach ( $types as $type ) {
$prefix = '';
if ( $type == 'brands' ) {
$prefix = 'fab ';
} elseif ( $type == 'solid' ) {
$prefix = 'fas ';
} elseif ( $type == 'regular' ) {
$prefix = 'far ';
} elseif ( $type == 'light' ) {
$prefix = 'fal ';
}
$icons[ $prefix . "fa-" . $data->id ] = $data->attributes->unicode ;
}
}
}
// output it for a nice copy/pase
echo "array( \n";
foreach($icons as $class=>$unicode){
echo "'".$class."' => '".$unicode."', \n";
}
echo ");";
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment