-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add course info block on lesson cards (#2847)
* Add course info block on lesson cards * Update lesson card experience level style * Fix doc * Use block gap var for level spacing to match row style
- Loading branch information
1 parent
3128a62
commit 8ebdeab
Showing
11 changed files
with
182 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
wp-content/themes/pub/wporg-learn-2024/src/lesson-course-info/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "wporg-learn/lesson-course-info", | ||
"version": "0.1.0", | ||
"title": "Lesson Course Info", | ||
"category": "design", | ||
"icon": "info-outline", | ||
"description": "Displays information about the course a lesson belongs to.", | ||
"textdomain": "wporg-learn", | ||
"supports": { | ||
"align": true, | ||
"html": false, | ||
"color": { | ||
"text": true, | ||
"background": true, | ||
"link": true | ||
}, | ||
"spacing": { | ||
"margin": true, | ||
"padding": true | ||
}, | ||
"typography": { | ||
"fontSize": true, | ||
"lineHeight": true | ||
} | ||
}, | ||
"usesContext": [ "postId", "postType" ], | ||
"editorScript": "file:./index.js", | ||
"style": "file:./style-index.css" | ||
} |
19 changes: 19 additions & 0 deletions
19
wp-content/themes/pub/wporg-learn-2024/src/lesson-course-info/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Edit from '../shared/dynamic-edit'; | ||
import metadata from './block.json'; | ||
import './style.scss'; | ||
|
||
registerBlockType( metadata.name, { | ||
/** | ||
* @see ./edit.js | ||
*/ | ||
edit: Edit, | ||
save: () => null, | ||
} ); |
71 changes: 71 additions & 0 deletions
71
wp-content/themes/pub/wporg-learn-2024/src/lesson-course-info/index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* Block Name: Lesson Course Info | ||
* Description: Displays information about the course a lesson belongs to. | ||
* | ||
* @package wporg | ||
*/ | ||
|
||
namespace WordPressdotorg\Theme\Learn_2024\Lesson_Course_Info; | ||
|
||
use Sensei_Utils; | ||
|
||
add_action( 'init', __NAMESPACE__ . '\init' ); | ||
|
||
/** | ||
* Registers the block using the metadata loaded from the `block.json` file. | ||
* Behind the scenes, it registers also all assets so they can be enqueued | ||
* through the block editor in the corresponding context. | ||
* | ||
* @see https://developer.wordpress.org/reference/functions/register_block_type/ | ||
*/ | ||
function init() { | ||
register_block_type( | ||
dirname( dirname( __DIR__ ) ) . '/build/lesson-course-info', | ||
array( | ||
'render_callback' => __NAMESPACE__ . '\render', | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Render the block content. | ||
* | ||
* @param array $attributes Block attributes. | ||
* @param string $content Block default content. | ||
* @param WP_Block $block Block instance. | ||
* | ||
* @return string Returns the block markup. | ||
*/ | ||
function render( $attributes, $content, $block ) { | ||
if ( ! isset( $block->context['postId'] ) || ! isset( $block->context['postType'] ) || 'lesson' !== $block->context['postType'] ) { | ||
return ''; | ||
} | ||
|
||
$course_id = get_post_meta( $block->context['postId'], '_lesson_course', true ); | ||
|
||
if ( empty( $course_id ) ) { | ||
return ''; | ||
} | ||
|
||
$course_title = get_the_title( $course_id ); | ||
$course_permalink = get_permalink( $course_id ); | ||
|
||
if ( empty( $course_title ) || ! $course_permalink ) { | ||
return ''; | ||
} | ||
|
||
$wrapper_attributes = get_block_wrapper_attributes(); | ||
return sprintf( | ||
'<p %s>%s</p>', | ||
$wrapper_attributes, | ||
wp_kses_post( | ||
sprintf( | ||
/* translators: 1: Course link, 2: Course title */ | ||
__( 'Part of: <a href="%1$s">%2$s</a>', 'wporg-learn' ), | ||
get_permalink( $course_id ), | ||
get_the_title( $course_id ), | ||
) | ||
), | ||
); | ||
} |
14 changes: 14 additions & 0 deletions
14
wp-content/themes/pub/wporg-learn-2024/src/lesson-course-info/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.wp-block-wporg-learn-lesson-course-info { | ||
white-space: nowrap; | ||
overflow-x: hidden; | ||
text-overflow: ellipsis; | ||
max-width: 100%; | ||
|
||
> a { | ||
text-decoration: none; | ||
|
||
&:hover { | ||
text-decoration: underline; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
wp-content/themes/pub/wporg-learn-2024/src/style/_tag.scss
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters