Skip to content

Commit

Permalink
removed support for deprecated Fonts API
Browse files Browse the repository at this point in the history
  • Loading branch information
nk-o committed Feb 7, 2024
1 parent 0612386 commit 7384b6c
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 363 deletions.
3 changes: 0 additions & 3 deletions classes/class-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,6 @@ public function register_scripts() {
'pro' => false,

'themeName' => $theme_data->get( 'Name' ),
'isFseTheme' => current_theme_supports( 'block-templates' ) ? true : false,
'fontsApiExist' => class_exists( 'WP_Fonts' ),
'typographyExist' => GhostKit_Typography::typography_exist(),
'settings' => get_option( 'ghostkit_settings', array() ),
'disabledBlocks' => get_option( 'ghostkit_disabled_blocks', array() ),

Expand Down
54 changes: 3 additions & 51 deletions classes/class-fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,57 +26,9 @@ public function __construct() {
* @return void
*/
public function enqueue_fonts() {
// enqueue fonts for FSE.
if ( current_theme_supports( 'block-templates' ) && ! GhostKit_Typography::typography_exist() && class_exists( 'WP_Fonts' ) ) {
$this->add_fonts();
} else {
// enqueue fonts.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_all_fonts_assets' ), 12 );
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_all_fonts_assets' ), 12 );
}
}

/**
* Registered Google Fonts for FSE Themes.
*
* @return void
*/
public function add_fonts() {
if ( ! function_exists( 'wp_register_fonts' ) ) {
return;
}

wp_register_font_provider( 'google', 'Ghostkit_Fonts_Google_Provider' );

$fonts = get_option( 'ghostkit_fonts_settings', array() );
$google_fonts = $fonts['google'] ?? false;

if ( $google_fonts ) {
$register_fonts = array();
foreach ( $google_fonts as $font ) {
$variants = array();
$font_style = $font['style'];
foreach ( $font['weight'] as $weight ) {
$variants[] = array(
'font-family' => $font['name'],
'font-weight' => $weight,
'font-style' => $font_style,
'provider' => 'google',
);
}
$register_fonts[ $font['name'] ] = $variants;

wp_register_fonts(
array(
$font['name'] => $variants,
)
);

if ( ! is_admin() ) {
wp_enqueue_fonts( array( $font['name'] ) );
}
}
}
// enqueue fonts.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_all_fonts_assets' ), 12 );
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_all_fonts_assets' ), 12 );
}

/**
Expand Down
57 changes: 0 additions & 57 deletions classes/class-typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,63 +18,6 @@ public function __construct() {
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_typography_assets' ), 100 );
}

/**
* Check if typography settings exist.
*
* @return bool
*/
public static function typography_exist() {
$result = get_transient( 'ghostkit_typography_exist' );

if ( ! $result ) {
global $wpdb;
// When caching, we have to write a string so that the function does not call requests every time the page is loaded.
$result = 'false';
$typography_prepeare_styles = array();
$global_typography_prepeare_styles = array();
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$local_typography = $wpdb->query(
$wpdb->prepare(
"SELECT * FROM `{$wpdb->prefix}postmeta` WHERE (`meta_key` LIKE %s) LIMIT 50",
'%ghostkit_typography%'
)
);
/**
* Comparing the global typography with the default.
* If the global typography differs from the default, then it is original.
* In this case, the custom typography is exist.
*/
$global_typography = get_option( 'ghostkit_typography', array() );
$default_typography = apply_filters( 'gkt_custom_typography', array() );
if ( self::is_exist( $default_typography ) && self::is_exist( $global_typography ) && self::is_exist( $global_typography['ghostkit_typography'] ) ) {
foreach ( $default_typography as $key => $typography ) {
if ( self::is_exist( $typography['output'] ) ) {
$typography_prepeare_styles[ $key ] = array(
'style-properties' => $typography['defaults'],
'output' => $typography['output'],
);
}
}

// Global custom Typography.
if ( self::is_exist( $global_typography ) && self::is_exist( $global_typography['ghostkit_typography'] ) ) {
$global_typography_prepeare_styles = self::get_typography_values( $global_typography['ghostkit_typography'], $typography_prepeare_styles );
}
}

if (
$local_typography > 0 &&
$typography_prepeare_styles !== $global_typography_prepeare_styles
) {
$result = true;
}

set_transient( 'ghostkit_typography_exist', $result );
}

return true === $result;
}

/**
* Enqueue Typography assets to editor and front end.
*/
Expand Down
227 changes: 104 additions & 123 deletions gutenberg/plugins/typography/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import getIcon from '../../utils/get-icon';

const PluginMoreMenuItem = StablePluginMoreMenuItem || {};

const { isFseTheme, typographyExist, fontsApiExist } = window.ghostkitVariables;

const { GHOSTKIT } = window;

GHOSTKIT.added_fonts = [];
Expand Down Expand Up @@ -849,129 +847,112 @@ class TypographyModal extends Component {
}}
icon={getIcon('plugin-typography')}
>
{isFseTheme && fontsApiExist && !typographyExist ? (
<div>
{__(
'You are using FSE theme. Typography settings have been moved to block settings',
'ghostkit'
)}
</div>
) : (
<TabPanel
className="ghostkit-control-tabs ghostkit-component-modal-tab-panel"
tabs={[
{
name: 'local',
title: (
<Tooltip
text={__(
'All changes will be applied on the current page only.',
'ghostkit'
)}
>
<span>{__('Local', 'ghostkit')}</span>
</Tooltip>
),
className: 'ghostkit-control-tabs-tab',
},
{
name: 'global',
title: (
<Tooltip
text={__(
'All changes will be applied site wide.',
'ghostkit'
)}
>
<span>{__('Global', 'ghostkit')}</span>
</Tooltip>
),
className: 'ghostkit-control-tabs-tab',
},
]}
>
{(tabData) => {
const isGlobal = tabData.name === 'global';
const setStateTypography = isGlobal
? this.state.globalCustomTypography
: this.state.customTypography;
const typographyList = getCustomTypographyList(
setStateTypography,
isGlobal
);
<TabPanel
className="ghostkit-control-tabs ghostkit-component-modal-tab-panel"
tabs={[
{
name: 'local',
title: (
<Tooltip
text={__(
'All changes will be applied on the current page only.',
'ghostkit'
)}
>
<span>{__('Local', 'ghostkit')}</span>
</Tooltip>
),
className: 'ghostkit-control-tabs-tab',
},
{
name: 'global',
title: (
<Tooltip
text={__(
'All changes will be applied site wide.',
'ghostkit'
)}
>
<span>{__('Global', 'ghostkit')}</span>
</Tooltip>
),
className: 'ghostkit-control-tabs-tab',
},
]}
>
{(tabData) => {
const isGlobal = tabData.name === 'global';
const setStateTypography = isGlobal
? this.state.globalCustomTypography
: this.state.customTypography;
const typographyList = getCustomTypographyList(
setStateTypography,
isGlobal
);

return (
<Fragment>
{Object.keys(typographyList).map((key) => {
const advancedData =
this.state[
isGlobal
? 'globalAdvanced'
: 'advanced'
][key];
const advancedLabel =
advancedData === true
? __(
'Hide Advanced',
'ghostkit'
)
: __(
'Show Advanced',
'ghostkit'
);

if (
typographyList[key].childOf === ''
) {
return (
<div
className="ghostkit-typography-container"
key={key}
>
{this.getTypographyComponent(
typographyList,
key,
isGlobal
)}

{typeof advancedData !==
'undefined' ? (
<div className="ghostkit-typography-advanced">
<Button
isSecondary
onClick={() =>
this.onClickAdvanced(
key,
isGlobal
)
}
className="ghostkit-typography-advanced-button"
>
{advancedLabel}
</Button>
</div>
) : (
''
)}

{advancedData === true
? this.getChildrenTypography(
typographyList,
key,
isGlobal
)
: ''}
</div>
);
}
return (
<Fragment>
{Object.keys(typographyList).map((key) => {
const advancedData =
this.state[
isGlobal
? 'globalAdvanced'
: 'advanced'
][key];
const advancedLabel =
advancedData === true
? __('Hide Advanced', 'ghostkit')
: __('Show Advanced', 'ghostkit');

if (typographyList[key].childOf === '') {
return (
<div
className="ghostkit-typography-container"
key={key}
>
{this.getTypographyComponent(
typographyList,
key,
isGlobal
)}

{typeof advancedData !==
'undefined' ? (
<div className="ghostkit-typography-advanced">
<Button
isSecondary
onClick={() =>
this.onClickAdvanced(
key,
isGlobal
)
}
className="ghostkit-typography-advanced-button"
>
{advancedLabel}
</Button>
</div>
) : (
''
)}

{advancedData === true
? this.getChildrenTypography(
typographyList,
key,
isGlobal
)
: ''}
</div>
);
}

return null;
})}
</Fragment>
);
}}
</TabPanel>
)}
return null;
})}
</Fragment>
);
}}
</TabPanel>
</Modal>
);
}
Expand Down
Loading

0 comments on commit 7384b6c

Please sign in to comment.