Astra_Update_Performance::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-performance.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' )
			);
		}

		$updated         = false;
		$update_messages = array();

		if ( isset( $args['load_google_fonts_locally'] ) ) {
			$load_locally = (bool) $args['load_google_fonts_locally'];
			Astra_API_Init::update_admin_settings_option( 'self_hosted_gfonts', $load_locally );
			$updated           = true;
			$update_messages[] = sprintf( 'Load Google Fonts Locally %s', $load_locally ? 'enabled' : 'disabled' );

			if ( ! $load_locally && isset( $args['preload_local_fonts'] ) && $args['preload_local_fonts'] ) {
				return Astra_Abilities_Response::error(
					__( 'Cannot enable Preload Local Fonts when Load Google Fonts Locally is disabled.', 'astra' ),
					__( 'Please enable Load Google Fonts Locally first or set preload_local_fonts to false.', 'astra' )
				);
			}
		}

		if ( isset( $args['preload_local_fonts'] ) ) {
			$preload              = (bool) $args['preload_local_fonts'];
			$load_locally_enabled = Astra_API_Init::get_admin_settings_option( 'self_hosted_gfonts', false );

			if ( $preload && ! $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', $preload );
			$updated           = true;
			$update_messages[] = sprintf( 'Preload Local Fonts %s', $preload ? 'enabled' : 'disabled' );
		}

		if ( ! $updated ) {
			return Astra_Abilities_Response::error(
				__( 'No changes specified.', 'astra' ),
				__( 'Please provide at least one setting to update.', 'astra' )
			);
		}

		$message = 'Performance settings updated: ' . implode( ', ', $update_messages ) . '.';

		return Astra_Abilities_Response::success(
			$message,
			array( 'updated' => true )
		);
	}


User Contributed Notes

You must log in before being able to contribute a note or feedback.