Astra_Update_Theme_Colors::execute( array $args )

Execute the ability.


Description


Parameters

$args

(array) (Required) Input arguments.


Return

(array) Result array.


Source

File: inc/abilities/customizer/globals/colors/class-astra-update-theme-colors.php

	public function execute( $args ) {
		// Map of input args to Astra settings keys.
		$color_settings = array(
			'accent_color'     => 'theme-color',
			'link_color'       => 'link-color',
			'link_hover_color' => 'link-h-color',
			'heading_color'    => 'heading-base-color',
			'text_color'       => 'text-color',
			'border_color'     => 'border-color',
		);

		// Check if at least one color is provided.
		$has_updates = false;
		foreach ( array_keys( $color_settings ) as $key ) {
			if ( ! empty( $args[ $key ] ) ) {
				$has_updates = true;
				break;
			}
		}

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

		$updated        = array();
		$updated_colors = array();

		foreach ( $color_settings as $arg_key => $settings_key ) {
			if ( ! empty( $args[ $arg_key ] ) ) {
				$color = sanitize_hex_color( $args[ $arg_key ] );

				if ( empty( $color ) ) {
					continue;
				}

				astra_update_option( $settings_key, $color );
				$updated[]                  = str_replace( '_', ' ', $arg_key );
				$updated_colors[ $arg_key ] = $color;
			}
		}

		if ( empty( $updated ) ) {
			return Astra_Abilities_Response::error(
				__( 'Invalid color values.', 'astra' ),
				__( 'Please provide valid hex color values (e.g., #046bd2).', 'astra' )
			);
		}

		// Get all current values for response.
		$current_colors = array();
		foreach ( $color_settings as $arg_key => $settings_key ) {
			$current_colors[ $arg_key ] = astra_get_option( $settings_key );
		}

		return Astra_Abilities_Response::success(
			/* translators: %s: comma-separated list of updated colors */
			sprintf( __( 'Theme colors updated successfully: %s', 'astra' ), implode( ', ', $updated ) ),
			array(
				'updated'        => $updated,
				'updated_colors' => $updated_colors,
				'current_colors' => $current_colors,
				'color_labels'   => array(
					'accent_color'     => 'Accent Color',
					'link_color'       => 'Link Color',
					'link_hover_color' => 'Link Hover Color',
					'heading_color'    => 'Heading (H1-H6) Color',
					'text_color'       => 'Body Text Color',
					'border_color'     => 'Border Color',
				),
			)
		);
	}


User Contributed Notes

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