Astra_Update_Footer_Builder_Design::execute( array $args )

Execute the ability.


Description


Parameters

$args

(array) (Required) Input arguments.


Return

(array) Result array.


Source

File: inc/abilities/customizer/footer/class-astra-update-footer-builder-design.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 ( ! isset( $args['section'] ) ) {
			return Astra_Abilities_Response::error(
				__( 'Section is required.', 'astra' ),
				__( 'Please provide a section: above, primary, or below.', 'astra' )
			);
		}

		$section        = $args['section'];
		$valid_sections = array( 'above', 'primary', 'below' );

		if ( ! in_array( $section, $valid_sections, true ) ) {
			return Astra_Abilities_Response::error(
				__( 'Invalid section provided.', 'astra' ),
				__( 'Section must be one of: above, primary, below.', 'astra' )
			);
		}

		$prefix     = $this->get_section_prefix( $section );
		$section_id = $this->get_section_id( $section );

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

		if ( isset( $args['background'] ) && is_array( $args['background'] ) ) {
			$sanitized_bg = $this->sanitize_background( $args['background'] );
			astra_update_option( $prefix . '-bg-obj-responsive', $sanitized_bg );
			$updated           = true;
			$update_messages[] = 'Background updated';
		}

		if ( isset( $args['border_color'] ) ) {
			$sanitized_color = sanitize_text_field( $args['border_color'] );
			astra_update_option( $prefix . '-top-border-color', $sanitized_color );
			$updated           = true;
			$update_messages[] = 'Border color updated';
		}

		if ( isset( $args['border_size'] ) ) {
			$size = intval( $args['border_size'] );
			$size = max( 0, min( 600, $size ) );
			astra_update_option( $prefix . '-separator', $size );
			$updated           = true;
			$update_messages[] = 'Border size updated';
		}

		if ( isset( $args['padding'] ) && is_array( $args['padding'] ) ) {
			$sanitized_padding = $this->sanitize_spacing( $args['padding'] );
			astra_update_option( $section_id . '-padding', $sanitized_padding );
			$updated           = true;
			$update_messages[] = 'Padding updated';
		}

		if ( isset( $args['margin'] ) && is_array( $args['margin'] ) ) {
			$sanitized_margin = $this->sanitize_spacing( $args['margin'] );
			astra_update_option( $section_id . '-margin', $sanitized_margin );
			$updated           = true;
			$update_messages[] = 'Margin updated';
		}

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

		/* translators: 1: section name, 2: list of updates */
		$message = sprintf(
			__( '%1$s footer design updated: %2$s.', 'astra' ),
			ucfirst( $section ),
			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.