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

Blockify everything, prefering HTML+blocks rather than patterns. #1

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
.plugin-card {
.plugin-cards {
list-style: none;
}

.plugin-card,
.plugin-cards > li.plugin {
background-color: #f9f9f9;
margin-bottom: 4%;
margin-block-start: 0;
padding: 15px 15px 8px;
vertical-align: top;

Expand All @@ -20,7 +26,7 @@
vertical-align: top;

@media screen and ( min-width: 21em ) {
width: calc(96% - 128px);
width: calc(95% - 128px);
}
}

Expand Down
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 @@ -415,23 +415,6 @@ function social_meta_data() {
}
add_action( 'wp_head', __NAMESPACE__ . '\social_meta_data' );

/**
* Bold archive terms are made here.
*
* @param string $term The archive term to bold.
* @return string
*/
function strong_archive_title( $term ) {
return '<strong>' . $term . '</strong>';
}
add_action( 'wp_head', function() {
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' );
add_filter( 'single_tag_title', __NAMESPACE__ . '\strong_archive_title' );
add_filter( 'get_the_date', __NAMESPACE__ . '\strong_archive_title' );
} );

/**
* Filter the archive title to use custom string for business model.
*
Expand Down Expand Up @@ -468,3 +451,55 @@ function update_archive_description( $description ) {
* Custom template tags for this theme.
*/
require get_stylesheet_directory() . '/inc/template-tags.php';

// TODO Maybe get_block_type_variations
add_filter( 'register_block_type_args', function( $args ) {
if ( 'core/query-title' === $args['name'] ) {
$args['variations'] ??= [];
$args['variations'][] = [
'name' => 'bolded',
'title' => 'Bolded query',
'attributes' => [
'variantType' => 'bolded',
],
'render_callback' => function( $attributes, $content, $original_render_callback) {
$strong_filter = function( $term ) {
return '<strong>' . $term . '</strong>';
};

foreach ( [ 'post_type_archive_title', 'single_term_title', 'single_cat_title', 'single_tag_title', 'get_the_date' ] as $filter_name ) {
add_filter( $filter_name, $strong_filter );
}

$return = $original_render_callback( $attributes, $content );

foreach ( [ 'post_type_archive_title', 'single_term_title', 'single_cat_title', 'single_tag_title', 'get_the_date' ] as $filter_name ) {
remove_filter( $filter_name, $strong_filter );
}

return $return;
},
];

// A render callback and intercepts and re-routes the render to the individual variation render callback.
$render_callback = $args['render_callback'];
$args['render_callback'] = function( $attributes, $content ) use( $render_callback ) {
$variation = $attributes['variantType'] ?? false;

if ( $variation ) {
$block = \WP_Block_Type_Registry::get_instance()->get_registered( 'core/query-title' );

$variations = $block->get_variations();
$variation = wp_list_filter( $variations, [ 'name' => $variation ] );
if ( ! empty( $variation[0]['render_callback'] ) ) {
$callback = $variation[0]['render_callback'];
return $callback( $attributes, $content, $render_callback );
}
}

return $render_callback( $attributes, $content );
};
}

return $args;
} );
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
@@ -1,5 +1,8 @@
<?php
use WordPressdotorg\Plugin_Directory\Template;
use WP_Query;

global $wp_query;

$sections = array(
'blocks' => __( 'Block-Enabled Plugins', 'wporg-plugins' ),
Expand Down Expand Up @@ -53,15 +56,16 @@
];
}

$section_query = new \WP_Query( $section_args );
$wp_query = new WP_Query( $section_args );

// If the user doesn't have any favorites, omit the section.
if ( 'favorites' === $browse && ! $section_query->have_posts() ) {
if ( 'favorites' === $browse && ! $wp_query->have_posts() ) {
wp_reset_query();
continue;
}
?>

<section class="plugin-section">
<section class="plugin-section plugin-cards">
<header class="section-header">
<h2 class="section-title"><?php echo esc_html( $section_title ); ?></h2>
<a class="section-link" href="<?php echo esc_url( home_url( "browse/$browse/" ) ); ?>">
Expand All @@ -76,15 +80,23 @@
</header>

<?php
while ( $section_query->have_posts() ) :
$section_query->the_post();

get_template_part( 'template-parts/plugin', 'index' );
endwhile;
echo do_blocks( <<<BLOCKS
<!-- wp:query {"tagName":"div","className":"alignfull","layout":{"type":"constrained"}} -->
<div class="wp-block-query alignfull">
<!-- wp:post-template {"className":"plugin-cards"} -->
<!-- wp:wporg/plugin-card /-->
<!-- /wp:post-template -->
</div>
<!-- /wp:query -->
BLOCKS
);
?>
</section>

<?php endforeach; ?>
<?php
wp_reset_query();
endforeach;
?>

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

Expand Down
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,22 @@
<?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' );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
namespace WordPressdotorg\Theme\Plugins_2024\PluginCard;
use WordPressdotorg\Plugin_Directory\Template;

global $post;

$tested_up_to = (string) get_post_meta( $post->ID, 'tested', true );
?>
<div class="entry-thumbnail">
<a href="<?php the_permalink(); ?>" rel="bookmark">
<?php
// phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
echo Template::get_plugin_icon( get_post(), 'html' );
?>
</a>
</div>
<div class="entry">
<header class="entry-header">
<?php the_title( '<h3 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h3>' ); ?>
</header><!-- .entry-header -->

<?php echo wp_kses_post( Template::get_star_rating() ); ?>

<div class="entry-excerpt">
<?php the_excerpt(); ?>
</div><!-- .entry-excerpt -->
</div>
<hr>
<footer>
<span class="plugin-author">
<i class="dashicons dashicons-admin-users"></i> <?php echo esc_html( strip_tags( get_post_meta( get_the_ID(), 'header_author', true ) ) ?: get_the_author() ); ?>
</span>
<span class="active-installs">
<i class="dashicons dashicons-chart-area"></i>
<?php echo esc_html( Template::active_installs() ); ?>
</span>
<?php if ( $tested_up_to ) : ?>
<span class="tested-with">
<i class="dashicons dashicons-wordpress-alt"></i>
<?php
/* translators: WordPress version. */
printf( esc_html__( 'Tested with %s', 'wporg-plugins' ), esc_html( $tested_up_to ) );
?>
</span>
<?php endif; ?>
<span class="last-updated">
<i class="dashicons dashicons-calendar"></i>
<?php
/* Translators: Plugin modified time. */
printf( esc_html__( 'Updated %s ago', 'wporg-plugins' ), esc_html( human_time_diff( get_post_modified_time() ) ) );
?>
</span>
</footer>
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