Astra_Update_Breadcrumb::execute( array $args )

Execute the ability.


Description


Parameters

$args

(array) (Required) Input arguments.


Return

(array) Result array.


Source

File: inc/abilities/customizer/general/breadcrumb/class-astra-update-breadcrumb.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' )
			);
		}

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

		if ( isset( $args['position'] ) ) {
			$position        = sanitize_text_field( $args['position'] );
			$valid_positions = array( 'none', 'astra_header_primary_container_after', 'astra_header_after', 'astra_entry_top' );

			if ( ! in_array( $position, $valid_positions, true ) ) {
				return Astra_Abilities_Response::error(
					/* translators: %s: invalid position value */
					sprintf( __( 'Invalid position: %s.', 'astra' ), $position ),
					__( 'Valid options: none, astra_header_primary_container_after, astra_header_after, astra_entry_top', 'astra' )
				);
			}

			astra_update_option( 'breadcrumb-position', $position );
			$updated = true;
			/* translators: %s: position value */
			$update_messages[] = sprintf( __( 'Position set to %s', 'astra' ), $position );
		}

		if ( isset( $args['alignment'] ) ) {
			$alignment        = sanitize_text_field( $args['alignment'] );
			$valid_alignments = array( 'left', 'center', 'right' );

			if ( ! in_array( $alignment, $valid_alignments, true ) ) {
				return Astra_Abilities_Response::error(
					/* translators: %s: invalid alignment value */
					sprintf( __( 'Invalid alignment: %s.', 'astra' ), $alignment ),
					__( 'Valid options: left, center, right', 'astra' )
				);
			}

			astra_update_option( 'breadcrumb-alignment', $alignment );
			$updated = true;
			/* translators: %s: alignment value */
			$update_messages[] = sprintf( __( 'Alignment set to %s', 'astra' ), $alignment );
		}

		if ( isset( $args['separator_type'] ) ) {
			$separator_type   = sanitize_text_field( $args['separator_type'] );
			$valid_separators = array( '\003E', '\00BB', '\002F', 'unicode' );

			if ( ! in_array( $separator_type, $valid_separators, true ) ) {
				return Astra_Abilities_Response::error(
					/* translators: %s: invalid separator type value */
					sprintf( __( 'Invalid separator_type: %s.', 'astra' ), $separator_type ),
					__( 'Valid options: \003E, \00BB, \002F, unicode', 'astra' )
				);
			}

			astra_update_option( 'breadcrumb-separator-selector', $separator_type );
			$updated           = true;
			$update_messages[] = __( 'Separator type updated', 'astra' );
		}

		if ( isset( $args['separator_custom'] ) ) {
			$separator_custom = sanitize_text_field( $args['separator_custom'] );
			astra_update_option( 'breadcrumb-separator', $separator_custom );
			$updated           = true;
			$update_messages[] = __( 'Custom separator updated', 'astra' );
		}

		if ( isset( $args['enable_on'] ) && is_array( $args['enable_on'] ) ) {
			$enable_map = array(
				'home_page'   => 'breadcrumb-disable-home-page',
				'blog_page'   => 'breadcrumb-disable-blog-posts-page',
				'search'      => 'breadcrumb-disable-search',
				'archive'     => 'breadcrumb-disable-archive',
				'single_page' => 'breadcrumb-disable-single-page',
				'single_post' => 'breadcrumb-disable-single-post',
				'singular'    => 'breadcrumb-disable-singular',
				'404_page'    => 'breadcrumb-disable-404-page',
			);

			foreach ( $enable_map as $key => $option_key ) {
				if ( isset( $args['enable_on'][ $key ] ) ) {
					$value = (bool) $args['enable_on'][ $key ] ? '1' : '0';
					astra_update_option( $option_key, $value );
					$updated = true;
				}
			}
			$update_messages[] = __( 'Display settings updated', 'astra' );
		}

		if ( isset( $args['typography'] ) && is_array( $args['typography'] ) ) {
			$typo = $args['typography'];

			if ( isset( $typo['font_family'] ) ) {
				astra_update_option( 'breadcrumb-font-family', sanitize_text_field( $typo['font_family'] ) );
				$updated = true;
			}

			if ( isset( $typo['font_weight'] ) ) {
				astra_update_option( 'breadcrumb-font-weight', sanitize_text_field( $typo['font_weight'] ) );
				$updated = true;
			}

			if ( isset( $typo['font_size'] ) && is_array( $typo['font_size'] ) ) {
				$sanitized_size = $this->sanitize_responsive_value( $typo['font_size'] );
				astra_update_option( 'breadcrumb-font-size', $sanitized_size );
				$updated = true;
			}

			if ( isset( $typo['font_extras'] ) && is_array( $typo['font_extras'] ) ) {
				$sanitized_extras = array();
				$allowed_keys     = array( 'line-height', 'text-transform', 'letter-spacing' );
				foreach ( $allowed_keys as $key ) {
					if ( isset( $typo['font_extras'][ $key ] ) ) {
						$sanitized_extras[ $key ] = sanitize_text_field( $typo['font_extras'][ $key ] );
					}
				}
				astra_update_option( 'breadcrumb-font-extras', $sanitized_extras );
				$updated = true;
			}

			if ( $updated ) {
				$update_messages[] = __( 'Typography updated', 'astra' );
			}
		}

		if ( isset( $args['colors'] ) && is_array( $args['colors'] ) ) {
			$colors = $args['colors'];

			if ( isset( $colors['background'] ) && is_array( $colors['background'] ) ) {
				$sanitized_bg = $this->sanitize_responsive_color( $colors['background'] );
				astra_update_option( 'breadcrumb-bg-color', $sanitized_bg );
				$updated = true;
			}

			if ( isset( $colors['text'] ) && is_array( $colors['text'] ) ) {
				$sanitized_text = $this->sanitize_responsive_color( $colors['text'] );
				astra_update_option( 'breadcrumb-active-color-responsive', $sanitized_text );
				$updated = true;
			}

			if ( isset( $colors['separator'] ) && is_array( $colors['separator'] ) ) {
				$sanitized_sep = $this->sanitize_responsive_color( $colors['separator'] );
				astra_update_option( 'breadcrumb-separator-color', $sanitized_sep );
				$updated = true;
			}

			if ( isset( $colors['link_normal'] ) && is_array( $colors['link_normal'] ) ) {
				$sanitized_link = $this->sanitize_responsive_color( $colors['link_normal'] );
				astra_update_option( 'breadcrumb-text-color-responsive', $sanitized_link );
				$updated = true;
			}

			if ( isset( $colors['link_hover'] ) && is_array( $colors['link_hover'] ) ) {
				$sanitized_hover = $this->sanitize_responsive_color( $colors['link_hover'] );
				astra_update_option( 'breadcrumb-hover-color-responsive', $sanitized_hover );
				$updated = true;
			}

			$update_messages[] = __( 'Colors updated', 'astra' );
		}

		if ( isset( $args['spacing'] ) && is_array( $args['spacing'] ) ) {
			$sanitized_spacing = $this->sanitize_spacing( $args['spacing'] );
			astra_update_option( 'breadcrumb-spacing', $sanitized_spacing );
			$updated           = true;
			$update_messages[] = __( 'Spacing updated', 'astra' );
		}

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

		/* translators: %s: comma-separated list of updated settings */
		$message = sprintf( __( 'Breadcrumb settings updated: %s.', 'astra' ), 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.