Skip to content

Commit

Permalink
Merge pull request #89 from pressidium/next
Browse files Browse the repository at this point in the history
1.5.2
  • Loading branch information
over-engineer authored Sep 7, 2024
2 parents 5ca55ef + c940353 commit 0b4749a
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 8 deletions.
4 changes: 2 additions & 2 deletions includes/Client/Cookie_Consent.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ private function print_inline_style(): void {
<style id="pressidium-cc-styles">
.pressidium-cc-theme {
<?php
$font_slug = $this->settings['pressidium_options']['font']['slug'];
$font_family = $this->settings['pressidium_options']['font']['family'];
$font_slug = $this->settings['pressidium_options']['font']['slug'] ?? 'default';
$font_family = $this->settings['pressidium_options']['font']['family'] ?? 'inherit';

if ( $font_slug !== 'default' ) {
echo "--cc-font-family: {$font_family};\n";
Expand Down
9 changes: 9 additions & 0 deletions includes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,18 @@ public function init(): void {
$settings = new Settings( $options );
$container->add( 'settings', $settings );

$upgrader = new Upgrader( $this->logger, $settings );
$container->add( 'upgrader', $upgrader );

$this->add_service_providers( $container );
$this->register_tables( $database_manager, $container );
$this->register_hooks( $hooks_manager, $container );

/*
* Run the upgrader on every request to check if the plugin was upgraded
* and if so, migrate the settings to the latest version and resave them.
*/
$upgrader->maybe_upgrade();
}

}
125 changes: 125 additions & 0 deletions includes/Upgrader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php
/**
* Upgrader.
*
* @author Konstantinos Pappas <[email protected]>
* @copyright 2024 Pressidium
*/

namespace Pressidium\WP\CookieConsent;

use const Pressidium\WP\CookieConsent\VERSION;

use Pressidium\WP\CookieConsent\Logging\Logger;

if ( ! defined( 'ABSPATH' ) ) {
die( 'Forbidden' );
}

/**
* Upgrader class.
*
* @since 1.5.2
*/
class Upgrader {

/**
* @var Logger Logger object.
*/
private Logger $logger;

/**
* @var Settings Settings object.
*/
private Settings $settings;

/**
* Upgrader constructor.
*
* @param Logger $logger Logger object.
* @param Settings $settings Settings object.
*/
public function __construct( Logger $logger, Settings $settings ) {
$this->logger = $logger;
$this->settings = $settings;
}

/**
* Whether the plugin was just upgraded.
*
* @param array $settings Settings to check against.
*
* @return bool
*/
public function did_just_upgrade( array $settings ): bool {
if ( ! isset( $settings['version'] ) ) {
return false;
}

if ( ! defined( 'Pressidium\WP\CookieConsent\VERSION' ) ) {
return false;
}

return version_compare( $settings['version'], VERSION, '<' );
}

/**
* Migrate the given settings to the latest version.
*
* @param array $settings Settings to migrate.
*
* @return array
*/
private function maybe_migrate( array $settings ): array {
$migrator = new Migrator( $settings );
$migrated_settings = $migrator->maybe_migrate();

return $migrated_settings;
}

/**
* Maybe upgrade.
*
* @return void
*/
public function maybe_upgrade(): void {
if ( ! is_admin() ) {
// We only run the upgrader in the admin area, bail early
return;
}

$settings = Emoji::decode_array( $this->settings->get() );

if ( ! $this->did_just_upgrade( $settings ) ) {
// Plugin was not just upgraded, bail early
return;
}

$old_version = $settings['version'];

$settings = $this->maybe_migrate( $settings );
$settings['version'] = VERSION;

$set_successfully = $this->settings->set( $settings );

if ( ! $set_successfully ) {
$this->logger->error(
sprintf(
'Could not save settings after upgrade from version %s to %s.',
$old_version,
VERSION
)
);
return;
}

$this->logger->info(
sprintf(
'Successfully upgraded from version %s to %s.',
$old_version,
VERSION
)
);
}

}
4 changes: 2 additions & 2 deletions pressidium-cookie-consent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Pressidium Cookie Consent
* Plugin URI: https://github.com/pressidium/pressidium-cookie-consent/
* Description: Lightweight, user-friendly and customizable cookie consent banner to help you comply with the EU GDPR cookie law and CCPA regulations.
* Version: 1.5.1
* Version: 1.5.2
* Author: Pressidium
* Author URI: https://pressidium.com/
* Text Domain: pressidium-cookie-consent
Expand All @@ -27,7 +27,7 @@
*/
function setup_constants(): void {
if ( ! defined( 'Pressidium\WP\CookieConsent\VERSION' ) ) {
define( 'Pressidium\WP\CookieConsent\VERSION', '1.5.1' );
define( 'Pressidium\WP\CookieConsent\VERSION', '1.5.2' );
}

if ( ! defined( 'Pressidium\WP\CookieConsent\PLUGIN_DIR' ) ) {
Expand Down
12 changes: 8 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Tags: cookie, consent, gdpr, ccpa, cookies
Requires at least: 6.0
Tested up to: 6.6
Requires PHP: 7.4
Stable Tag: 1.5.1
Stable Tag: 1.5.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -173,7 +173,11 @@ If you have spotted any bugs, or would like to request additional features from

== Changelog ==

= 1.5.1: Aug 5, 2023 =
= 1.5.2: Sep 7, 2024 =

* Fix an issue where settings didn't automatically migrate from the previous version, requiring users to manually save them

= 1.5.1: Aug 5, 2024 =

* Add a notice to warn users for potential issues with specific configurations
* Add more information to the logs to help with debugging
Expand All @@ -186,7 +190,7 @@ If you have spotted any bugs, or would like to request additional features from
* Fix an issue where the consent records table was not being created
* Fix an issue where the consent records table schema was not being updated correctly

= 1.5.0: Jul 30, 2023 =
= 1.5.0: Jul 30, 2024 =

* Add a “Font” option to select one of the fonts that you have installed via the Font Library (WordPress 6.5+)
* Add a new “Hide empty categories” option to hide a category if it has no cookies
Expand All @@ -196,7 +200,7 @@ If you have spotted any bugs, or would like to request additional features from
* Merged the “Consent Modal” and “Settings Modal” tabs into a single “Modals” tab to keep the settings page a bit more organized
* Tabs panel in the settings page is now responsive and will scroll horizontally on smaller screens

= 1.4.0: Mar 21, 2023 =
= 1.4.0: Mar 21, 2024 =

* Introduce a new “Preferences” cookies category
* Integrate with Google Consent Mode (GCM)
Expand Down

0 comments on commit 0b4749a

Please sign in to comment.