generated from alleyinteractive/create-wordpress-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from alleyinteractive/feature/LEDE-2617/post-…
…list-block LEDE-2617 Latest Posts Block
- Loading branch information
Showing
8 changed files
with
187 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* Core latest posts block modifications. | ||
* | ||
* @package wp-newsletter-builder | ||
*/ | ||
|
||
namespace WP_Newsletter_Builder; | ||
|
||
/** | ||
* Registers assets so that they can be enqueued through Gutenberg in | ||
* the corresponding context. | ||
*/ | ||
function register_latest_posts_scripts(): void { | ||
wp_register_script( | ||
'plugin-newsletter-latest-posts', | ||
get_entry_asset_url( 'wp-newsletter-builder-latest-posts' ), | ||
get_asset_dependency_array( 'wp-newsletter-builder-latest-posts' ), | ||
get_asset_version( 'wp-newsletter-builder-latest-posts' ), | ||
true | ||
); | ||
wp_set_script_translations( 'plugin-newsletter-latest-posts' ); | ||
} | ||
add_action( 'init', __NAMESPACE__ . '\register_latest_posts_scripts' ); | ||
|
||
/** | ||
* Enqueue block editor assets for latest-postss. | ||
*/ | ||
function action_enqueue_latest_posts_assets(): void { | ||
$post_type = get_edit_post_type(); | ||
if ( ( 'nb_newsletter' !== $post_type ) && ( 'nb_template' !== $post_type ) ) { | ||
return; | ||
} | ||
wp_enqueue_script( 'plugin-newsletter-latest-posts' ); | ||
} | ||
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\action_enqueue_latest_posts_assets' ); |
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,56 @@ | ||
import { addFilter } from '@wordpress/hooks'; | ||
|
||
/** | ||
* Modifies supports for Latest Posts block. | ||
* | ||
* @param {Object} settings - The original block settings. | ||
* @param {string} name - The name of the block. | ||
* | ||
* @returns {Object} The modified block settings. | ||
*/ | ||
// @ts-ignore | ||
function modifyLatestPostsSupports(settings, name) { | ||
// Bail early if the block does not have supports. | ||
if (!settings?.supports) { | ||
return settings; | ||
} | ||
// Only apply to Latest Posts blocks. | ||
if ( | ||
name === 'core/latest-posts' | ||
) { | ||
return { | ||
...settings, | ||
attributes: Object.assign(settings.attributes, { | ||
excerptLength: { | ||
default: 20, | ||
}, | ||
}), | ||
supports: Object.assign(settings.supports, { | ||
align: [], | ||
anchor: false, | ||
color: { | ||
background: false, | ||
text: false, | ||
}, | ||
customClassName: false, | ||
spacing: false, | ||
typography: { | ||
__experimentalFontSize: false, | ||
__experimentalLineHeight: false, | ||
__experimentalLetterSpacing: false, | ||
__experimentalFontFamily: false, | ||
__experimentalFontWeight: false, | ||
__experimentalFontStyle: false, | ||
__experimentalTextTransform: false, | ||
}, | ||
}), | ||
}; | ||
} | ||
return settings; | ||
} | ||
|
||
addFilter( | ||
'blocks.registerBlockType', | ||
'wp-newsletter-builder/latest-posts', | ||
modifyLatestPostsSupports, | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
.wp-block-latest-posts { | ||
border-collapse: collapse; | ||
display: table; | ||
list-style-type: none; | ||
padding: 0; | ||
width: 100%; | ||
|
||
li { | ||
border-bottom: 1px solid #ccc; | ||
box-sizing: border-box; | ||
clear: both; | ||
display: table-row; | ||
width: 100%; | ||
|
||
> * { | ||
margin: 16px; | ||
} | ||
} | ||
|
||
img { | ||
max-width: 250px; | ||
} | ||
|
||
.wp-block-latest-posts__post-title { | ||
color: currentColor; | ||
display: block; | ||
font-weight: bold; | ||
margin-bottom: 8px; | ||
text-decoration: none; | ||
} | ||
|
||
.wp-block-latest-posts__featured-image { | ||
display: table-cell; | ||
|
||
&.aligncenter { | ||
display: block; | ||
margin-bottom: 8px; | ||
margin-left: auto; | ||
margin-right: auto; | ||
max-width: none; | ||
padding-left: 0; | ||
padding-right: 0; | ||
width: 100%; | ||
|
||
img { | ||
max-width: 90%; | ||
width: 100%; | ||
} | ||
} | ||
|
||
&.alignleft { | ||
float: left; | ||
margin-right: 16px; | ||
} | ||
|
||
&.alignright { | ||
float: right; | ||
margin-left: 16px; | ||
} | ||
} | ||
|
||
.wp-block-latest-posts__post-author, | ||
.wp-block-latest-posts__post-date { | ||
display: block; | ||
font-size: 13px; | ||
} | ||
|
||
.wp-block-latest-posts__post-excerpt { | ||
font-size: 14px; | ||
margin-bottom: 8px; | ||
margin-top: 8px; | ||
|
||
> a { | ||
display: none; | ||
} | ||
} | ||
|
||
@media screen and (max-width: 480px) { | ||
li { | ||
display: block; | ||
width: 100%; | ||
} | ||
|
||
img { | ||
max-width: none; | ||
width: 100%; | ||
} | ||
} | ||
} |
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