<?php
/**
 * The Primary Sidebar
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package Magazine_Power
 */

$default_sidebar = apply_filters( 'magazine_power_filter_default_sidebar_id', 'sidebar-1', 'primary' );

if ( is_singular( array( 'post', 'page' ) ) ) {
	global $post;
	$post_options = get_post_meta( $post->ID, 'magazine_power_theme_settings', true );
	if ( isset( $post_options['sidebar_location_primary'] ) && ! empty( $post_options['sidebar_location_primary'] ) ) {
		$default_sidebar = esc_attr( $post_options['sidebar_location_primary'] );
	}
}
?>

<div id="sidebar-primary" class="widget-area sidebar" role="complementary">

	<div class="sidebar-inner">
	<?php if ( is_active_sidebar( $default_sidebar ) ) : ?>
		<?php dynamic_sidebar( $default_sidebar ); ?>
	<?php else : ?>
		<?php
			/**
			 * Hook - magazine_power_action_default_sidebar.
			 */
			do_action( 'magazine_power_action_default_sidebar', $default_sidebar, 'primary' );
		?>
	<?php endif; ?>
	</div><!-- .sidebar-inner -->
</div><!-- #sidebar-primary -->
