astra_toggle_layout( mixed $new_content_option, mixed $level, mixed $post_id = false, mixed $old_meta = false )

Return current content layout as per new layout selection.


Description


Parameters

$new_content_option

(mixed) (Required) The new content layout option.

$level

(mixed) (Required) The level of the layout.

$post_id

(mixed) (Optional) The id to fetch post meta.

Default value: false

$old_meta

(mixed) (Optional) The old content layout option for migration cases.

Default value: false


Return

(mixed) content layout.


Source

File: inc/extras.php

function astra_toggle_layout( $new_content_option, $level, $post_id = false, $old_meta = false ) {

	// Dynamic layout option for meta case.
	$dynamic_layout_option = 'meta' === $level ? astra_get_option_meta( $new_content_option, '', true ) : astra_get_option( $new_content_option, 'default' );
	$current_layout        = '';

	// Get meta value by ID if specified.
	if ( $post_id ) {
		$dynamic_layout_option = get_post_meta( $post_id, $new_content_option, true );
	}

	// Meta layout migrations.
	$meta_key              = astra_get_option_meta( 'astra-migrate-meta-layouts', '', true );
	$migrated_user         = ( ! Astra_Dynamic_CSS::astra_fullwidth_sidebar_support() );
	$third_party_meta_page = astra_third_party_archive_meta( 'site-content-layout' );
	if ( 'meta' === $level && $migrated_user ) {
		if ( false !== $third_party_meta_page ) {
			$old_meta = $third_party_meta_page;
			$meta_key = astra_third_party_archive_meta( 'astra-migrate-meta-layouts' );
		}
		if ( $old_meta && 'set' !== $meta_key ) {
			$dynamic_layout_option = astra_migrate_meta_layout( $old_meta );
		}
	}

	switch ( $dynamic_layout_option ) {
		case 'normal-width-container':
			$current_layout = 'plain-container';
			break;
		case 'narrow-width-container':
			$current_layout = 'narrow-container';

			// Exclude narrow layout for third party cases.
			if ( astra_with_third_party() && ( ! $migrated_user ) ) {
				$current_layout = 'plain-container';
			}
			break;
		case 'full-width-container':
			$current_layout = 'page-builder';
			break;
		default:
			if ( 'meta' === $level && ! $migrated_user && 'set' !== $meta_key && $old_meta ) {
				$current_layout = $old_meta;
			} else {
				$current_layout = '';
			}
			break;
	}
	return $current_layout;
}

Changelog

Changelog
Version Description
4.2.0 Introduced.


User Contributed Notes

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