Skip to content

Commit

Permalink
Merge pull request #7 from kprajapatii/master
Browse files Browse the repository at this point in the history
1.1.1
  • Loading branch information
kprajapatii authored Nov 2, 2022
2 parents e092fe1 + ab6ac30 commit dab8a00
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ayecode/wp-font-awesome-settings",
"version": "1.1.0",
"version": "1.1.1",
"type": "library",
"description": "Settings page for Font Awesome in WordPress",
"keywords": ["font-awesome","fontawesome"],
Expand Down
37 changes: 33 additions & 4 deletions wp-font-awesome-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed.
* @since 1.0.15 Font Awesome will now load in the FSE if enable din the backend.
* @since 1.1.0 Option added to load FontAwesome locally.
* @since 1.1.1 Requires to re-save settings to load locally when option does not exists - FIXED.
* @ver 1.0.15
* @todo decide how to implement textdomain
*/
Expand All @@ -42,7 +43,7 @@ class WP_Font_Awesome_Settings {
*
* @var string
*/
public $version = '1.0.15';
public $version = '1.1.1';

/**
* Class textdomain.
Expand Down Expand Up @@ -115,6 +116,7 @@ public static function instance() {
*/
public function init() {
// Download fontawesome locally.
add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );

$this->settings = $this->get_settings();
Expand Down Expand Up @@ -671,7 +673,34 @@ public function admin_notices() {
}

/**
* Handle fontawesome save settings to download fontawesome to store locally.
* Handle fontawesome add settings to download fontawesome to store locally.
*
* @since 1.1.1
*
* @param string $option The option name.
* @param mixed $value The option value.
*/
public function add_option_wp_font_awesome_settings( $option, $value ) {
// Do nothing if WordPress is being installed.
if ( wp_installing() ) {
return;
}

if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
$version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();

if ( ! empty( $version ) ) {
$response = $this->download_package( $version, $value );

if ( is_wp_error( $response ) ) {
add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
}
}
}
}

/**
* Handle fontawesome update settings to download fontawesome to store locally.
*
* @since 1.1.0
*
Expand All @@ -684,15 +713,15 @@ public function update_option_wp_font_awesome_settings( $old_value, $new_value )
return;
}

if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) ) {
if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
// Old values
$old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
$old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;

// New values
$new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();

if ( empty( $old_local ) || $old_version !== $new_version ) {
if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
$response = $this->download_package( $new_version, $new_value );

if ( is_wp_error( $response ) ) {
Expand Down

0 comments on commit dab8a00

Please sign in to comment.