Skip to content

Commit

Permalink
Block theme: Hide the 'draft' button if the pattern is already a draft
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle committed Apr 15, 2024
1 parent 33a81cc commit ff70012
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
add_action( 'template_redirect', __NAMESPACE__ . '\redirect_term_archives' );
add_action( 'wp_head', __NAMESPACE__ . '\add_social_meta_tags', 5 );
add_filter( 'document_title_parts', __NAMESPACE__ . '\set_document_title' );
add_filter( 'body_class', __NAMESPACE__ . '\add_status_body_class' );

add_action(
'init',
Expand Down Expand Up @@ -552,3 +553,23 @@ function set_document_title( $title ) {

return $title;
}

/**
* Filter the body class on single "owned" patterns.
*
* This allows for hiding some status-specific buttons.
*
* @param string[] $classes An array of body class names.
*
* @return string[] Filtered classes.
*/
function add_status_body_class( $classes ) {
if ( ! is_singular( POST_TYPE ) || get_current_user_id() !== get_the_author_meta( 'ID' ) ) {
return $classes;
}
$status = get_post_status();
if ( $status ) {
$classes[] = 'is-status-' . $status;
}
return $classes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
<div class="wp-block-button is-style-toggle is-small"><a href="[pattern_edit_link]" class="wp-block-button__link wp-element-button"><?php esc_html_e( 'Edit', 'wporg-patterns' ); ?></a></div>
<!-- /wp:button -->

<!-- wp:button {"className":"is-style-toggle is-small"} -->
<div class="wp-block-button is-style-toggle is-small"><a href="[pattern_draft_link]" class="wp-block-button__link wp-element-button"><?php esc_html_e( 'Revert to draft', 'wporg-patterns' ); ?></a></div>
<!-- wp:button {"className":"is-style-toggle is-small is-draft-button"} -->
<div class="wp-block-button is-style-toggle is-small is-draft-button"><a href="[pattern_draft_link]" class="wp-block-button__link wp-element-button"><?php esc_html_e( 'Revert to draft', 'wporg-patterns' ); ?></a></div>
<!-- /wp:button -->

<!-- wp:wporg/delete-button /-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ body.page .wp-block-wporg-local-navigation-bar .wp-block-query-title {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='25' fill='none' viewBox='0 0 24 25'%3E%3Cpath fill='%23ffffff' d='m19 7.478-3-3-8.5 8.5-1 4 4-1 8.5-8.5ZM12 18.978H5v1.5h7v-1.5Z'/%3E%3C/svg%3E");
}

/* Hide the draft button if we're already on a draft. */
body.single-wporg-pattern.is-status-draft .is-draft-button {
display: none;
}

/* Style the pattern grid. */
.wp-block-query .wp-block-post-title {
flex-shrink: 1;
Expand Down

0 comments on commit ff70012

Please sign in to comment.