Skip to content

Commit

Permalink
migrating to default theme.json on plugin deactivate
Browse files Browse the repository at this point in the history
  • Loading branch information
abkarim committed Sep 12, 2023
1 parent ba7ac12 commit f056f37
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
19 changes: 19 additions & 0 deletions includes/classes/ThemeJSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ protected static function rename_defaultthemejson_file_to_themejson_in_theme():
return $is_rename_success;
}

/**
* Migrate to default theme.json
*
* @return bool is_success
* @static
* @access public
* @since 0.2.1
*/
public static function migrate_to_default_theme_json(): bool
{
// Get the path to the active theme's directory
$current_theme_directory = get_stylesheet_directory();

// Remove theme.json
wp_delete_file($current_theme_directory . "/theme.json");

return self::rename_defaultthemejson_file_to_themejson_in_theme();
}

/**
* Update theme.json into backup directory
*
Expand Down
31 changes: 30 additions & 1 deletion xynity-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Xynity Blocks
* Plugin URI: https://github.com/abkarim/xynity-blocks
* Description: Extends wordpress blocks functionality to make better experience with Full Site Editing
* Version: 0.2.0
* Version: 0.2.1
* Requires at least: 6.0
* Requires PHP: 8.0
* Author: Karim
Expand Down Expand Up @@ -43,6 +43,16 @@ public function __construct()
"handle_activation",
]);

/**
* Register plugin deactivation hook
*
* @since 0.2.1
*/
register_deactivation_hook(XYNITY_BLOCKS_FILE, [
$this,
"handle_deactivation",
]);

/**
* Check compatibility and
* manage options
Expand Down Expand Up @@ -259,6 +269,25 @@ public function handle_activation()
}
}

/**
* Handle deactivation
* Performs necessary operation on plugin deactivation
*
* @return void
* @access public
* @since 0.2.1
*/
public function handle_deactivation(): void
{
/**
* Manage theme.json content
* remove xynity's theme.json
* and rename default.theme.json to theme.json
*/
require_once XYNITY_BLOCKS_DIR . "includes/classes/ThemeJSON.php";
\Xynity_Blocks\ThemeJSON::migrate_to_default_theme_json();
}

/**
* Handle theme switch
*
Expand Down

0 comments on commit f056f37

Please sign in to comment.