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

Add patterns filter by post type #5202

Merged
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
5 changes: 3 additions & 2 deletions assets/admin/editor-wizard/patterns-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ const PatternsList = ( { onChoose } ) => {
aria-label={ __( 'Sensei block patterns', 'sensei-lms' ) }
>
{ patterns
.filter( ( { categories } ) =>
categories.includes( 'sensei-lms' )
.filter(
( { categories } ) =>
categories && categories.includes( 'sensei-lms' )
)
.map(
( { name, title, description, blocks, viewportWidth } ) => (
Expand Down
5 changes: 5 additions & 0 deletions assets/admin/editor-wizard/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
padding: 0;
position: fixed;

// WP 5.8 fixes.
width: 100%;
background: transparent;
margin: 0;

.components-button {
align-self: flex-start;
margin: 8px 8px 0 0;
Expand Down
35 changes: 31 additions & 4 deletions includes/admin/class-sensei-editor-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public static function instance() {
*/
public function init() {
add_action( 'init', [ $this, 'register_post_metas' ] );
add_action( 'init', [ $this, 'register_block_patterns' ] );
add_action( 'init', [ $this, 'register_block_patterns_category' ] );
add_action( 'current_screen', [ $this, 'register_block_patterns' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] );
}

Expand Down Expand Up @@ -96,17 +97,38 @@ public function enqueue_admin_scripts( $hook_suffix ) {
}

/**
* Register block patterns.
* Register Sensei block patterns category.
*
* @access private
*/
public function register_block_patterns() {
// Register block pattern category.
public function register_block_patterns_category() {
register_block_pattern_category(
self::PATTERNS_CATEGORY,
array( 'label' => __( 'Sensei LMS', 'sensei-lms' ) )
);
}

/**
* Register block patterns.
*
* @param WP_Screen $current_screen Current WP_Screen object.
*
* @access private
*/
public function register_block_patterns( $current_screen ) {
$post_type = $current_screen->post_type;

if ( 'course' === $post_type ) {
$this->register_course_block_patterns();
} elseif ( 'lesson' === $post_type ) {
$this->register_lesson_block_patterns();
}
}

/**
* Register course block patterns.
*/
private function register_course_block_patterns() {
register_block_pattern(
'sensei-lms/teachers',
array(
Expand Down Expand Up @@ -136,7 +158,12 @@ public function register_block_patterns() {
'content' => "<!-- wp:columns --><div class=\"wp-block-columns\"><!-- wp:column {\"width\":\"100%\"} --><div class=\"wp-block-column\" style=\"flex-basis:100%\"><!-- wp:columns --><div class=\"wp-block-columns\"><!-- wp:column {\"width\":\"100%\"} --><div class=\"wp-block-column\" style=\"flex-basis:100%\"><!-- wp:columns --><div class=\"wp-block-columns\"><!-- wp:column {\"width\":\"\",\"style\":{\"spacing\":{\"padding\":{\"top\":\"20px\",\"right\":\"10px\",\"bottom\":\"20px\",\"left\":\"10px\"}},\"border\":{\"width\":\"0px\",\"style\":\"none\"}},\"gradient\":\"very-light-gray-to-cyan-bluish-gray\",\"layout\":{\"inherit\":false}} --><div class=\"wp-block-column has-very-light-gray-to-cyan-bluish-gray-gradient-background has-background\" style=\"border-style:none;border-width:0px;padding-top:20px;padding-right:10px;padding-bottom:20px;padding-left:10px\"><!-- wp:heading {\"textAlign\":\"center\",\"level\":3,\"textColor\":\"black\",\"fontSize\":\"large\"} --><h3 class=\"has-text-align-center has-black-color has-text-color has-large-font-size\"><strong>Free'</strong></h3><!-- /wp:heading --><!-- wp:paragraph {\"align\":\"center\"} --><p class=\"has-text-align-center\"><strong>$0</strong>/<em>Month</em></p><!-- /wp:paragraph --><!-- wp:separator {\"className\":\"is-style-wide\"} --><hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\" /><!-- /wp:separator --><!-- wp:paragraph {\"align\":\"center\"} --><p class=\"has-text-align-center\"><strong>- Lorem Ipsum<br>- Pellentesque malesuada<br>- Maecenas vel velit<br>- Nam molestie<br>- Phasellus in turpis</strong><br><strong>- Nunc ornare enim</strong></p><!-- /wp:paragraph --><!-- wp:buttons {\"layout\":{\"type\":\"flex\",\"justifyContent\":\"center\"}} --><div class=\"wp-block-buttons\"><!-- wp:button {\"style\":{\"spacing\":{\"padding\":{\"top\":\"10px\",\"right\":\"25px\",\"bottom\":\"10px\",\"left\":\"25px\"}},\"border\":{\"radius\":\"50px\"}},\"className\":\"is-style-fill\"} --><div class=\"wp-block-button is-style-fill\"><a class=\"wp-block-button__link\" style=\"border-radius:50px;padding-top:10px;padding-right:25px;padding-bottom:10px;padding-left:25px\">Buy Now</a></div><!-- /wp:button --></div><!-- /wp:buttons --></div><!-- /wp:column --><!-- wp:column {\"width\":\"\",\"style\":{\"spacing\":{\"padding\":{\"top\":\"20px\",\"right\":\"10px\",\"bottom\":\"20px\",\"left\":\"10px\"}},\"border\":{\"width\":\"0px\",\"style\":\"none\"}},\"gradient\":\"very-light-gray-to-cyan-bluish-gray\",\"layout\":{\"inherit\":false}} --><div class=\"wp-block-column has-very-light-gray-to-cyan-bluish-gray-gradient-background has-background\" style=\"border-style:none;border-width:0px;padding-top:20px;padding-right:10px;padding-bottom:20px;padding-left:10px\"><!-- wp:heading {\"textAlign\":\"center\",\"level\":3,\"textColor\":\"black\",\"fontSize\":\"large\"} --><h3 class=\"has-text-align-center has-black-color has-text-color has-large-font-size\"><strong>Premium</strong></h3><!-- /wp:heading --><!-- wp:paragraph {\"align\":\"center\"} --><p class=\"has-text-align-center\"><strong>$50</strong>/<em>Month</em></p><!-- /wp:paragraph --><!-- wp:separator {\"className\":\"is-style-wide\"} --><hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\" /><!-- /wp:separator --><!-- wp:paragraph {\"align\":\"center\"} --><p class=\"has-text-align-center\"><strong>- Lorem Ipsum<br>- Pellentesque malesuada<br>- Maecenas vel velit<br>- Nam molestie<br>- Phasellus in turpis</strong><br><strong>- Nunc ornare enim</strong></p><!-- /wp:paragraph --><!-- wp:buttons {\"layout\":{\"type\":\"flex\",\"justifyContent\":\"center\"}} --><div class=\"wp-block-buttons\"><!-- wp:button {\"style\":{\"spacing\":{\"padding\":{\"top\":\"10px\",\"right\":\"25px\",\"bottom\":\"10px\",\"left\":\"25px\"}},\"border\":{\"radius\":\"50px\"}},\"className\":\"is-style-fill\"} --><div class=\"wp-block-button is-style-fill\"><a class=\"wp-block-button__link\" style=\"border-radius:50px;padding-top:10px;padding-right:25px;padding-bottom:10px;padding-left:25px\">Buy Now</a></div><!-- /wp:button --></div><!-- /wp:buttons --></div><!-- /wp:column --></div><!-- /wp:columns --></div><!-- /wp:column --></div><!-- /wp:columns --></div><!-- /wp:column --></div><!-- /wp:columns -->",
)
);
}

/**
* Register lesson block patterns.
*/
private function register_lesson_block_patterns() {
register_block_pattern(
'sensei-lms/artists',
array(
Expand Down