Skip to content

Commit

Permalink
fix(post-meta): use block registry for conditional content (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasguillot authored Jun 19, 2024
1 parent 8bf31f5 commit 3e4c738
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
11 changes: 6 additions & 5 deletions patterns/post-meta-multiple-lines-avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
* @package Newspack_Block_Theme
*/

$registry = WP_Block_Type_Registry::get_instance();
?>
<!-- wp:group {"metadata":{"name":"Post Meta"},"style":{"spacing":{"blockGap":"var:preset|spacing|20"}},"className":"post-meta","layout":{"type":"flex","flexWrap":"wrap","justifyContent":"space-between","verticalAlignment":"bottom"}} -->
<div class="wp-block-group post-meta">

<!-- wp:group {"lock":{"move":false,"remove":true},"metadata":{"name":"Meta"},"style":{"spacing":{"blockGap":"var:preset|spacing|20"}},"layout":{"type":"flex","flexWrap":"nowrap","verticalAlignment":"center"}} -->
<div class="wp-block-group">

<?php if ( class_exists( 'CoAuthors_Guest_Authors' ) ) : ?>
<?php if ( $registry->get_registered( 'co-authors-plus/coauthors' ) ) : ?>

<!-- wp:co-authors-plus/coauthors {"layout":{"type":"flex","orientation":"horizontal","flexWrap":"nowrap"},"lock":{"move":true,"remove":true},"style":{"layout":{"selfStretch":"fit"},"spacing":{"blockGap":"0"}},"className":"cap-avatar"} -->
<div class="wp-block-co-authors-plus-coauthors cap-avatar"><!-- wp:co-authors-plus/avatar {"size":48} /--></div>
<!-- /wp:co-authors-plus/coauthors -->
Expand All @@ -31,7 +32,7 @@
<!-- wp:group {"templateLock":"all","lock":{"move":true,"remove":true},"metadata":{"name":"Byline + Date"},"style":{"spacing":{"blockGap":"4px"}},"layout":{"type":"flex","orientation":"vertical"}} -->
<div class="wp-block-group">

<?php if ( class_exists( 'CoAuthors_Guest_Authors' ) ) : ?>
<?php if ( $registry->get_registered( 'co-authors-plus/coauthors' ) ) : ?>

<!-- wp:co-authors-plus/coauthors -->
<div class="wp-block-co-authors-plus-coauthors"><!-- wp:co-authors-plus/name {"isLink":true} /--></div>
Expand All @@ -47,7 +48,7 @@
<!-- /wp:group --></div>
<!-- /wp:group -->

<?php if ( function_exists( 'sharing_display' ) ) : ?>
<?php if ( $registry->get_registered( 'jetpack/sharing-buttons' ) ) : ?>

<!-- wp:jetpack/sharing-buttons {"styleType":"icon","layout":{"type":"flex","justifyContent":"left","flexWrap":"nowrap"}} -->
<ul class="wp-block-jetpack-sharing-buttons has-normal-icon-size jetpack-sharing-buttons__services-list" id="jetpack-sharing-serivces-list">
Expand Down
7 changes: 4 additions & 3 deletions patterns/post-meta-multiple-lines.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
* @package Newspack_Block_Theme
*/

$registry = WP_Block_Type_Registry::get_instance();
?>
<!-- wp:group {"metadata":{"name":"Post Meta"},"style":{"spacing":{"blockGap":"var:preset|spacing|20"}},"className":"post-meta","layout":{"type":"flex","flexWrap":"wrap","justifyContent":"space-between","verticalAlignment":"bottom"}} -->
<div class="wp-block-group post-meta">

<!-- wp:group {"lock":{"move":false,"remove":true},"metadata":{"name":"Meta"},"style":{"spacing":{"blockGap":"4px"}},"layout":{"type":"flex","orientation":"vertical"}} -->
<div class="wp-block-group">

<?php if ( class_exists( 'CoAuthors_Guest_Authors' ) ) : ?>
<?php if ( $registry->get_registered( 'co-authors-plus/coauthors' ) ) : ?>

<!-- wp:co-authors-plus/coauthors {"lock":{"move":true,"remove":true}} -->
<div class="wp-block-co-authors-plus-coauthors"><!-- wp:co-authors-plus/name {"isLink":true,"lock":{"move":true,"remove":true}} /--></div>
Expand All @@ -31,7 +32,7 @@
<!-- wp:post-date {"format":"F j, Y","lock":{"move":true,"remove":true}} /--></div>
<!-- /wp:group -->

<?php if ( function_exists( 'sharing_display' ) ) : ?>
<?php if ( $registry->get_registered( 'jetpack/sharing-buttons' ) ) : ?>

<!-- wp:jetpack/sharing-buttons {"styleType":"icon","layout":{"type":"flex","justifyContent":"left","flexWrap":"nowrap"}} -->
<ul class="wp-block-jetpack-sharing-buttons has-normal-icon-size jetpack-sharing-buttons__services-list" id="jetpack-sharing-serivces-list">
Expand Down
11 changes: 6 additions & 5 deletions patterns/post-meta-single-line-avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
* @package Newspack_Block_Theme
*/

$registry = WP_Block_Type_Registry::get_instance();
?>
<!-- wp:group {"metadata":{"name":"Post Meta"},"style":{"spacing":{"blockGap":"var:preset|spacing|30"}},"className":"post-meta","layout":{"type":"constrained"}} -->
<div class="wp-block-group post-meta">

<!-- wp:group {"lock":{"move":false,"remove":true},"metadata":{"name":"Meta"},"style":{"spacing":{"blockGap":"var:preset|spacing|30"}},"layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"center","verticalAlignment":"center"}} -->
<div class="wp-block-group">
<?php if ( class_exists( 'CoAuthors_Guest_Authors' ) ) : ?>

<?php if ( $registry->get_registered( 'co-authors-plus/coauthors' ) ) : ?>

<!-- wp:group {"templateLock":"all","lock":{"move":true,"remove":true},"metadata":{"name":"Avatar + Byline"},"style":{"spacing":{"blockGap":"var:preset|spacing|20"}},"layout":{"type":"flex","flexWrap":"nowrap"}} -->
<div class="wp-block-group">

<!-- wp:co-authors-plus/coauthors {"layout":{"type":"flex","orientation":"horizontal"},"prefix":"","style":{"spacing":{"blockGap":"0"}},"className":"cap-avatar"} -->
<div class="wp-block-co-authors-plus-coauthors cap-avatar"><!-- wp:co-authors-plus/avatar /--></div>
<!-- /wp:co-authors-plus/coauthors -->
Expand All @@ -45,7 +46,7 @@
<!-- wp:post-date {"lock":{"move":true,"remove":true}} /--></div>
<!-- /wp:group -->

<?php if ( function_exists( 'sharing_display' ) ) : ?>
<?php if ( $registry->get_registered( 'jetpack/sharing-buttons' ) ) : ?>

<!-- wp:jetpack/sharing-buttons {"styleType":"icon","layout":{"type":"flex","justifyContent":"center"}} -->
<ul class="wp-block-jetpack-sharing-buttons has-normal-icon-size jetpack-sharing-buttons__services-list" id="jetpack-sharing-serivces-list">
Expand Down
11 changes: 6 additions & 5 deletions patterns/post-meta-single-line.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
* @package Newspack_Block_Theme
*/

$registry = WP_Block_Type_Registry::get_instance();
?>
<!-- wp:group {"metadata":{"name":"Post Meta"},"style":{"spacing":{"blockGap":"var:preset|spacing|30"}},"className":"post-meta","layout":{"type":"constrained"}} -->
<div class="wp-block-group post-meta">

<!-- wp:group {"lock":{"move":false,"remove":true},"metadata":{"name":"Meta"},"style":{"spacing":{"blockGap":"var:preset|spacing|30"}},"layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"center","verticalAlignment":"center"}} -->
<div class="wp-block-group">

<?php if ( class_exists( 'CoAuthors_Guest_Authors' ) ) : ?>
<?php if ( $registry->get_registered( 'co-authors-plus/coauthors' ) ) : ?>

<!-- wp:co-authors-plus/coauthors {"lock":{"move":true,"remove":true}} -->
<div class="wp-block-co-authors-plus-coauthors"><!-- wp:co-authors-plus/name {"isLink":true,"lock":{"move":true,"remove":true}} /--></div>

<!-- /wp:co-authors-plus/coauthors -->

<?php else : ?>
Expand All @@ -36,7 +37,7 @@
<!-- wp:post-date {"lock":{"move":true,"remove":true}} /--></div>
<!-- /wp:group -->

<?php if ( function_exists( 'sharing_display' ) ) : ?>
<?php if ( $registry->get_registered( 'jetpack/sharing-buttons' ) ) : ?>

<!-- wp:jetpack/sharing-buttons {"styleType":"icon","layout":{"type":"flex","justifyContent":"center"}} -->
<ul class="wp-block-jetpack-sharing-buttons has-normal-icon-size jetpack-sharing-buttons__services-list" id="jetpack-sharing-serivces-list">
Expand All @@ -49,4 +50,4 @@
<?php endif; ?>

</div>
<!-- /wp:group -->
<!-- /wp:group -->

0 comments on commit 3e4c738

Please sign in to comment.