From 12675e380e005b351d67c1f867f87df353280ab1 Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Mon, 23 May 2022 19:29:28 -0300 Subject: [PATCH 1/3] Add some samples to Sensei patterns --- includes/admin/class-sensei-editor-wizard.php | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/includes/admin/class-sensei-editor-wizard.php b/includes/admin/class-sensei-editor-wizard.php index 7cc2bed706..0e66942923 100644 --- a/includes/admin/class-sensei-editor-wizard.php +++ b/includes/admin/class-sensei-editor-wizard.php @@ -46,6 +46,7 @@ public static function instance() { */ public function init() { add_action( 'init', [ $this, 'register_post_metas' ] ); + add_action( 'init', [ $this, 'register_block_patterns' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] ); } @@ -88,4 +89,124 @@ public function enqueue_admin_scripts( $hook_suffix ) { Sensei()->assets->enqueue( 'sensei-editor-wizard-style', 'admin/editor-wizard/style.css' ); } } + + /** + * Register block patterns. + * + * @access private + */ + public function register_block_patterns() { + $post_type = $this->get_early_post_type(); + + if ( ! $post_type ) { + return; + } + + // Register block pattern category. + if ( in_array( $post_type, [ 'course', 'lesson' ], true ) ) { + register_block_pattern_category( + 'sensei-lms', + array( 'label' => __( 'Sensei LMS', 'sensei-lms' ) ) + ); + } + + if ( 'course' === $post_type ) { + $this->register_course_block_patterns(); + } elseif ( 'lesson' === $post_type ) { + $this->register_lesson_block_patterns(); + } + } + + /** + * Get post type in the init hook. + * + * @return string|false Post type on success, false on failure. + */ + private function get_early_post_type() { + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Only for comparison. + $post_type = $_GET['post_type'] ?? null; + + if ( ! empty( $post_type ) ) { + return $post_type; + } + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Only for comparison. + $post_id = $_GET['post'] ?? null; + + if ( ! empty( $post_id ) ) { + return get_post_type( $post_id ); + } + + return false; + } + + /** + * Register course block patterns. + */ + private function register_course_block_patterns() { + register_block_pattern( + 'sensei-lms/teachers', + array( + 'title' => __( 'Teachers', 'sensei-lms' ), + 'categories' => [ 'sensei-lms' ], + 'viewportWidth' => 800, + 'content' => "
OUR TEAM

Experienced & Professional

We're Proud to present you our experienced and professional people who will work on your project.

\"\"
Jack Tommy Bishop - CEO

Jack Tommy Bishop is a 53-year-old senior politician who enjoys swimming, watching television and travelling. He is friendly and bright, but can also be very sneaky and a bit boring.

\"\"
Mike Daniel Grey - COO

Mike Daniel Grey is an 81-year-old teenager who enjoys painting, watching television and watching YouTube videos. He is considerate and friendly, but can also be very greedy and a bit unintelligent.

\"\"
Ruth Sonya Malkovic - CTO

Ruth Sonya Malkovich is a 23-year-old town counsellor who enjoys listening to music, chess and drone photography. She is exciting and considerate, but can also be very sneaky and a bit lazy.

", + ) + ); + + register_block_pattern( + 'sensei-lms/clients', + array( + 'title' => __( 'Clients', 'sensei-lms' ), + 'categories' => [ 'sensei-lms' ], + 'viewportWidth' => 800, + 'content' => "
Portfolio

Some of Our Clients

We're Proud to Have Established Relationships with Thousands of Clients in All Industries. Below represents a small sampling of our clients.

\"\"
\"\"
\"\"
\"\"
\"\"

We'd love to add your company to our growing roster of happy customers!

", + ) + ); + + register_block_pattern( + 'sensei-lms/prices', + array( + 'title' => __( 'Prices', 'sensei-lms' ), + 'categories' => [ 'sensei-lms' ], + 'viewportWidth' => 800, + 'content' => "

Free'

$0/Month


- Lorem Ipsum
- Pellentesque malesuada
- Maecenas vel velit
- Nam molestie
- Phasellus in turpis

- Nunc ornare enim

Premium

$50/Month


- Lorem Ipsum
- Pellentesque malesuada
- Maecenas vel velit
- Nam molestie
- Phasellus in turpis

- Nunc ornare enim

", + ) + ); + } + + /** + * Register lesson block patterns. + */ + private function register_lesson_block_patterns() { + register_block_pattern( + 'sensei-lms/artists', + array( + 'title' => __( 'Artists', 'sensei-lms' ), + 'categories' => [ 'sensei-lms' ], + 'viewportWidth' => 800, + 'content' => "

2022 Artists' Line Up

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

", + ) + ); + + register_block_pattern( + 'sensei-lms/testimonials', + array( + 'title' => __( 'Testimonials', 'sensei-lms' ), + 'categories' => [ 'sensei-lms' ], + 'viewportWidth' => 800, + 'content' => "

TESTIMONIALS

What Clients Say

We place huge value on strong relationships and have seen the benefit' they bring to our business. Customer feedback is vital in helping us to get it right.

\"\"

\"Vitae suscipit tellus mauris a diam maecenas sed enim ut. Mauris augue neque gravida in fermentum. Praesent semper feugiat nibh sed pulvinar.\"

Nat Reynolds
Chief Accountant
\"\"

\"Pharetra vel turpis nunc eget lorem. Quisque id diam vel quam elementum pulvinar etiam. Urna porttitor rhoncus dolor purus non enim.\"

Celia Almeda
Secretary
\"\"

\"Mauris augue neque gravida in fermentum. Praesent semper feugiat nibh sed pulvinar proin. Nibh nisl dictumst vestibulum rhoncus.\"

Bob Roberts
Sales Manager
", + ) + ); + + register_block_pattern( + 'sensei-lms/featured', + array( + 'title' => __( 'Featured', 'sensei-lms' ), + 'categories' => [ 'sensei-lms' ], + 'viewportWidth' => 800, + 'content' => "

officia deserunt mollit

Lorem ipsum' dolor

Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\"\"
", + ) + ); + } } From 578e4d522f08e6b9dcf8aeb18c8cc3a66433f58f Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Wed, 25 May 2022 17:08:36 -0300 Subject: [PATCH 2/3] Register all patterns regardless the post type --- includes/admin/class-sensei-editor-wizard.php | 55 ++----------------- 1 file changed, 4 insertions(+), 51 deletions(-) diff --git a/includes/admin/class-sensei-editor-wizard.php b/includes/admin/class-sensei-editor-wizard.php index 0e66942923..851ce3de9e 100644 --- a/includes/admin/class-sensei-editor-wizard.php +++ b/includes/admin/class-sensei-editor-wizard.php @@ -96,54 +96,12 @@ public function enqueue_admin_scripts( $hook_suffix ) { * @access private */ public function register_block_patterns() { - $post_type = $this->get_early_post_type(); - - if ( ! $post_type ) { - return; - } - // Register block pattern category. - if ( in_array( $post_type, [ 'course', 'lesson' ], true ) ) { - register_block_pattern_category( - 'sensei-lms', - array( 'label' => __( 'Sensei LMS', 'sensei-lms' ) ) - ); - } - - if ( 'course' === $post_type ) { - $this->register_course_block_patterns(); - } elseif ( 'lesson' === $post_type ) { - $this->register_lesson_block_patterns(); - } - } - - /** - * Get post type in the init hook. - * - * @return string|false Post type on success, false on failure. - */ - private function get_early_post_type() { - // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Only for comparison. - $post_type = $_GET['post_type'] ?? null; - - if ( ! empty( $post_type ) ) { - return $post_type; - } - - // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Only for comparison. - $post_id = $_GET['post'] ?? null; - - if ( ! empty( $post_id ) ) { - return get_post_type( $post_id ); - } - - return false; - } + register_block_pattern_category( + 'sensei-lms', + array( 'label' => __( 'Sensei LMS', 'sensei-lms' ) ) + ); - /** - * Register course block patterns. - */ - private function register_course_block_patterns() { register_block_pattern( 'sensei-lms/teachers', array( @@ -173,12 +131,7 @@ private function register_course_block_patterns() { 'content' => "

Free'

$0/Month


- Lorem Ipsum
- Pellentesque malesuada
- Maecenas vel velit
- Nam molestie
- Phasellus in turpis

- Nunc ornare enim

Premium

$50/Month


- Lorem Ipsum
- Pellentesque malesuada
- Maecenas vel velit
- Nam molestie
- Phasellus in turpis

- Nunc ornare enim

", ) ); - } - /** - * Register lesson block patterns. - */ - private function register_lesson_block_patterns() { register_block_pattern( 'sensei-lms/artists', array( From 7b9332b75563c49171e07b15218fc4fdf35b62ab Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Wed, 25 May 2022 17:09:02 -0300 Subject: [PATCH 3/3] Add pattern category to a constant --- includes/admin/class-sensei-editor-wizard.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/includes/admin/class-sensei-editor-wizard.php b/includes/admin/class-sensei-editor-wizard.php index 851ce3de9e..75f2b44fda 100644 --- a/includes/admin/class-sensei-editor-wizard.php +++ b/includes/admin/class-sensei-editor-wizard.php @@ -15,6 +15,8 @@ * @since $$next-version$$ */ class Sensei_Editor_Wizard { + const PATTERNS_CATEGORY = 'sensei-lms'; + /** * Instance of class. * @@ -98,7 +100,7 @@ public function enqueue_admin_scripts( $hook_suffix ) { public function register_block_patterns() { // Register block pattern category. register_block_pattern_category( - 'sensei-lms', + self::PATTERNS_CATEGORY, array( 'label' => __( 'Sensei LMS', 'sensei-lms' ) ) ); @@ -106,7 +108,7 @@ public function register_block_patterns() { 'sensei-lms/teachers', array( 'title' => __( 'Teachers', 'sensei-lms' ), - 'categories' => [ 'sensei-lms' ], + 'categories' => [ self::PATTERNS_CATEGORY ], 'viewportWidth' => 800, 'content' => "
OUR TEAM

Experienced & Professional

We're Proud to present you our experienced and professional people who will work on your project.

\"\"
Jack Tommy Bishop - CEO

Jack Tommy Bishop is a 53-year-old senior politician who enjoys swimming, watching television and travelling. He is friendly and bright, but can also be very sneaky and a bit boring.

\"\"
Mike Daniel Grey - COO

Mike Daniel Grey is an 81-year-old teenager who enjoys painting, watching television and watching YouTube videos. He is considerate and friendly, but can also be very greedy and a bit unintelligent.

\"\"
Ruth Sonya Malkovic - CTO

Ruth Sonya Malkovich is a 23-year-old town counsellor who enjoys listening to music, chess and drone photography. She is exciting and considerate, but can also be very sneaky and a bit lazy.

", ) @@ -116,7 +118,7 @@ public function register_block_patterns() { 'sensei-lms/clients', array( 'title' => __( 'Clients', 'sensei-lms' ), - 'categories' => [ 'sensei-lms' ], + 'categories' => [ self::PATTERNS_CATEGORY ], 'viewportWidth' => 800, 'content' => "
Portfolio

Some of Our Clients

We're Proud to Have Established Relationships with Thousands of Clients in All Industries. Below represents a small sampling of our clients.

\"\"
\"\"
\"\"
\"\"
\"\"

We'd love to add your company to our growing roster of happy customers!

", ) @@ -126,7 +128,7 @@ public function register_block_patterns() { 'sensei-lms/prices', array( 'title' => __( 'Prices', 'sensei-lms' ), - 'categories' => [ 'sensei-lms' ], + 'categories' => [ self::PATTERNS_CATEGORY ], 'viewportWidth' => 800, 'content' => "

Free'

$0/Month


- Lorem Ipsum
- Pellentesque malesuada
- Maecenas vel velit
- Nam molestie
- Phasellus in turpis

- Nunc ornare enim

Premium

$50/Month


- Lorem Ipsum
- Pellentesque malesuada
- Maecenas vel velit
- Nam molestie
- Phasellus in turpis

- Nunc ornare enim

", ) @@ -136,7 +138,7 @@ public function register_block_patterns() { 'sensei-lms/artists', array( 'title' => __( 'Artists', 'sensei-lms' ), - 'categories' => [ 'sensei-lms' ], + 'categories' => [ self::PATTERNS_CATEGORY ], 'viewportWidth' => 800, 'content' => "

2022 Artists' Line Up

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

", ) @@ -146,7 +148,7 @@ public function register_block_patterns() { 'sensei-lms/testimonials', array( 'title' => __( 'Testimonials', 'sensei-lms' ), - 'categories' => [ 'sensei-lms' ], + 'categories' => [ self::PATTERNS_CATEGORY ], 'viewportWidth' => 800, 'content' => "

TESTIMONIALS

What Clients Say

We place huge value on strong relationships and have seen the benefit' they bring to our business. Customer feedback is vital in helping us to get it right.

\"\"

\"Vitae suscipit tellus mauris a diam maecenas sed enim ut. Mauris augue neque gravida in fermentum. Praesent semper feugiat nibh sed pulvinar.\"

Nat Reynolds
Chief Accountant
\"\"

\"Pharetra vel turpis nunc eget lorem. Quisque id diam vel quam elementum pulvinar etiam. Urna porttitor rhoncus dolor purus non enim.\"

Celia Almeda
Secretary
\"\"

\"Mauris augue neque gravida in fermentum. Praesent semper feugiat nibh sed pulvinar proin. Nibh nisl dictumst vestibulum rhoncus.\"

Bob Roberts
Sales Manager
", ) @@ -156,7 +158,7 @@ public function register_block_patterns() { 'sensei-lms/featured', array( 'title' => __( 'Featured', 'sensei-lms' ), - 'categories' => [ 'sensei-lms' ], + 'categories' => [ self::PATTERNS_CATEGORY ], 'viewportWidth' => 800, 'content' => "

officia deserunt mollit

Lorem ipsum' dolor

Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\"\"
", )