Astra_Update_Background_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-background-colors.php

	public function execute( $args ) {
		if ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) {
			return Astra_Abilities_Response::error(
				__( 'Astra theme is not active.', 'astra' ),
				__( 'Option functions are not available.', 'astra' )
			);
		}

		if ( empty( $args['site_background'] ) && empty( $args['content_background'] ) ) {
			return Astra_Abilities_Response::error(
				__( 'No background specified.', 'astra' ),
				__( 'Please provide either site_background or content_background to update.', 'astra' )
			);
		}

		$theme_options = get_option( ASTRA_THEME_SETTINGS, array() );
		if ( ! is_array( $theme_options ) ) {
			$theme_options = array();
		}

		$updated = array();

		if ( ! empty( $args['site_background'] ) ) {
			$current_site_bg = astra_get_option( 'site-layout-outside-bg-obj-responsive' );
			$new_site_bg     = $this->merge_background_config( $current_site_bg, $args['site_background'] );

			$theme_options['site-layout-outside-bg-obj-responsive'] = $new_site_bg;
			$updated[] = 'site_background';
		}

		if ( ! empty( $args['content_background'] ) ) {
			$current_content_bg = astra_get_option( 'content-bg-obj-responsive' );
			$new_content_bg     = $this->merge_background_config( $current_content_bg, $args['content_background'] );

			$theme_options['content-bg-obj-responsive'] = $new_content_bg;
			$updated[]                                  = 'content_background';
		}

		update_option( ASTRA_THEME_SETTINGS, $theme_options );

		return Astra_Abilities_Response::success(
			/* translators: %s: comma-separated list of updated backgrounds */
			sprintf( __( 'Background colors updated successfully: %s', 'astra' ), implode( ', ', $updated ) ),
			array(
				'updated'            => $updated,
				'site_background'    => isset( $theme_options['site-layout-outside-bg-obj-responsive'] ) ? $theme_options['site-layout-outside-bg-obj-responsive'] : array(),
				'content_background' => isset( $theme_options['content-bg-obj-responsive'] ) ? $theme_options['content-bg-obj-responsive'] : array(),
			)
		);
	}


User Contributed Notes

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