Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove/font management #519

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated the output of filtering fonts to match a full save scenario
pbking committed Mar 14, 2024
commit 51d2afe9094c35a2d6214787d476dfde746879f2
13 changes: 12 additions & 1 deletion admin/create-theme/theme-fonts.php
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ function( $theme_font_family ) use ( $font_families_to_not_remove ) {
foreach ( $font_family['fontFace'] as $font_face ) {
$font_filename = basename( $font_face['src'] );
if ( file_exists( $theme_font_asset_location . $font_filename ) ) {
$response = unlink( $theme_font_asset_location . $font_filename );
unlink( $theme_font_asset_location . $font_filename );
}
}
}
@@ -120,6 +120,17 @@ function( $theme_font_family ) use ( $font_families_to_not_remove ) {
)
);
MY_Theme_JSON_Resolver::write_theme_file_contents( $theme_json );

// Remove user preferences for theme font activation
unset( $user_settings['typography']['fontFamilies']['theme'] );
if ( empty( $user_settings['typography']['fontFamilies'] ) ) {
unset( $user_settings['typography']['fontFamilies'] );
}
if ( empty( $user_settings['typography'] ) ) {
unset( $user_settings['typography'] );
}

MY_Theme_JSON_Resolver::write_user_settings( $user_settings );
}

}
24 changes: 16 additions & 8 deletions tests/test-theme-fonts.php
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ public function test_copy_activated_fonts_to_theme() {
$user_data_before = MY_Theme_JSON_Resolver::get_user_data()->get_settings();
$theme_data_before = MY_Theme_JSON_Resolver::get_theme_data()->get_settings();

Theme_Fonts::copy_activated_fonts_to_theme();
$this->save_theme();

$user_data_after = MY_Theme_JSON_Resolver::get_user_data()->get_settings();
$theme_data_after = MY_Theme_JSON_Resolver::get_theme_data()->get_settings();
@@ -59,11 +59,6 @@ public function test_copy_activated_fonts_to_theme() {

}

private function uninstall_theme( $theme_slug ) {
MY_Theme_JSON_Resolver::write_user_settings( array() );
delete_theme( $theme_slug );
}

public function test_remove_deactivated_fonts_from_theme() {
wp_set_current_user( self::$admin_id );

@@ -76,7 +71,7 @@ public function test_remove_deactivated_fonts_from_theme() {
$merged_data_before = MY_Theme_JSON_Resolver::get_merged_data()->get_settings();
$theme_file_exists_before = file_exists( get_stylesheet_directory() . '/assets/fonts/open-sans-normal-400.ttf' );

Theme_Fonts::remove_deactivated_fonts_from_theme();
$this->save_theme();

$user_data_after = MY_Theme_JSON_Resolver::get_user_data()->get_settings();
$theme_data_after = MY_Theme_JSON_Resolver::get_theme_data()->get_settings();
@@ -94,7 +89,7 @@ public function test_remove_deactivated_fonts_from_theme() {
// ensure that the font was removed from the user settings and removed from the theme settings and therefore missing in merged settings
$this->assertCount( 1, $theme_data_after['typography']['fontFamilies']['theme'] );
$this->assertnotequals( 'open-sans', $theme_data_after['typography']['fontFamilies']['theme'][0]['slug'] );
$this->assertCount( 1, $user_data_after['typography']['fontFamilies']['theme'] );
$this->assertarraynothaskey( 'typography', $user_data_after );
$this->assertnotequals( 'open-sans', $theme_data_after['typography']['fontFamilies']['theme'][0]['slug'] );
$this->assertCount( 1, $merged_data_after['typography']['fontFamilies']['theme'] );
$this->assertnotequals( 'open-sans', $merged_data_after['typography']['fontFamilies']['theme'][0]['slug'] );
@@ -106,6 +101,14 @@ public function test_remove_deactivated_fonts_from_theme() {
$this->uninstall_theme( $test_theme_slug );
}

private function save_theme() {
Theme_Fonts::persist_font_settings();
// Theme_Templates::add_templates_to_local( 'all' );
// Theme_Json::add_theme_json_to_local( 'all' );
// Theme_Styles::clear_user_styles_customizations();
// Theme_Templates::clear_user_templates_customizations();
}

private function create_blank_theme() {

$test_theme_slug = 'cbttesttheme';
@@ -128,6 +131,11 @@ private function create_blank_theme() {
return $test_theme_slug;
}

private function uninstall_theme( $theme_slug ) {
MY_Theme_JSON_Resolver::write_user_settings( array() );
delete_theme( $theme_slug );
}

private function activate_user_font() {

$font_dir = wp_get_font_dir();
Loading