Astra_Update_Single_Page::execute( array $args )

Execute the ability.


Description


Parameters

$args

(array) (Required) Input arguments.


Return

(array) Result array.


Source

File: inc/abilities/customizer/posttypes/blog/class-astra-update-single-page.php

	public function execute( $args ) {
		$updated         = false;
		$update_messages = array();

		if ( isset( $args['container_layout'] ) && ! empty( $args['container_layout'] ) ) {
			$container_layout = sanitize_text_field( $args['container_layout'] );
			$valid_layouts    = array( 'default', 'normal-width-container', 'narrow-width-container', 'full-width-container' );
			if ( ! in_array( $container_layout, $valid_layouts, true ) ) {
				return Astra_Abilities_Response::error(
					/* translators: %s: container layout value */
					sprintf( __( 'Invalid container_layout: %s.', 'astra' ), $container_layout ),
					__( 'Valid options: default, normal-width-container, narrow-width-container, full-width-container', 'astra' )
				);
			}

			$layout_labels = array(
				'default'                => 'Default',
				'normal-width-container' => 'Normal',
				'narrow-width-container' => 'Narrow',
				'full-width-container'   => 'Full Width',
			);

			astra_update_option( 'single-page-ast-content-layout', $container_layout );
			$updated           = true;
			$update_messages[] = sprintf( 'Container layout set to %s', $layout_labels[ $container_layout ] );
		}

		if ( isset( $args['container_style'] ) && ! empty( $args['container_style'] ) ) {
			$container_style = sanitize_text_field( $args['container_style'] );
			$valid_styles    = array( 'boxed', 'unboxed' );
			if ( ! in_array( $container_style, $valid_styles, true ) ) {
				return Astra_Abilities_Response::error(
					/* translators: %s: container style value */
					sprintf( __( 'Invalid container_style: %s.', 'astra' ), $container_style ),
					__( 'Valid options: boxed, unboxed', 'astra' )
				);
			}

			$style_labels = array(
				'boxed'   => 'Boxed',
				'unboxed' => 'Unboxed',
			);

			astra_update_option( 'site-content-style', $container_style );
			$updated           = true;
			$update_messages[] = sprintf( 'Container style set to %s', $style_labels[ $container_style ] );
		}

		if ( isset( $args['sidebar_layout'] ) && ! empty( $args['sidebar_layout'] ) ) {
			$sidebar_layout = sanitize_text_field( $args['sidebar_layout'] );
			$valid_sidebars = array( 'default', 'no-sidebar', 'left-sidebar', 'right-sidebar' );
			if ( ! in_array( $sidebar_layout, $valid_sidebars, true ) ) {
				return Astra_Abilities_Response::error(
					/* translators: %s: sidebar layout value */
					sprintf( __( 'Invalid sidebar_layout: %s.', 'astra' ), $sidebar_layout ),
					__( 'Valid options: default, no-sidebar, left-sidebar, right-sidebar', 'astra' )
				);
			}

			$sidebar_labels = array(
				'default'       => 'Default',
				'no-sidebar'    => 'No Sidebar',
				'left-sidebar'  => 'Left Sidebar',
				'right-sidebar' => 'Right Sidebar',
			);

			astra_update_option( 'single-page-sidebar-layout', $sidebar_layout );
			$updated           = true;
			$update_messages[] = sprintf( 'Sidebar layout set to %s', $sidebar_labels[ $sidebar_layout ] );
		}

		if ( isset( $args['sidebar_style'] ) && ! empty( $args['sidebar_style'] ) ) {
			$sidebar_style = sanitize_text_field( $args['sidebar_style'] );
			$valid_styles  = array( 'default', 'unboxed', 'boxed' );
			if ( ! in_array( $sidebar_style, $valid_styles, true ) ) {
				return Astra_Abilities_Response::error(
					/* translators: %s: sidebar style value */
					sprintf( __( 'Invalid sidebar_style: %s.', 'astra' ), $sidebar_style ),
					__( 'Valid options: default, unboxed, boxed', 'astra' )
				);
			}

			$style_labels = array(
				'default' => 'Default',
				'unboxed' => 'Unboxed',
				'boxed'   => 'Boxed',
			);

			astra_update_option( 'single-page-sidebar-style', $sidebar_style );
			$updated           = true;
			$update_messages[] = sprintf( 'Sidebar style set to %s', $style_labels[ $sidebar_style ] );
		}

		if ( isset( $args['content_width'] ) && ! empty( $args['content_width'] ) ) {
			$content_width = sanitize_text_field( $args['content_width'] );
			$valid_widths  = array( 'default', 'custom' );
			if ( ! in_array( $content_width, $valid_widths, true ) ) {
				return Astra_Abilities_Response::error(
					/* translators: %s: content width value */
					sprintf( __( 'Invalid content_width: %s.', 'astra' ), $content_width ),
					__( 'Valid options: default, custom', 'astra' )
				);
			}

			astra_update_option( 'single-page-width', $content_width );
			$updated           = true;
			$update_messages[] = sprintf( 'Content width set to %s', ucfirst( $content_width ) );
		}

		if ( isset( $args['content_max_width'] ) ) {
			$content_max_width = absint( $args['content_max_width'] );
			if ( $content_max_width > 1920 ) {
				return Astra_Abilities_Response::error(
					/* translators: %d: content max width value */
					sprintf( __( 'Invalid content_max_width: %d.', 'astra' ), $content_max_width ),
					__( 'Value must be between 0 and 1920 pixels.', 'astra' )
				);
			}

			astra_update_option( 'single-page-max-width', $content_max_width );
			$updated           = true;
			$update_messages[] = sprintf( 'Content max width set to %dpx', $content_max_width );
		}

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

		$message = 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.