Astra_Update_Preload_Local_Fonts::execute( array $args )
Execute the ability.
Description
Parameters
- $args
-
(array) (Required) Input arguments.
Return
(array) Result array.
Source
File: inc/abilities/admin/settings/performance/class-astra-update-preload-local-fonts.php
public function execute( $args ) {
if ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) {
return Astra_Abilities_Response::error(
__( 'Astra theme is not active.', 'astra' ),
__( 'Please activate the Astra theme to use this feature.', 'astra' )
);
}
if ( ! class_exists( 'Astra_API_Init' ) ) {
return Astra_Abilities_Response::error(
__( 'Astra API not available.', 'astra' ),
__( 'Please ensure Astra theme is properly loaded.', 'astra' )
);
}
if ( ! isset( $args['enabled'] ) ) {
return Astra_Abilities_Response::error(
__( 'Enabled status is required.', 'astra' ),
__( 'Please provide enabled as true or false.', 'astra' )
);
}
$enabled = (bool) $args['enabled'];
$load_locally_enabled = Astra_API_Init::get_admin_settings_option( 'self_hosted_gfonts', false );
if ( $enabled && ! $load_locally_enabled ) {
return Astra_Abilities_Response::error(
__( 'Cannot enable Preload Local Fonts.', 'astra' ),
__( 'Load Google Fonts Locally must be enabled first.', 'astra' )
);
}
Astra_API_Init::update_admin_settings_option( 'preload_local_fonts', $enabled );
/* translators: %s: enabled or disabled */
$message = sprintf( __( 'Preload Local Fonts %s.', 'astra' ), $enabled ? 'enabled' : 'disabled' );
return Astra_Abilities_Response::success(
$message,
array(
'updated' => true,
'enabled' => $enabled,
)
);
}
Expand full source code Collapse full source code View on Trac