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

TECH-111: CI/CD and Linting Updates #99

Merged
merged 10 commits into from
Jun 12, 2024
Merged
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
2 changes: 2 additions & 0 deletions ci-templates/.github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ jobs:
code-quality:
if: github.event.pull_request.draft == false
uses: alleyinteractive/.github/.github/workflows/php-code-quality.yml@main
with:
php: 8.2
2 changes: 2 additions & 0 deletions ci-templates/.github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ jobs:
coding-standards:
if: github.event.pull_request.draft == false
uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main
with:
php: 8.2
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
cache: 'npm'
cache-dependency-path: package-lock.json
node-version: 18
node-version: 20

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
cache: 'npm'
cache-dependency-path: package-lock.json
node-version: 18
node-version: 20

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
3 changes: 2 additions & 1 deletion ci-templates/.github/workflows/node-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ jobs:
uses: alleyinteractive/.github/.github/workflows/node-tests.yml@main
with:
ci: true
node: 18
node: 20
npm: 10
run-audit: true
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ includes:
parameters:
# Level 9 is the highest level
level: max
checkGenericClassInNonGenericObjectType: false

scanDirectories:
- plugins/elasticsearch-extensions
Expand All @@ -21,5 +20,7 @@ parameters:
- plugins/create-wordpress-plugin/build/
- plugins/create-wordpress-plugin/src/post-types/
- plugins/create-wordpress-plugin/tests/
- plugins/create-wordpress-plugin/vendor/
- themes/create-wordpress-theme/build/
- themes/create-wordpress-theme/tests/
- themes/create-wordpress-theme/vendor/
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
/**
* Registers the create-wordpress-plugin/theme-faceted-search-facets block using the metadata loaded from the `block.json` file.
*/
function theme_faceted_search_facets_theme_faceted_search_facets_block_init(): void {
function create_wordpress_plugin_theme_faceted_search_facets_block_init(): void {
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
);
}
add_action( 'init', 'theme_faceted_search_facets_theme_faceted_search_facets_block_init' );
add_action( 'init', 'create_wordpress_plugin_theme_faceted_search_facets_block_init' );
22 changes: 17 additions & 5 deletions plugin-templates/blocks/theme-faceted-search-facets/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*
* @phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- File doesn't load in global scope, just appears to to PHPCS.
*
* @phpstan-var array<string, mixed> $attributes
*
* @var array $attributes The array of attributes for this block.
* @var string $content Rendered block output. ie. <InnerBlocks.Content />.
* @var WP_Block $block The instance of the WP_Block class that represents the block being rendered.
Expand All @@ -27,20 +29,30 @@
}

// Negotiate whether any of the facet fields have been set.
$is_facet_set = ! empty( $post_type_aggregation->get_query_values() )
|| ! empty( $category_aggregation->get_query_values() );
$is_facet_set = (
( $post_type_aggregation && $post_type_aggregation->get_query_values() )
|| ( $category_aggregation && $category_aggregation->get_query_values() )
);

?>
<div <?php echo wp_kses_data( get_block_wrapper_attributes() ); ?>>
<h2 class="wp-block-create-wordpress-plugin-theme-faceted-search-facets__heading">
<?php esc_html_e( 'Filter By', 'create-wordpress-plugin' ); ?>
</h2>

<?php $post_type_aggregation->checkboxes(); ?>
<?php
if ( $post_type_aggregation ) :
$post_type_aggregation->checkboxes();
endif;
?>

<?php $category_aggregation->checkboxes(); ?>
<?php
if ( $category_aggregation ) :
$category_aggregation->checkboxes();
endif;
?>

<?php if ( ! empty( $is_facet_set ) ) : ?>
<?php if ( $is_facet_set ) : ?>
<a class="wp-block-create-wordpress-plugin-theme-faceted-search-facets__reset" href="<?php echo esc_url( home_url( '/?s=' ) ); ?>"><?php esc_html_e( 'Reset', 'create-wordpress-plugin' ); ?></a>
<?php endif; ?>
</div>
4 changes: 2 additions & 2 deletions plugin-templates/blocks/theme-faceted-search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
/**
* Registers the create-wordpress-plugin/theme-faceted-search block using the metadata loaded from the `block.json` file.
*/
function theme_faceted_search_theme_faceted_search_block_init(): void {
function create_wordpress_plugin_theme_faceted_search_block_init(): void {
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
);
}
add_action( 'init', 'theme_faceted_search_theme_faceted_search_block_init' );
add_action( 'init', 'create_wordpress_plugin_theme_faceted_search_block_init' );
4 changes: 3 additions & 1 deletion plugin-templates/blocks/theme-faceted-search/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*
* @phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- File doesn't load in global scope, just appears to to PHPCS.
*
* @phpstan-var array<string, mixed> $attributes
*
* @var array $attributes The array of attributes for this block.
* @var string $content Rendered block output. ie. <InnerBlocks.Content />.
* @var WP_Block $block The instance of the WP_Block class that represents the block being rendered.
Expand All @@ -15,5 +17,5 @@

?>
<form role="search" method="get" action="<?php echo esc_url( home_url() ); ?>" id="search-form">
<?php echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Rendered by Gutenberg. ?>
<?php echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Rendered by Gutenberg. ?>
</form>
2 changes: 1 addition & 1 deletion plugin-templates/blocks/theme-navigation/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
wp_nav_menu(
[
'theme_location' => $create_wordpress_plugin_menu_location,
'container' => false,
'container' => '',
'fallback_cb' => false,
]
);
Expand Down
7 changes: 5 additions & 2 deletions plugin-templates/blocks/theme-post-subheadline/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
*
* @phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- File doesn't load in global scope, just appears to to PHPCS.
*
* @phpstan-var array<string, mixed> $attributes
*
* @var array $attributes The array of attributes for this block.
* @var string $content Rendered block output. ie. <InnerBlocks.Content />.
* @var WP_Block $block The instance of the WP_Block class that represents the block being rendered.
*
* @package create-wordpress-plugin
*/
$create_wordpress_plugin_post_id = $block?->context['postId'];

$create_wordpress_plugin_post_id = $block->context['postId'];
if ( empty( $create_wordpress_plugin_post_id ) ) {
return;
}
$subheadline = get_post_meta( $create_wordpress_plugin_post_id, 'create_wordpress_plugin_subheadline', true );

if ( empty( $subheadline ) ) {
if ( ! is_string( $subheadline ) || empty( $subheadline ) ) {
return;
}
?>
Expand Down
4 changes: 2 additions & 2 deletions plugin-templates/blocks/theme-primary-term/block.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "create-wordpress-plugin/primary-term",
"name": "create-wordpress-plugin/theme-primary-term",
"version": "0.1.0",
"title": "Primary Term",
"category": "theme",
Expand Down Expand Up @@ -44,4 +44,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion plugin-templates/blocks/theme-primary-term/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type PostWithPrimaryTerm = WP_REST_API_Post & { // eslint-disable-line camelcase
};

/**
* The create-wordpress-plugin/primary-term block edit function.
* The create-wordpress-plugin/theme-primary-term block edit function.
*
* @return {WPElement} Element to render.
*/
Expand Down
6 changes: 3 additions & 3 deletions plugin-templates/blocks/theme-primary-term/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/

/**
* Registers the create-wordpress-plugin/primary-term block using the metadata loaded from the `block.json` file.
* Registers the create-wordpress-plugin/theme-primary-term block using the metadata loaded from the `block.json` file.
*/
function primary_term_primary_term_block_init(): void {
function create_wordpress_plugin_primary_term_block_init(): void {
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
);
}
add_action( 'init', 'primary_term_primary_term_block_init' );
add_action( 'init', 'create_wordpress_plugin_primary_term_block_init' );
14 changes: 11 additions & 3 deletions plugin-templates/blocks/theme-primary-term/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@
* All of the parameters passed to the function where this file is being required are accessible in this scope:
*
* @phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- File doesn't load in global scope, just appears to to PHPCS.
* @phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited -- File doesn't load in global scope, just appears to to PHPCS.
*
* @phpstan-var array<string, mixed> $attributes
*
* @var array $attributes The array of attributes for this block.
* @var string $content Rendered block output. ie. <InnerBlocks.Content />.
* @var WP_Block $block The instance of the WP_Block class that represents the block being rendered.
*
* @package create-wordpress-plugin
*/
$post_id = isset( $block->context['postId'] ) ? $block->context['postId'] : get_the_ID();

$primary_term_rest = new \Create_WordPress_Plugin\Features\Primary_Term_Rest;
$primary_term = $primary_term_rest->get_primary_term( $post_id, $attributes['taxonomy'] );
$post_id = isset( $block->context['postId'] ) ? $block->context['postId'] : get_the_ID();
$primary_term_rest = new \Create_WordPress_Plugin\Features\Primary_Term_Rest();

if ( ! isset( $attributes['taxonomy'] ) || ! is_string( $attributes['taxonomy'] ) ) {
return;
}

$primary_term = $primary_term_rest->get_primary_term( $post_id, $attributes['taxonomy'] );
if ( ! $primary_term ) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions plugin-templates/blocks/theme-primary-term/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Styles for the create-wordpress-plugin/primary-term block that get applied on both on the front of your site
* Styles for the create-wordpress-plugin/theme-primary-term block that get applied on both on the front of your site
* and in the editor.
*/

.wp-block-create-wordpress-plugin-primary-term {}
.wp-block-create-wordpress-plugin-theme-primary-term {}
4 changes: 2 additions & 2 deletions plugin-templates/blocks/theme-search-meta/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
/**
* Registers the create-wordpress-plugin/theme-search-meta block using the metadata loaded from the `block.json` file.
*/
function theme_faceted_search_meta_theme_faceted_search_meta_block_init(): void {
function create_wordpress_plugin_theme_faceted_search_meta_block_init(): void {
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
);
}
add_action( 'init', 'theme_faceted_search_meta_theme_faceted_search_meta_block_init' );
add_action( 'init', 'create_wordpress_plugin_theme_faceted_search_meta_block_init' );
10 changes: 6 additions & 4 deletions plugin-templates/blocks/theme-search-meta/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
*
* @phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- File doesn't load in global scope, just appears to to PHPCS.
*
* @phpstan-var array<string, mixed> $attributes
*
* @var array $attributes The array of attributes for this block.
* @var string $content Rendered block output. ie. <InnerBlocks.Content />.
* @var WP_Block $block The instance of the WP_Block class that represents the block being rendered.
*
* @package create-wordpress-plugin
*/

global $wp_query;
global $wp_query; // @phpstan-ignore-line

$search_query = get_search_query( false );
$found_posts = $wp_query->found_posts;
Expand All @@ -24,9 +26,9 @@
<?php if ( ! empty( $search_query ) && empty( $found_posts ) ) : ?>
<span class="wp-block-create-wordpress-plugin-theme-search-meta__no-results">
<?php
// translators: %s is the search query.
echo esc_html(
sprintf(
/* translators: %s: search query. */
__( 'No search results found for &lsquo;%s&rsquo;. Try again by using different keywords or adjusting the search filters.', 'create-wordpress-plugin' ),
$search_query
)
Expand All @@ -39,7 +41,7 @@
if ( ! empty( $search_query ) ) :
echo esc_html(
sprintf(
// translators: %1$s is the number of results, %2$s is the search query.
/* translators: 1: number of results, 2: search query. */
_n(
'%1$s result for &lsquo;%2$s&rsquo;',
'%1$s results for &lsquo;%2$s&rsquo;',
Expand All @@ -53,7 +55,7 @@
else :
echo esc_html(
sprintf(
// translators: %s is the number of results.
/* translators: %s number of results. */
_n(
'%s result',
'%s results',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ public function boot(): void {
/**
* Adds the featured image caption to the featured image block.
*
* @phpstan-param array<string, mixed> $block
*
* @param string $block_content The existing block content.
* @param array $block The full block, including name and attributes.
* @param WP_Block $instance The block instance.
*
* @phpstan-param array<string, mixed> $block
*
* @return string Modified block content.
*/
public function add_caption_to_featured_image( string $block_content, array $block, WP_Block $instance ): string {
public function add_caption_to_featured_image( string $block_content, array $block, WP_Block $instance ): string {
$post_id = $instance->context['postId'] ?? null;
if ( empty( $post_id ) ) {
return $block_content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function get_primary_term( int $post_id, string $taxonomy ): array {
}
if ( empty( $primary_term_id ) ) {
$terms = get_the_terms( $post_id, $taxonomy );
if ( ! empty( $terms[0]->term_id ) ) {
if ( is_array( $terms ) && ! empty( $terms[0]->term_id ) ) {
$primary_term_id = $terms[0]->term_id;
}
}
Expand Down