Skip to content

Commit

Permalink
Blockify everything, prefering HTML+blocks rather than patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
dd32 committed Mar 1, 2024
1 parent 26128cb commit f1a0127
Show file tree
Hide file tree
Showing 27 changed files with 2,048 additions and 212 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.plugin-card {
background-color: #f9f9f9;
margin-bottom: 4%;
margin-block-start: 0;
padding: 15px 15px 8px;
vertical-align: top;

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@


// Block Files
require_once( __DIR__ . '/src/blocks/archive-page/index.php' );
require_once( __DIR__ . '/src/blocks/filter-bar/index.php' );
require_once( __DIR__ . '/src/blocks/front-page/index.php' );
require_once( __DIR__ . '/src/blocks/search-page/index.php' );
require_once( __DIR__ . '/src/blocks/single-plugin/index.php' );
require_once( __DIR__ . '/src/blocks/plugin-card/index.php' );
require_once( __DIR__ . '/src/blocks/missing-template-tag/index.php' );

// Block Configs
require_once( __DIR__ . '/inc/block-config.php' );
Expand Down Expand Up @@ -425,6 +425,7 @@ function strong_archive_title( $term ) {
return '<strong>' . $term . '</strong>';
}
add_action( 'wp_head', function() {
// TODO: This no longer fires, as it's rendered before `wp_head` when using blocks.
add_filter( 'post_type_archive_title', __NAMESPACE__ . '\strong_archive_title' );
add_filter( 'single_term_title', __NAMESPACE__ . '\strong_archive_title' );
add_filter( 'single_cat_title', __NAMESPACE__ . '\strong_archive_title' );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +0,0 @@
<?php
/**
* The main template file.
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists.
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package WordPressdotorg\Plugin_Directory\Theme
*/

namespace WordPressdotorg\Plugin_Directory\Theme;

get_header();
?>

<main id="main" class="site-main" role="main">

<?php
if ( have_posts() ) :
if ( is_home() && ! is_front_page() ) :
?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php
endif;

/* Start the Loop */
while ( have_posts() ) :
the_post();

get_template_part( 'template-parts/plugin', 'index' );
endwhile;

the_posts_pagination();

else :
get_template_part( 'template-parts/no-results' );
endif;
?>

</main><!-- #main -->

<?php
get_footer();
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "wporg/missing-template-tag",
"version": "0.1.0",
"title": "Missing Template Tag",
"category": "design",
"icon": "",
"description": "A block that executes a missing template tag.",
"textdomain": "wporg",
"attributes": {
"function": {
"type": "string",
"enum": [
"the_posts_pagination",
"the_archive_description"
]
},
"args": {
"type": "array"
}
},
"supports": {
"html": false
},
"editorScript": "file:./index.js",
"render": "file:./render.php"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @package wporg
*/

namespace WordPressdotorg\Theme\Plugins_2024\SearchPage;
namespace WordPressdotorg\Theme\Plugins_2024\MissingTemplateTag;

add_action( 'init', __NAMESPACE__ . '\init' );

Expand All @@ -18,5 +18,5 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function init() {
register_block_type( __DIR__ . '/../../../js/build/blocks/search-page' );
register_block_type( __DIR__ . '/../../../js/build/blocks/missing-template-tag' );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$function = $attributes['function'] ?? false;
$args = $attributes['args'] ?? [];
$valid_functions = [
'the_posts_pagination',
'the_archive_description'
];

// Validated by block.json enum, but duplicated here.
if ( $function && in_array( $function, $valid_functions ) && function_exists( $function ) ) {
call_user_func_array( $function, $args );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "wporg/plugin-card",
"version": "0.1.0",
"title": "Single Plugin Card",
"category": "design",
"icon": "",
"description": "A block that displays the single plugin card",
"textdomain": "wporg",
"attributes": {},
"supports": {
"html": false
},
"usesContext": [
"postId"
],
"editorScript": "file:./index.js",
"render": "file:./render.php"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Block Name: Single Plugin
* Description: The content that is displayed on the single plugin page
*
* @package wporg
*/

namespace WordPressdotorg\Theme\Plugins_2024\PluginCard;

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( __DIR__ . '/../../../js/build/blocks/plugin-card' );
}

// TODO: Figure out how to add a post_class for wrapping a block...
add_filter( 'render_block_core/post-template', function( $html, $block ) {
// If the post-template has the 'plugin-cards' class, add the 'plugin-card' class to the child blocks
if ( ! empty( $block['attrs']['className'] ) && str_contains( $block['attrs']['className'], 'plugin-cards' ) ) {
$html = str_replace( 'class="wp-block-post ', 'class="wp-block-post plugin-card ', $html );
}

return $html;
}, 10, 2 );
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
get_template_part( 'template-parts/plugin' );
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-element'), 'version' => '43ab82ac4ef93561f4cc');
<?php return array('dependencies' => array('react', 'wp-element'), 'version' => '4967f0d80ed01cf03524');
Loading

0 comments on commit f1a0127

Please sign in to comment.