Skip to content

Commit

Permalink
Tools: Apply phpcs to new theme, fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle committed Apr 11, 2024
1 parent fa15e76 commit 81c9db6
Show file tree
Hide file tree
Showing 27 changed files with 166 additions and 117 deletions.
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<exclude-pattern>*/build/*</exclude-pattern>

<!-- Exclude all themes except the pattern directory theme -->
<exclude-pattern>/wp-content/themes/(?!pattern-directory)</exclude-pattern>
<exclude-pattern>/wp-content/themes/(?!*pattern-directory*)</exclude-pattern>

<!-- Exclude all plugins except the pattern directory plugin -->
<exclude-pattern>/wp-content/plugins/(?!pattern-)</exclude-pattern>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function do_pattern_actions() {
// Reload the page with an error flag.
$url = add_query_arg(
array(
'status' => 'draft-failed'
'status' => 'draft-failed',
),
get_the_permalink()
);
Expand All @@ -109,16 +109,16 @@ function do_pattern_actions() {
);
if ( $success ) {
$args = array(
'status' => 'reported'
'status' => 'reported',
);
} else {
$args = array(
'status' => 'report-failed'
'status' => 'report-failed',
);
}
} else {
$args = array(
'status' => 'logged-out'
'status' => 'logged-out',
);
}

Expand Down Expand Up @@ -387,6 +387,7 @@ function get_patterns_count() {
AND {$wpdb->postmeta}.meta_key = 'wpop_locale'
AND {$wpdb->postmeta}.meta_value = '%s'";

// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$count = $wpdb->get_var( $wpdb->prepare( $sql, $locale ) );
set_transient( $cache_key, $count, $ttl );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
add_filter( 'wporg_block_site_breadcrumbs', __NAMESPACE__ . '\update_site_breadcrumbs' );
add_filter( 'render_block_data', __NAMESPACE__ . '\modify_pattern_include' );

/**
* Register block bindings.
*
* This registers some sources which can be used to dynamically inject content
* into block text or attributes.
*/
function register_block_bindings() {
register_block_bindings_source(
'wporg-pattern/edit-label',
Expand All @@ -33,7 +39,7 @@ function register_block_bindings() {
__( 'Edit <span class="screen-reader-text">"%s"</span>', 'wporg-patterns' ),
get_the_title( $post_id )
);
}
},
)
);

Expand All @@ -45,7 +51,7 @@ function register_block_bindings() {
'get_value_callback' => function( $args, $block ) {
$post_id = $block->context['postId'];
return site_url( "pattern/$post_id/edit/" );
}
},
)
);
}
Expand Down Expand Up @@ -108,10 +114,10 @@ function update_query_total_label( $label, $found_posts ) {
$count = get_patterns_count();

/* translators: %s: the result count. */
return sprintf( _n( '%s pattern', '%s patterns', $count, 'wporg' ), number_format_i18n( $count ) );
return sprintf( _n( '%s pattern', '%s patterns', $count, 'wporg-patterns' ), number_format_i18n( $count ) );
}
/* translators: %s: the result count. */
return _n( '%s pattern', '%s patterns', $found_posts, 'wporg' );
return _n( '%s pattern', '%s patterns', $found_posts, 'wporg-patterns' );
}

/**
Expand All @@ -124,34 +130,34 @@ function get_curation_options( $options ) {
global $wp_query;
$current = strtolower( $wp_query->get( 'curation' ) );

$label = __( 'Filter by', 'wporg' );
$label = __( 'Filter by', 'wporg-patterns' );
switch ( $current ) {
case 'community':
$label = __( 'Community', 'wporg' );
$label = _x( 'Community', 'filter option label', 'wporg-patterns' );
break;
case 'core':
$label = __( 'Curated', 'wporg' );
$label = _x( 'Curated', 'filter option label', 'wporg-patterns' );
break;
default:
$label = __( 'All', 'wporg' );
$label = _x( 'All', 'filter option label', 'wporg-patterns' );
break;
}

// Show the correct filters on the front page.
if ( is_front_page() ) {
$current = 'core';
$label = __( 'Curated', 'wporg' );
$label = _x( 'Curated', 'filter option label', 'wporg-patterns' );
}

return array(
'label' => $label,
'title' => __( 'Filter', 'wporg' ),
'title' => __( 'Filter', 'wporg-patterns' ),
'key' => 'curation',
'action' => get_filter_action_url(),
'options' => array(
'' => __( 'All', 'wporg' ),
'community' => __( 'Community', 'wporg' ),
'core' => __( 'Curated', 'wporg' ),
'' => _x( 'All', 'filter option label', 'wporg-patterns' ),
'community' => _x( 'Community', 'filter option label', 'wporg-patterns' ),
'core' => _x( 'Curated', 'filter option label', 'wporg-patterns' ),
),
'selected' => [ $current ],
);
Expand All @@ -174,38 +180,43 @@ function get_sort_options( $options ) {
$sort = 'favorite_count_desc';
}

$label = __( 'Sort', 'wporg' );
$label = __( 'Sort', 'wporg-patterns' );
switch ( $sort ) {
case 'date_desc':
$label = __( 'Newest', 'wporg' );
$label = __( 'Newest', 'wporg-patterns' );
break;
case 'date_asc':
$label = __( 'Oldest', 'wporg' );
$label = __( 'Oldest', 'wporg-patterns' );
break;
case 'favorite_count_desc':
$label = __( 'Popular', 'wporg' );
$label = __( 'Popular', 'wporg-patterns' );
break;
}

// Show the correct filters on the front page.
if ( is_front_page() ) {
$sort = 'favorite_count_desc';
$label = __( 'Popular', 'wporg' );
$label = __( 'Popular', 'wporg-patterns' );
}

$options = array(
'date_desc' => __( 'Newest', 'wporg' ),
'date_asc' => __( 'Oldest', 'wporg' ),
'date_desc' => __( 'Newest', 'wporg-patterns' ),
'date_asc' => __( 'Oldest', 'wporg-patterns' ),
);

// These pages don't support sorting by favorite count.
if ( ! is_page( [ 'my-patterns', 'favorites' ] ) ) {
$options = array_merge( [ 'favorite_count_desc' => __( 'Popular', 'wporg' ) ], $options );
$options = array_merge(
array(
'favorite_count_desc' => __( 'Popular', 'wporg-patterns' ),
),
$options
);
}

return array(
'label' => $label,
'title' => __( 'Sort', 'wporg' ),
'title' => $label,
'key' => 'orderby',
'action' => get_filter_action_url(),
'options' => $options,
Expand Down Expand Up @@ -241,10 +252,10 @@ function inject_other_filters( $key ) {
}

if ( is_front_page() ) {
if ( $key !== 'curation' ) {
if ( 'curation' !== $key ) {
printf( '<input type="hidden" name="curation" value="core" />' );
}
if ( $key !== 'orderby' ) {
if ( 'orderby' !== $key ) {
printf( '<input type="hidden" name="orderby" value="favorite_count_desc" />' );
}
}
Expand Down Expand Up @@ -304,17 +315,17 @@ function add_site_navigation_menus( $menus ) {
$current_status = isset( $wp_query->query['status'] ) ? $wp_query->query['status'] : false;
$statuses = array(
array(
'label' => __( 'Draft', 'wporg' ),
'label' => __( 'Draft', 'wporg-patterns' ),
'url' => add_query_arg( 'status', 'draft', get_permalink() ),
'className' => 'draft' === $current_status ? 'current-menu-item' : '',
),
array(
'label' => __( 'Pending Review', 'wporg' ),
'label' => __( 'Pending Review', 'wporg-patterns' ),
'url' => add_query_arg( 'status', 'pending', get_permalink() ),
'className' => 'pending' === $current_status ? 'current-menu-item' : '',
),
array(
'label' => __( 'Published', 'wporg' ),
'label' => __( 'Published', 'wporg-patterns' ),
'url' => add_query_arg( 'status', 'publish', get_permalink() ),
'className' => 'publish' === $current_status ? 'current-menu-item' : '',
),
Expand All @@ -327,7 +338,7 @@ function add_site_navigation_menus( $menus ) {
'slug' => array(
// `query` is "Posts".
'featured', 'query', 'text', 'gallery', 'call-to-action',
'banner', 'header', 'footer', 'wireframe'
'banner', 'header', 'footer', 'wireframe',
),
'orderby' => 'slug__in',
)
Expand Down Expand Up @@ -378,13 +389,13 @@ function update_archive_title( $block_content, $block, $instance ) {
if ( ! empty( $term_names ) ) {
$term_names = wp_list_pluck( $term_names, 'name' );
// translators: %s list of terms used for filtering.
$title = sprintf( __( 'Patterns: %s', 'wporg' ), implode( ', ', $term_names ) );
$title = sprintf( __( 'Patterns: %s', 'wporg-patterns' ), implode( ', ', $term_names ) );
} else {
$author = isset( $wp_query->query['author_name'] ) ? get_user_by( 'slug', $wp_query->query['author_name'] ) : false;
if ( $author ) {
$title = sprintf( __( 'Author: %s', 'wporg' ), $author->display_name );
$title = sprintf( __( 'Author: %s', 'wporg-patterns' ), $author->display_name );
} else {
$title = __( 'All patterns', 'wporg' );
$title = __( 'All patterns', 'wporg-patterns' );
}
}

Expand All @@ -410,7 +421,7 @@ function update_archive_title( $block_content, $block, $instance ) {
/**
* Update the archive title for all filter views.
*
* @param string $block_content The block content.
* @param string $block_content The block content.
*/
function update_site_title( $block_content, $block, $instance ) {
return str_replace(
Expand All @@ -432,7 +443,7 @@ function update_site_breadcrumbs( $breadcrumbs ) {
$breadcrumbs = array(
array(
'url' => home_url(),
'title' => __( 'Home', 'wporg' ),
'title' => __( 'Home', 'wporg-patterns' ),
),
);

Expand All @@ -453,7 +464,7 @@ function update_site_breadcrumbs( $breadcrumbs ) {
if ( isset( $wp_query->query['status'] ) ) {
$breadcrumbs[] = array(
'url' => false,
'title' => get_post_status_object( $wp_query->query['status'] )->label
'title' => get_post_status_object( $wp_query->query['status'] )->label,
);
}
return $breadcrumbs;
Expand All @@ -462,11 +473,11 @@ function update_site_breadcrumbs( $breadcrumbs ) {
if ( is_search() ) {
$breadcrumbs[] = array(
'url' => home_url( '/archives/' ),
'title' => __( 'All patterns', 'wporg' ),
'title' => __( 'All patterns', 'wporg-patterns' ),
);
$breadcrumbs[] = array(
'url' => false,
'title' => __( 'Search results', 'wporg' ),
'title' => __( 'Search results', 'wporg-patterns' ),
);
return $breadcrumbs;
}
Expand All @@ -478,13 +489,13 @@ function update_site_breadcrumbs( $breadcrumbs ) {

$breadcrumbs[] = array(
'url' => home_url( '/archives/' ),
'title' => __( 'All patterns', 'wporg' ),
'title' => __( 'All patterns', 'wporg-patterns' ),
);

if ( $author ) {
$breadcrumbs[] = array(
'url' => get_author_posts_url( $author->ID ),
'title' => sprintf( __( 'Author: %s', 'wporg' ), $author->display_name ),
'title' => sprintf( __( 'Author: %s', 'wporg-patterns' ), $author->display_name ),
);
}

Expand All @@ -499,7 +510,7 @@ function update_site_breadcrumbs( $breadcrumbs ) {
}

// Last item should be "current", no URL.
$breadcrumbs[count($breadcrumbs) - 1]['url'] = false;
$breadcrumbs[ count( $breadcrumbs ) - 1 ]['url'] = false;

return $breadcrumbs;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
// phpcs:disable WordPress.Files.FileName -- Allow underscore for pattern partial.
/**
* Title: Footer
* Slug: wporg-pattern-directory-2024/footer
Expand All @@ -11,17 +12,17 @@
<!-- wp:column {"style":{"spacing":{"padding":{"top":"var:preset|spacing|50","right":"var:preset|spacing|edge-space","bottom":"var:preset|spacing|50","left":"var:preset|spacing|edge-space"}},"border":{"right":{"color":"var:preset|color|white-opacity-15","width":"1px"},"top":{},"bottom":{},"left":{}}}} -->
<div class="wp-block-column" style="border-right-color:var(--wp--preset--color--white-opacity-15);border-right-width:1px;padding-top:var(--wp--preset--spacing--50);padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:var(--wp--preset--spacing--50);padding-left:var(--wp--preset--spacing--edge-space)">
<!-- wp:heading {"fontSize":"heading-4"} -->
<h2 class="wp-block-heading has-heading-4-font-size"><?php _e( 'What&#8217;s a pattern?', 'wporg-patterns' ); ?></h2>
<h2 class="wp-block-heading has-heading-4-font-size"><?php esc_html_e( 'What&#8217;s a pattern?', 'wporg-patterns' ); ?></h2>
<!-- /wp:heading -->

<!-- wp:paragraph {"className":"is-style-short-text"} -->
<p class="is-style-short-text"><?php _e( 'A block pattern is a collection of blocks you can insert into your site and customize with your own content. Patterns save you time when composing pages of any kind and are a great way to learn how blocks can be combined to achieve specific layouts.', 'wporg-patterns' ); ?></p>
<p class="is-style-short-text"><?php esc_html_e( 'A block pattern is a collection of blocks you can insert into your site and customize with your own content. Patterns save you time when composing pages of any kind and are a great way to learn how blocks can be combined to achieve specific layouts.', 'wporg-patterns' ); ?></p>
<!-- /wp:paragraph -->

<!-- wp:buttons -->
<div class="wp-block-buttons">
<!-- wp:button {"className":"is-style-outline-on-dark"} -->
<div class="wp-block-button is-style-outline-on-dark"><a class="wp-block-button__link wp-element-button" href="https://wordpress.org/documentation/article/block-pattern/"><?php _e( 'Learn more<span class="screen-reader-text">about using patterns</span>', 'wporg-patterns' ); ?></a></div>
<div class="wp-block-button is-style-outline-on-dark"><a class="wp-block-button__link wp-element-button" href="https://wordpress.org/documentation/article/block-pattern/"><?php echo wp_kses_post( __( 'Learn more<span class="screen-reader-text">about using patterns</span>', 'wporg-patterns' ) ); ?></a></div>
<!-- /wp:button -->
</div>
<!-- /wp:buttons -->
Expand All @@ -31,17 +32,17 @@
<!-- wp:column {"style":{"spacing":{"padding":{"top":"var:preset|spacing|50","right":"var:preset|spacing|edge-space","bottom":"var:preset|spacing|50","left":"var:preset|spacing|edge-space"}}}} -->
<div class="wp-block-column" style="padding-top:var(--wp--preset--spacing--50);padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:var(--wp--preset--spacing--50);padding-left:var(--wp--preset--spacing--edge-space)">
<!-- wp:heading {"fontSize":"heading-4"} -->
<h2 class="wp-block-heading has-heading-4-font-size"><?php _e( 'Share your patterns', 'wporg-patterns' ); ?></h2>
<h2 class="wp-block-heading has-heading-4-font-size"><?php esc_html_e( 'Share your patterns', 'wporg-patterns' ); ?></h2>
<!-- /wp:heading -->

<!-- wp:paragraph {"className":"is-style-short-text"} -->
<p class="is-style-short-text"><?php _e( 'Showcase your creations and make them publicly available in the Block Pattern Directory. Submitting a pattern to the directory means it can be referenced in themes and easily reused across sites—without requiring theme authors to bundle pattern code with each theme.', 'wporg-patterns' ); ?></p>
<p class="is-style-short-text"><?php esc_html_e( 'Showcase your creations and make them publicly available in the Block Pattern Directory. Submitting a pattern to the directory means it can be referenced in themes and easily reused across sites—without requiring theme authors to bundle pattern code with each theme.', 'wporg-patterns' ); ?></p>
<!-- /wp:paragraph -->

<!-- wp:buttons -->
<div class="wp-block-buttons">
<!-- wp:button {"className":"is-style-outline-on-dark"} -->
<div class="wp-block-button is-style-outline-on-dark"><a class="wp-block-button__link wp-element-button" href="<?php echo esc_url( home_url( '/new-pattern/' ) ); ?>"><?php _e( 'Create a pattern', 'wporg-patterns' ); ?></a></div>
<div class="wp-block-button is-style-outline-on-dark"><a class="wp-block-button__link wp-element-button" href="<?php echo esc_url( home_url( '/new-pattern/' ) ); ?>"><?php esc_html_e( 'Create a pattern', 'wporg-patterns' ); ?></a></div>
<!-- /wp:button -->
</div>
<!-- /wp:buttons -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
// phpcs:disable WordPress.Files.FileName -- Allow underscore for pattern partial.
/**
* Title: Pattern Grid (Favorites)
* Slug: wporg-pattern-directory-2024/grid-favorites
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
// phpcs:disable WordPress.Files.FileName -- Allow underscore for pattern partial.
/**
* Title: Pattern Grid (Front Page)
* Slug: wporg-pattern-directory-2024/grid-front-page
Expand All @@ -14,7 +15,7 @@
<div class="wp-block-group alignwide">
<!-- wp:group {"layout":{"type":"flex","flexWrap":"wrap"}} -->
<div class="wp-block-group">
<!-- wp:search {"showLabel":false,"placeholder":"<?php esc_html_e( 'Search patterns', 'wporg-patterns' ); ?>","width":100,"widthUnit":"%","buttonText":"<?php esc_html_e( 'Search', 'wporg' ); ?>","buttonPosition":"button-inside","buttonUseIcon":true,"className":"is-style-secondary-search-control"} /-->
<!-- wp:search {"showLabel":false,"placeholder":"<?php esc_html_e( 'Search patterns', 'wporg-patterns' ); ?>","width":100,"widthUnit":"%","buttonText":"<?php esc_html_e( 'Search', 'wporg-patterns' ); ?>","buttonPosition":"button-inside","buttonUseIcon":true,"className":"is-style-secondary-search-control"} /-->

<!-- wp:wporg/query-total /-->
</div>
Expand Down Expand Up @@ -54,7 +55,7 @@
<!-- wp:group {"align":"wide","style":{"spacing":{"padding":{"top":"var:preset|spacing|40","bottom":"var:preset|spacing|40"},"margin":{"top":"var:preset|spacing|40"}},"elements":{"link":{"color":{"text":"var:preset|color|charcoal-0"}}}},"textColor":"charcoal-0","layout":{"type":"default"}} -->
<div class="wp-block-group alignwide has-charcoal-0-color has-text-color has-link-color" style="margin-top:var(--wp--preset--spacing--40);padding-top:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--40)">
<!-- wp:heading {"style":{"typography":{"fontStyle":"normal","fontWeight":"300","letterSpacing":"-2px"}},"className":"is-style-with-arrow","fontSize":"heading-1","fontFamily":"inter"} -->
<h2 class="wp-block-heading is-style-with-arrow has-inter-font-family has-heading-1-font-size" style="font-style:normal;font-weight:300;letter-spacing:-2px"><a href="<?php echo esc_url( home_url( '/archives/' ) ); ?>"><?php _e( 'View all patterns', 'wporg' ); ?></a></h2>
<h2 class="wp-block-heading is-style-with-arrow has-inter-font-family has-heading-1-font-size" style="font-style:normal;font-weight:300;letter-spacing:-2px"><a href="<?php echo esc_url( home_url( '/archives/' ) ); ?>"><?php esc_html_e( 'View all patterns', 'wporg-patterns' ); ?></a></h2>
<!-- /wp:heading -->
</div>
<!-- /wp:group -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
// phpcs:disable WordPress.Files.FileName -- Allow underscore for pattern partial.
/**
* Title: Pattern Grid (Mine)
* Slug: wporg-pattern-directory-2024/grid-mine
Expand Down
Loading

0 comments on commit 81c9db6

Please sign in to comment.