includes/class-custom-sidebars.php
public function init() {

		$posts = array();

		if ( ! $posts = wp_cache_get( 'sidebars', 'custom_sidebars' ) ) {
			$args = array(
				'post_type' => Custom_Sidebars::get_post_types(),
				'meta_query' => array(
					array(
						'key'   => '_custom_sidebar',
						'value' => true,
					)
				)
			);

			$query = new WP_Query( $args );

			if ( $query->have_posts() ) {
				$posts = $query->posts;
			}

			wp_cache_set( 'sidebars', 'custom_sidebars' );
		}

		foreach ( $posts as $post ) {
			$args = apply_filters( 'custom_sidebar_args', array(
				'name'          => sprintf( __( 'Sidebar: %s', 'custom_sidebars' ), $post->post_title ),
				'id'            => $this->get_sidebar_id( $post->ID ),
				'description'   => sprintf( __( 'This sidebar will appear on the %s single page.', 'cd-sidebar' ), $post->post_title ),
				'class'         => '',
				'before_widget' => '<aside id="%1$s" class="widget %2$s">',
				'after_widget'  => '</aside>',
				'before_title'  => '<h2 class="widget-title">',
				'after_title'   => '</h2>',
			) );

			register_sidebar( $args );
		}

	}
public function init() {

		$posts = array();

		if ( ! $posts = wp_cache_get( 'sidebars', 'custom_sidebars' ) ) {
			$args = array(
				'post_type' => Custom_Sidebars::get_post_types(),
				'meta_query' => array(
					array(
						'key'   => '_custom_sidebar',
						'value' => true,
					)
				)
			);

			$query = new WP_Query( $args );

			if ( $query->have_posts() ) {
				$posts = $query->posts;
			}

			wp_cache_set( 'sidebars', 'custom_sidebars' );
		}

		foreach ( $posts as $post ) {
			$args = apply_filters( 'custom_sidebar_args', array(
				'name'          => sprintf( __( 'Sidebar: %s', 'custom_sidebars' ), $post->post_title ),
				'id'            => $this->get_sidebar_id( $post->ID ),
				'description'   => sprintf( __( 'This sidebar will appear on the %s single page.', 'cd-sidebar' ), $post->post_title ),
				'class'         => '',
				'before_widget' => '<aside id="%1$s" class="widget %2$s">',
				'after_widget'  => '</aside>',
				'before_title'  => '<h2 class="widget-title">',
				'after_title'   => '</h2>',
			) );

			register_sidebar( $args );
		}

	}
public function init ( ) { $ posts = array ( ) ; if ( ! $ posts = wp_cache_get ( 'sidebars' , 'custom_sidebars' ) ) { $ args = array ( 'post_type' => Custom_Sidebars :: get_post_types ( ) , 'meta_query' => array ( array ( 'key' => '_custom_sidebar' , 'value' => true , ) ) ) ; $ query = new WP_Query ( $ args ) ; if ( $ query -> have_posts ( ) ) { $ posts = $ query -> posts ; } wp_cache_set ( 'sidebars' , 'custom_sidebars' ) ; } foreach ( $ posts as $ post ) { $ args = apply_filters ( 'custom_sidebar_args' , array ( 'name' => sprintf ( __ ( 'Sidebar: %s' , 'custom_sidebars' ) , $ post -> post_title ) , 'id' => $ this -> get_sidebar_id ( $ post -> ID ) , 'description' => sprintf ( __ ( 'This sidebar will appear on the %s single page.' , 'cd-sidebar' ) , $ post -> post_title ) , 'class' => '' , 'before_widget' => '<aside id="%1$s" class="widget %2$s">' , 'after_widget' => '</aside>' , 'before_title' => '<h2 class="widget-title">' , 'after_title' => '</h2>' , ) ) ; register_sidebar ( $ args ) ; } }
The WP admin_init action callback

Get all pages and posts and add sidebars for each individual post
The WP admin_init action callback