Skip to content

Commit ba86065

Browse files
committed
Fix issues that will lead to pull request tests failure
1 parent 08348bd commit ba86065

File tree

13 files changed

+146
-71
lines changed

13 files changed

+146
-71
lines changed

.npmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
auto-install-peers = true
1+
legacy-peer-deps=true

.phpcs.xml

+6-8
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@
3333
<!-- The version set here matches the minimum version tested in CI. -->
3434
<config name="minimum_supported_wp_version" value="6.2" />
3535

36-
<!-- Define the prefixes that can be used by the plugin -->
37-
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
38-
<properties>
39-
<property name="prefixes" type="array">
40-
<element value="vendor_name" />
41-
<element value="create_wordpress_project" />
42-
</property>
43-
</properties>
36+
<!-- Turn off some rules for scaffolded files. -->
37+
<rule ref="WordPress.NamingConventions.ValidPostTypeSlug.NotStringLiteral">
38+
<exclude-pattern>./plugins/create-wordpress-plugin/src/post-types/</exclude-pattern>
39+
</rule>
40+
<rule ref="WordPressVIPMinimum.Hooks.AlwaysReturnInFilter.AbstractMethod">
41+
<exclude-pattern>./plugins/create-wordpress-plugin/src/post-types/</exclude-pattern>
4442
</rule>
4543
</ruleset>

composer.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,11 @@
7777
],
7878
"phpcs:plugin": "cd plugins/create-wordpress-plugin && phpcs .",
7979
"phpcs:theme": "cd themes/create-wordpress-theme && phpcs .",
80-
"phpstan": "phpstan --memory-limit=512M",
80+
"phpstan": "phpstan --memory-limit=1G",
8181
"phpunit": [
82-
"@phpunit:plugin",
83-
"@phpunit:theme"
82+
"@phpunit:plugin"
8483
],
8584
"phpunit:plugin": "cd plugins/create-wordpress-plugin && phpunit",
86-
"phpunit:theme": "cd themes/create-wordpress-theme && phpunit",
8785
"setup": [
8886
"composer install --quiet --no-interaction"
8987
],

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"plugins/create-wordpress-theme"
66
],
77
"dependencies": {
8-
"@alleyinteractive/block-editor-tools": "^0.5",
9-
"@tinymce/tinymce-react": "4.1",
8+
"@alleyinteractive/block-editor-tools": "^0.6.3",
9+
"@tinymce/tinymce-react": "^4.3.2",
1010
"@wordpress/block-editor": "^12.16.0"
1111
},
1212
"devDependencies": {
@@ -28,7 +28,8 @@
2828
"ts-jest": "^29.1.1",
2929
"turbo": "^1.10.14",
3030
"typescript": "^5.2.2",
31-
"webpack-cli": "^5.1.4"
31+
"webpack-cli": "^5.1.4",
32+
"wp-types": "^3.64.0"
3233
},
3334
"engines": {
3435
"node": "18",
@@ -38,10 +39,10 @@
3839
"name": "create-wordpress-project",
3940
"scripts": {
4041
"build": "turbo run build",
41-
"check-types": "tsc --noEmit",
4242
"create-package": "turbo gen workspace --destination packages --type package",
4343
"lint": "turbo run lint",
4444
"lint:fix": "turbo run lint:fix",
45+
"packages-update": "turbo run packages-update -- --dist-tag=wp-6.4",
4546
"start:hot": "turbo run start:hot",
4647
"start": "turbo run start",
4748
"stylelint": "turbo run stylelint",

phpstan.neon

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ includes:
44
parameters:
55
# Level 9 is the highest level
66
level: max
7+
checkGenericClassInNonGenericObjectType: false
8+
9+
scanDirectories:
10+
- plugins/elasticsearch-extensions
11+
- plugins/wp-asset-manager
712

813
paths:
914
- mu-plugins/000-wp-environment.php
@@ -13,7 +18,8 @@ parameters:
1318
- themes/create-wordpress-theme/
1419

1520
excludePaths:
16-
- plugins/create-wordpress-plugin/tests/
17-
- themes/create-wordpress-theme/tests/
1821
- plugins/create-wordpress-plugin/build/
22+
- plugins/create-wordpress-plugin/src/post-types/
23+
- plugins/create-wordpress-plugin/tests/
1924
- themes/create-wordpress-theme/build/
25+
- themes/create-wordpress-theme/tests/

plugin-templates/.phpcs.xml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Create WordPress Plugin Configuration" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
3+
<description>PHP_CodeSniffer standard for Create WordPress Plugin</description>
4+
5+
<!-- DO NOT ADD ADDITIONAL RULES TO THIS FILE. Modifications belong in the root-level configuration. -->
6+
7+
<!-- Include Root Rules -->
8+
<rule ref="../../.phpcs.xml" />
9+
10+
<rule ref="WordPress.WP.I18n">
11+
<properties>
12+
<!--
13+
Verify that the text_domain is set to the desired text-domain.
14+
Multiple valid text domains can be provided as a comma-delimited list.
15+
-->
16+
<property name="text_domain" type="array" value="create-wordpress-plugin" />
17+
</properties>
18+
</rule>
19+
20+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
21+
<properties>
22+
<property name="prefixes" type="array" value="create_wordpress_plugin" />
23+
</properties>
24+
</rule>
25+
</ruleset>

plugin-templates/blocks/theme-post-subheadline/edit.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type EditProps = {
1111
};
1212

1313
/**
14-
* The create-wordpress-project/theme-post-subheadline block edit function.
14+
* The create-wordpress-plugin/theme-post-subheadline block edit function.
1515
*
1616
* @return {WPElement} Element to render.
1717
*/

plugin-templates/entries/slotfills/subheadline/Subheadline.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Subheadline() {
1818
return (
1919
<PluginDocumentSettingPanel
2020
name="subheadline"
21-
title={__('Subheadline', 'create-wordpress-project')}
21+
title={__('Subheadline', 'create-wordpress-plugin')}
2222
>
2323
{/* @ts-ignore - types are not available for Editor */}
2424
<Editor

plugin-templates/src/features/class-featured-image-caption.php

+21-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
<?php
22
/**
3-
* Featured_Image_Caption class file
3+
* Create WordPress Plugin Features: Featured_Image_Caption class
44
*
55
* @package create-wordpress-plugin
66
*/
77

88
namespace Create_WordPress_Plugin\Features;
9-
use function Create_WordPress_Plugin\register_meta_helper;
109

1110
use Alley\WP\Types\Feature;
11+
use WP_Block;
12+
13+
use function Create_WordPress_Plugin\register_meta_helper;
1214

15+
/**
16+
* Feature: Adds support for captions on featured images.
17+
*
18+
* @package create-wordpress-plugin
19+
*/
1320
final class Featured_Image_Caption implements Feature {
1421
/**
1522
* Boot the feature.
@@ -22,24 +29,27 @@ public function boot(): void {
2229
/**
2330
* Adds the featured image caption to the featured image block.
2431
*
25-
* @param string $block_content The existing block content.
26-
* @param array $block The full block, including name and attributes.
27-
* @param \WP_Block $instance The block instance.
28-
* @return void
32+
* @param string $block_content The existing block content.
33+
* @param array $block The full block, including name and attributes.
34+
* @param WP_Block $instance The block instance.
35+
*
36+
* @phpstan-param array<string, mixed> $block
37+
*
38+
* @return string Modified block content.
2939
*/
30-
public function add_caption_to_featured_image( string $block_content, array $block, \WP_Block $instance ) {
31-
$post_id = isset( $instance->context['postId'] ) ? $instance->context['postId'] : null;
40+
public function add_caption_to_featured_image( string $block_content, array $block, WP_Block $instance ): string {
41+
$post_id = $instance->context['postId'] ?? null;
3242
if ( empty( $post_id ) ) {
3343
return $block_content;
3444
}
3545
$featured_image_caption = get_post_meta( $post_id, 'create_wordpress_plugin_featured_image_caption', true );
3646
if ( empty( $featured_image_caption ) ) {
3747
$featured_image_id = get_post_meta( $post_id, '_thumbnail_id', true );
38-
$featured_image_caption = wp_get_attachment_caption( $featured_image_id );
48+
$featured_image_caption = wp_get_attachment_caption( is_numeric( $featured_image_id ) ? (int) $featured_image_id : 0 );
3949
}
4050

4151
if ( ! empty( $featured_image_caption ) ) {
42-
$block_content = str_replace( '</figure>', '<figcaption class="wp-block-post-featured-image__caption">' . esc_html( $featured_image_caption ) . '</figcaption></figure>', $block_content );
52+
$block_content = str_replace( '</figure>', '<figcaption class="wp-block-post-featured-image__caption">' . esc_html( is_string( $featured_image_caption ) ? $featured_image_caption : '' ) . '</figcaption></figure>', $block_content );
4353
}
4454

4555
return $block_content;
@@ -48,7 +58,7 @@ public function add_caption_to_featured_image( string $block_content, array $blo
4858
/**
4959
* Registers the meta field only for post types that support featured images.
5060
*/
51-
public function add_meta_field() {
61+
public function add_meta_field(): void {
5262
register_meta_helper(
5363
'post',
5464
get_post_types_by_support( 'thumbnail' ),
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
<?php
22
/**
3-
* Primary_Term_Rest class file
3+
* Create WordPress Plugin Features: Primary_Term_Rest class
44
*
55
* @package create-wordpress-plugin
66
*/
77

88
namespace Create_WordPress_Plugin\Features;
9-
use function Create_WordPress_Plugin\register_meta_helper;
109

1110
use Alley\WP\Types\Feature;
11+
use WP_Term;
1212

13+
/**
14+
* Feature: Adds a REST API field for the primary term.
15+
*
16+
* @package create-wordpress-plugin
17+
*/
1318
final class Primary_Term_Rest implements Feature {
1419
/**
1520
* Set up.
1621
*
17-
* @param array $taxonomies The taxonomies to support primary term for.
22+
* @param string[] $taxonomies The taxonomies to support primary term for.
1823
*/
1924
public function __construct(
2025
private readonly array $taxonomies = [ 'category' ],
@@ -28,18 +33,17 @@ public function boot(): void {
2833
}
2934

3035
/**
31-
* Adds support for subheadline to the `post` post type.
32-
* Registers the meta field only for post types that support subheadline.
36+
* Adds the create_wordpress_plugin_primary_term field to the REST API to return the primary term for a post.
3337
*/
34-
public function register_rest_field() {
38+
public function register_rest_field(): void {
3539
register_rest_field(
3640
'post',
3741
'create_wordpress_plugin_primary_term',
3842
[
3943
'get_callback' => [ $this, 'rest_callback' ],
4044
'update_callback' => null,
4145
'schema' => [
42-
'description' => __( 'The primary term for the post.' ),
46+
'description' => __( 'The primary term for the post.', 'create-wordpress-plugin' ),
4347
'type' => [
4448
'term_name' => 'string',
4549
'term_id' => 'integer',
@@ -51,13 +55,18 @@ public function register_rest_field() {
5155
}
5256

5357
/**
54-
* Callback functionf for the rest field.
58+
* Callback function for the REST field.
59+
*
60+
* @param array $request The REST request.
61+
*
62+
* @phpstan-param array{id: int} $request
5563
*
56-
* @param \WP_REST_Reqest $request The rest request.
57-
* @return array
64+
* @return array An array containing taxonomy slugs as keys with term objects as values.
65+
*
66+
* @phpstan-return array<string, array{term_name?: string, term_id?: int, term_link?: string}>
5867
*/
59-
public function rest_callback( $request ) {
60-
$output = [];
68+
public function rest_callback( array $request ): array {
69+
$output = [];
6170
$post_id = $request['id'];
6271
foreach ( $this->taxonomies as $taxonomy ) {
6372
$output[ $taxonomy ] = $this->get_primary_term( $post_id, $taxonomy );
@@ -66,39 +75,46 @@ public function rest_callback( $request ) {
6675
}
6776

6877
/**
69-
* Gets the primary term for the post.
78+
* Gets the primary term for the post for a given taxonomy.
7079
*
71-
* @param int $post_id The post id.
80+
* @param int $post_id The post id.
7281
* @param string $taxonomy The taxonomy to get the primary term for.
73-
* @return array
82+
*
83+
* @return array An array containing the term name, ID, and link.
84+
*
85+
* @phpstan-return array{term_name?: string, term_id?: int, term_link?: string}
7486
*/
75-
public function get_primary_term( $post_id, $taxonomy ) {
87+
public function get_primary_term( int $post_id, string $taxonomy ): array {
88+
$term = [];
7689
if ( function_exists( 'yoast_get_primary_term_id' ) ) {
7790
$primary_term_id = yoast_get_primary_term_id( $taxonomy, $post_id );
7891
}
7992
if ( empty( $primary_term_id ) ) {
8093
$terms = get_the_terms( $post_id, $taxonomy );
81-
if ( ! empty( $terms ) ) {
94+
if ( ! empty( $terms[0]->term_id ) ) {
8295
$primary_term_id = $terms[0]->term_id;
8396
}
8497
}
85-
if ( empty( $primary_term_id ) ) {
86-
$term = [];
87-
} else {
98+
if ( ! empty( $primary_term_id ) ) {
8899
$primary_term = get_term( $primary_term_id, $taxonomy );
89-
$term = [
90-
'term_name' => $primary_term->name,
91-
'term_id' => $primary_term->term_id,
92-
'term_link' => get_term_link( $primary_term ),
93-
];
100+
if ( $primary_term instanceof WP_Term ) {
101+
$term_link = get_term_link( $primary_term );
102+
$term = [
103+
'term_name' => $primary_term->name,
104+
'term_id' => $primary_term->term_id,
105+
'term_link' => ! is_wp_error( $term_link ) ? $term_link : '',
106+
];
107+
}
94108
}
95109
/**
96110
* Filters the primary term for the post.
97111
*
98112
* @param array $term The primary term for the post.
99113
* @param int $id The post ID.
100114
* @param string $taxonomy The taxonomy.
115+
*
116+
* @phpstan-param array{term_name?: string, term_id?: int, term_link?: string} $term
101117
*/
102-
return \apply_filters( 'create_wordpress_plugin_primary_term', $term, $post_id, $taxonomy );
118+
return apply_filters( 'create_wordpress_plugin_primary_term', $term, $post_id, $taxonomy );
103119
}
104120
}

plugin-templates/src/features/class-search-customizations.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
<?php
22
/**
3-
* Search_Customizations class file
3+
* Create WordPress Plugin Features: Search_Customizations class
44
*
55
* @package create-wordpress-plugin
66
*/
77

88
namespace Create_WordPress_Plugin\Features;
9-
use function Create_WordPress_Plugin\register_meta_helper;
109

1110
use Alley\WP\Types\Feature;
11+
use Elasticsearch_Extensions\Controller;
1212

13+
/**
14+
* Feature: Customizes the search experience for the site.
15+
*
16+
* @package create-wordpress-plugin
17+
*/
1318
final class Search_Customizations implements Feature {
1419
/**
1520
* Set up.
1621
*
17-
* @param array $taxonomies The taxonomies to support primary term for.
22+
* @param string[] $post_types A list of post types to restrict the search to.
23+
* @param string[] $taxonomies A list of the taxonomies to enable aggregation for.
1824
*/
1925
public function __construct(
2026
private readonly array $post_types = [ 'post', 'page' ],
@@ -30,8 +36,10 @@ public function boot(): void {
3036

3137
/**
3238
* Configure Elasticsearch Extensions.
39+
*
40+
* @param Controller $es_config The Elasticsearch Extensions configuration object.
3341
*/
34-
public function elasticsearch_extensions_config( $es_config ) {
42+
public function elasticsearch_extensions_config( Controller $es_config ): void {
3543
$es_config->enable_empty_search()
3644
->enable_post_type_aggregation()
3745
->restrict_post_types( $this->post_types );

0 commit comments

Comments
 (0)