Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize Sensei blocks for new posts #7736

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/fix-no-sensei-blocks-for-posts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Initialize Sensei blocks for posts
8 changes: 6 additions & 2 deletions includes/blocks/class-sensei-blocks-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,12 @@ private function get_admin_page_post_type(): ?string {
return $post_type ? $post_type : null;
}

if ( 'post-new.php' === $pagenow && isset( $_GET['post_type'] ) && post_type_exists( $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput -- Only reading the post type.
return $_GET['post_type']; // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput -- Already validated.
if ( 'post-new.php' === $pagenow ) {
if ( isset( $_GET['post_type'] ) && post_type_exists( $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput -- Only reading the post type.
return $_GET['post_type']; // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput -- Already validated.
} else {
return 'post';
}
}

return null;
Expand Down
19 changes: 18 additions & 1 deletion tests/unit-tests/blocks/test-class-sensei-blocks-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,24 @@ public function testMaybeInitializeBlocks_WhenInAdminOnGutenbergEditSiteScreen_I
$initializer_mock->maybe_initialize_blocks();
}

public function testMaybeInitializeBlocks_WhenInAdminOnNewPostScreenAndHasCorrectPostType_InitializesBlocks() {
public function testMaybeInitializeBlocks_WhenInAdminOnNewPostScreen_InitializesBlocks() {
/* Arrange */
$initializer_mock = $this->getMockForAbstractClass( Sensei_Blocks_Initializer::class );

set_current_screen( 'post' );

global $pagenow;
$pagenow = 'post-new.php';

/* Assert */
$initializer_mock->expects( $this->once() )
->method( 'initialize_blocks' );

/* Act */
$initializer_mock->maybe_initialize_blocks();
}

public function testMaybeInitializeBlocks_WhenInAdminOnNewCourseScreenAndHasCorrectPostType_InitializesBlocks() {
/* Arrange */
$initializer_mock = $this->getMockForAbstractClass( Sensei_Blocks_Initializer::class, [ [ 'course' ] ] );

Expand Down
Loading