Skip to content

Commit 9ff8d6f

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feature/wp-scripts
2 parents 9d9cd54 + fec28ff commit 9ff8d6f

File tree

5 files changed

+103
-8
lines changed

5 files changed

+103
-8
lines changed

.deployignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ output.log
1212
tests
1313
bin
1414
composer.lock
15-
phpcs.xml
15+
.phpcs.xml
1616
phpunit.xml
1717
configure.php
1818
DOCKER_ENV

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Via WPCS.
77
#
88
/.github export-ignore
9-
/phpcs.xml export-ignore
9+
/.phpcs.xml export-ignore
1010
/.phpcs export-ignore
1111
/phpunit.xml export-ignore
1212
/tests export-ignore
File renamed without changes.

configure.php

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
/**
44
* Configure the WordPress Plugin interactively.
55
*
6+
* Supports arguments to set the values directly.
7+
*
8+
* [--author_name=<author_name>]
9+
* : The author name.
10+
*
11+
* [--author_email=<author_email>]
12+
* : The author email.
13+
*
614
* phpcs:disable
715
*/
816

@@ -14,6 +22,34 @@
1422
die( 'Not supported in Windows. 🪟' );
1523
}
1624

25+
if ( version_compare( PHP_VERSION, '8.0.0', '<' ) ) {
26+
die( 'PHP 8.0.0 or greater is required.' );
27+
}
28+
29+
// Parse the command line arguments from $argv.
30+
$args = [];
31+
$previous_key = null;
32+
33+
foreach ( $argv as $value ) {
34+
if ( str_starts_with( $value, '--' ) ) {
35+
if ( false !== strpos( $value, '=' ) ) {
36+
[ $arg, $value ] = explode( '=', substr( $value, 2 ), 2 );
37+
38+
$args[ $arg ] = trim( $value );
39+
40+
$previous_key = null;
41+
} else {
42+
$args[ substr( $value, 2 ) ] = true;
43+
44+
$previous_key = substr( $value, 2 );
45+
}
46+
} elseif ( ! empty( $previous_key ) ) {
47+
$args[ $previous_key ] = trim( $value );
48+
} else {
49+
$previous_key = trim( $value );
50+
}
51+
}
52+
1753
function ask( string $question, string $default = '', bool $allow_empty = true ): string {
1854
$answer = readline(
1955
$question . ( $default ? " [{$default}]" : '' ) . ': '
@@ -136,6 +172,38 @@ function remove_project_files() {
136172
echo 'Removed .buddy, buddy.yml, CHANGELOG.md, .deployignore, .editorconfig, .gitignore, .gitattributes, .github and LICENSE files.' . PHP_EOL;
137173
}
138174

175+
function rollup_phpcs_to_parent( string $parent_file, string $local_file, string $plugin_name, string $plugin_domain ) {
176+
$config = '<?xml version="1.0"?>
177+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="' . $plugin_name . ' Configuration" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
178+
<description>PHP_CodeSniffer standard for ' . $plugin_name . '</description>
179+
180+
<!-- DO NOT ADD ADDITIONAL RULES TO THIS FILE. Modifications belong in the root-level configuration. -->
181+
182+
<!-- Include Root Rules -->
183+
<rule ref="' . $parent_file . '" />
184+
185+
<rule ref="WordPress.WP.I18n">
186+
<properties>
187+
<!--
188+
Verify that the text_domain is set to the desired text-domain.
189+
Multiple valid text domains can be provided as a comma-delimited list.
190+
-->
191+
<property name="text_domain" type="array" value="' . $plugin_domain . '" />
192+
</properties>
193+
</rule>
194+
195+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
196+
<properties>
197+
<property name="prefixes" type="array" value="' . $plugin_domain . '" />
198+
</properties>
199+
</rule>
200+
</ruleset>';
201+
202+
if ( file_put_contents( $local_file, $config ) ) {
203+
echo "Updated {$local_file}.\n";
204+
}
205+
}
206+
139207
function remove_assets_readme( bool $keep_contents, string $file = 'README.md' ) {
140208
$contents = file_get_contents( $file );
141209

@@ -198,13 +266,13 @@ function delete_files( string|array $paths ) {
198266

199267
$author_name = ask(
200268
question: 'Author name?',
201-
default: run( 'git config user.name' ),
269+
default: $args['author_name'] ?? run( 'git config user.name' ),
202270
allow_empty: false,
203271
);
204272

205273
$author_email = ask(
206274
question: 'Author email?',
207-
default: run( 'git config user.email' ),
275+
default: $args['author_email'] ?? run( 'git config user.email' ),
208276
allow_empty: false,
209277
);
210278

@@ -342,8 +410,8 @@ function delete_files( string|array $paths ) {
342410
remove_assets_buddy();
343411
}
344412

345-
if ( confirm( 'Will this plugin be using Composer? (WordPress Composer Autoloader already included!)', true ) ) {
346-
$uses_composer = true;
413+
if ( confirm( 'Will this plugin be using Composer? (WordPress Composer Autoloader already included! phpcs and phpunit also rely on Composer being installed for testing.)', true ) ) {
414+
$uses_composer = true;
347415
$needs_built_assets = true;
348416

349417
if ( confirm( 'Do you want to run `composer install`?', true ) ) {
@@ -368,7 +436,9 @@ function delete_files( string|array $paths ) {
368436
$standalone = true;
369437

370438
// Check if the plugin will be use standalone (as a single repository) or as a
371-
// part of larger project (such as a wp-content-rooted project).
439+
// part of larger project (such as a wp-content-rooted project). Assumes that
440+
// the parent project is located at /wp-content/ and this plugin is located at
441+
// /wp-content/plugins/:plugin/.
372442
if (
373443
file_exists( '../../.git/index' )
374444
&& ! confirm(
@@ -417,6 +487,31 @@ function delete_files( string|array $paths ) {
417487
echo "\n\n";
418488
}
419489
}
490+
491+
$parent_files = [
492+
$parent_folder . '/phpcs.xml',
493+
$parent_folder . '/phpcs.xml.dist',
494+
$parent_folder . '/.phpcs.xml',
495+
];
496+
497+
if ( file_exists( __DIR__ . '/.phpcs.xml' ) ) {
498+
foreach ( $parent_files as $parent_file ) {
499+
if ( ! file_exists( $parent_file ) ) {
500+
continue;
501+
}
502+
503+
if ( confirm( "Do you want to roll up the phpcs configuration to the parent? (This will change the plugin's phpcs configuration to inherit the parent configuration from {$parent_file}.)" ) ) {
504+
rollup_phpcs_to_parent(
505+
parent_file: '../../' . basename( $parent_file ),
506+
local_file: __DIR__ . '/.phpcs.xml',
507+
plugin_name: $plugin_name,
508+
plugin_domain: $plugin_name_slug,
509+
);
510+
511+
break;
512+
}
513+
}
514+
}
420515
}
421516
}
422517

src/meta.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function register_meta_helper(
7272
* @param string $meta_key The meta key to register.
7373
*/
7474
$args = apply_filters(
75-
'ai_register_meta_helper_args', // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
75+
'create_wordpress_plugin_register_meta_helper_args', // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
7676
wp_parse_args(
7777
$args,
7878
[

0 commit comments

Comments
 (0)