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

Make customize template task point to Learning Mode template #7393

Merged
merged 12 commits into from
Dec 25, 2023
4 changes: 4 additions & 0 deletions changelog/add-update-customize-template-task
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Take user to Learning Mode Lesson Template in Setup task instead of only site editor
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function get_priority(): int {
* @return string
*/
public function get_title(): string {
return __( 'Customize your theme', 'sensei-lms' );
return __( 'Customize your lesson template', 'sensei-lms' );
}

/**
Expand All @@ -47,7 +47,7 @@ public function get_title(): string {
* @return string
*/
public function get_url(): ?string {
return admin_url( 'site-editor.php' );
return Sensei_Course_Theme::get_learning_mode_fse_url();
}

/**
Expand Down
7 changes: 6 additions & 1 deletion includes/class-sensei-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,12 @@
// the site editor or the customizer with the Course theme installed.
if ( Sensei_Home_Task_Customize_Course_Theme::is_active() ) {
if ( in_array( $pagenow, [ 'site-editor.php', 'customize.php' ], true ) ) {
Sensei_Home_Task_Customize_Course_Theme::mark_completed();
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$post_id = isset( $_GET['postId'] ) ? sanitize_text_field( wp_unslash( $_GET['postId'] ) ) : '';

Check warning on line 1892 in includes/class-sensei-admin.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei-admin.php#L1892

Added line #L1892 was not covered by tests

if ( Sensei_Course_Theme::get_learning_mode_template_id( 'lesson' ) === $post_id ) {
Sensei_Home_Task_Customize_Course_Theme::mark_completed();

Check warning on line 1895 in includes/class-sensei-admin.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei-admin.php#L1894-L1895

Added lines #L1894 - L1895 were not covered by tests
}
}
}
}
Expand Down
17 changes: 14 additions & 3 deletions includes/course-theme/class-sensei-course-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@
*
* @param string|null $post_type The post type to customize.
*
* @return The customization url
* @return string The customization url.
*/
public static function get_learning_mode_fse_url( string $post_type = null ) : string {
// Get the post type manually if not provided.
Expand All @@ -456,11 +456,22 @@
$post_type = 'lesson';
}

return admin_url( 'site-editor.php?postType=wp_template&postId=' . self::THEME_NAME . '//' . $post_type );
return admin_url( 'site-editor.php?postType=wp_template&postId=' . self::get_learning_mode_template_id( $post_type ) );

Check warning on line 459 in includes/course-theme/class-sensei-course-theme.php

View check run for this annotation

Codecov / codecov/patch

includes/course-theme/class-sensei-course-theme.php#L459

Added line #L459 was not covered by tests
}

/**
* Returnds the url for customizing Learning Mode template colors.
* Returns the template ID of the post type for Learning Mode.
*
* @param string|null $post_type The post type to generate the template ID for.
*
* @return string The template ID.
*/
public static function get_learning_mode_template_id( $post_type = null ) : string {
return self::THEME_NAME . '//' . $post_type;

Check warning on line 470 in includes/course-theme/class-sensei-course-theme.php

View check run for this annotation

Codecov / codecov/patch

includes/course-theme/class-sensei-course-theme.php#L469-L470

Added lines #L469 - L470 were not covered by tests
}

/**
* Returns the url for customizing Learning Mode template colors.
*/
public static function get_learning_mode_customizer_url(): string {
// Get the last modified lesson.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ public function testIsActive_WhenCourseThemeIsInstalled_ReturnsTrue() {
// Assert.
$this->assertTrue( $this->task->is_active() );
}

public function testGetTitle_WhenCalled_ReturnsProperTitle() {
// Assert.
$this->assertEquals( 'Customize your lesson template', $this->task->get_title() );
}

public function testGetURL_WhenCalled_ReturnsFSETemplateURLOfLesson() {
// Assert.
$this->assertStringContainsString( 'sensei-course-theme//lesson', $this->task->get_url() );
}
}
Loading