Astra_Update_Sidebar_Layout::execute( array $args )

Execute the ability.


Description


Parameters

$args

(array) (Required) Input arguments.


Return

(array) Result array.


Source

File: inc/abilities/customizer/general/sidebar/class-astra-update-sidebar-layout.php

	public function execute( $args ) {
		if ( ! isset( $args['layout'] ) ) {
			return Astra_Abilities_Response::error(
				__( 'Layout is required.', 'astra' ),
				__( 'Please provide a layout: no-sidebar, left-sidebar, or right-sidebar.', 'astra' )
			);
		}

		$layout        = sanitize_text_field( $args['layout'] );
		$valid_layouts = array( 'no-sidebar', 'left-sidebar', 'right-sidebar' );

		if ( ! in_array( $layout, $valid_layouts, true ) ) {
			return Astra_Abilities_Response::error(
				sprintf(
					/* translators: %s: layout value */
					__( 'Invalid layout: %s.', 'astra' ),
					$layout
				),
				__( 'Valid options: no-sidebar, left-sidebar, right-sidebar', 'astra' )
			);
		}

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

		astra_update_option( 'site-sidebar-layout', $layout );

		$message = sprintf(
			/* translators: %s: layout label */
			__( 'Sidebar layout set to %s.', 'astra' ),
			$layout_labels[ $layout ]
		);

		return Astra_Abilities_Response::success(
			$message,
			array(
				'updated' => true,
				'layout'  => $layout,
			)
		);
	}


User Contributed Notes

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