Inventory_Presser_Admin_Photo_Arranger::create_gallery( WP_Post $post )

Makes sure the Gallery Block is waiting for the user when they open a vehicle post in the block editor.


Parameters Parameters

$post

(WP_Post) (Required)


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/admin/class-admin-photo-arranger.php

	public function create_gallery( $post ) {
		global $pagenow;
		if ( ! is_admin()
			|| get_post_type() !== INVP::POST_TYPE
			|| 'post-new.php' !== $pagenow ) {

			return;
		}

		// Does the post content contain a Gallery with a specific CSS class?
		if ( false !== $this->find_gallery_block( $post ) ) {
			// Yes.
			return;
		}

		$blocks             = parse_blocks( $post->post_content );
		$blocks[]           = array(
			'blockName'    => 'core/gallery',
			'attrs'        => array(
				'linkTo'    => 'none',
				'className' => self::CSS_CLASS,
			),
			'innerBlocks'  => array(),
			'innerHTML'    => '',
			'innerContent' => array(
				0 => '<figure class="wp-block-gallery has-nested-images columns-default is-cropped columns-0 ' . self::CSS_CLASS . '"></figure>',
			),
		);
		$post->post_content = serialize_blocks( $blocks );
		$this->safe_update_post( $post );

			// Add all this vehicle's photos.
			// $posts = get_children(
			// array(
			// 'meta_key'    => apply_filters( 'invp_prefix_meta_key', 'photo_number' ),
			// 'order'       => 'ASC',
			// 'orderby'     => 'meta_value_num',
			// 'post_parent' => $post->ID,
			// 'post_type'   => 'attachment',
			// )
			// );
			// foreach ( $posts as $post ) {
			// $this->add_attachment_to_gallery( $post->ID, $post->post_parent );
			// }
	}