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

Misc Changes #166

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ fabric.properties
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
!.vscode/*.code-workspace

# Local History for Visual Studio Code
.history/
Expand Down
13 changes: 13 additions & 0 deletions .vscode/wp-starter.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"folders": [
{
"path": "../"
}
],
"settings": {
"files.trimTrailingWhitespace": true,
"files.associations": {
"*.css": "tailwindcss"
}
}
}
21 changes: 19 additions & 2 deletions bin/composer-scripts/ProjectEvents/PostCreateProjectScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ public static function updateProjectFiles(): void {
}
}

$defaultWorkspace = self::translatePath( '.vscode/' . self::$defaults['theme-slug'] . '.code-workspace' );
$projectWorkspace = self::translatePath( '.vscode/' . self::$info['slug'] . '.code-workspace' );

// Change the project workspace name.
if ( ! rename( $defaultWorkspace, $projectWorkspace ) ) {
self::writeError( 'Failed to rename project workspace.' );
} else {
self::writeInfo( 'Project workspace name changed.' );
}

self::writeInfo( 'Project files updated!' );
}

Expand Down Expand Up @@ -543,7 +553,7 @@ private static function removeGithubFiles(): void {
$deployFile = self::translatePath( '.github/workflows/deploy.yaml', true );

if ( ! file_exists( $deployFile ) ) {
self::writeWarning( 'Deployment script not found. Skipping removal.' );
self::writeWarning( sprintf( 'Deployment script not found (%s). Skipping removal.', $deployFile ) );
} else {
unlink( $deployFile );
self::writeInfo( 'Deployment script removed.' );
Expand All @@ -552,12 +562,19 @@ private static function removeGithubFiles(): void {
$componentTemplate = self::translatePath( '.github/ISSUE_TEMPLATE/new-component-ticket.md', true );

if ( ! file_exists( $componentTemplate ) ) {
self::writeWarning( 'Component Issue template not found. Skipping removal.' );
self::writeWarning( sprintf( 'Component Issue template not found (%s). Skipping removal.', $componentTemplate ) );
} else {
unlink( $componentTemplate );
self::writeInfo( 'Component Issue template removed.' );
}

$releaseFile = self::translatePath( '.github/workflows/release.yaml', true );

if ( ! file_exists( $releaseFile ) ) {
self::writeWarning( sprintf( 'Release script not found (%s). Skipping removal.', $releaseFile ) );
} else {
unlink( $releaseFile );
self::writeInfo( 'Release script removed.' );
}
}
}
2 changes: 0 additions & 2 deletions bin/composer-scripts/ProjectEvents/PostInstallScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ class PostInstallScript extends ComposerScript {
* @var array
*/
private static array $activatePlugins = [
'accessibility-checker' => 'Accessibility Checker',
'viget-blocks-toolkit' => [
'name' => 'Viget Blocks Toolkit',
'dependencies' => [
'advanced-custom-fields-pro' => 'Advanced Custom Fields Pro',
],
],
'seo-by-rank-math' => 'Rank Math SEO',
'safe-svg' => 'Safe SVG',
];

Expand Down
2 changes: 1 addition & 1 deletion bin/composer-scripts/ProjectEvents/PreScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function preUpdate( Event $event ): void {
*/
private static function checkRepoPlugins(): void {
foreach ( self::$repoPlugins as $packageName => $pluginDir ) {
$pluginGitDir = self::translatePath( 'wp-content/plugins/' . $pluginDir . '/.git' );
$pluginGitDir = self::translatePath( 'wp-content/plugins/' . $pluginDir . '/.git', true );
if ( is_dir( $pluginGitDir ) ) {
self::writeInfo( sprintf( 'Skipping installation of %s: directory containing repository exists.', $packageName ) );

Expand Down
28 changes: 6 additions & 22 deletions wp-content/themes/wp-starter/.phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,17 @@
#############################################################################
-->

<!-- Include the WordPress-Extra standard. -->
<rule ref="WordPress-Extra">
<!--
We may want a middle ground though. The best way to do this is add the
entire ruleset, then rule by rule, remove ones that don't suit a project.
We can do this by running `phpcs` with the '-s' flag, which allows us to
see the names of the sniffs reporting errors.
Once we know the sniff names, we can opt to exclude sniffs which don't
suit our project like so.

The below two examples just show how you can exclude rules/error codes.
They are not intended as advice about which sniffs to exclude.
-->

<!--
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing"/>
<exclude name="Modernize.FunctionCalls.Dirname.Nested"/>
-->
<rule ref="WordPress">
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
<exclude name="Universal.Arrays.DisallowShortArraySyntax"/>
</rule>

<!-- Let's also check that everything is properly documented. -->
<rule ref="WordPress-Docs">
<!-- Include the WordPress-Extra standard. -->
<rule ref="WordPress-Extra">
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
<exclude name="Universal.Arrays.DisallowShortArraySyntax"/>
</rule>


<!-- Add in some extra rules from other standards. -->
<rule ref="Generic.Commenting.Todo"/>

Expand Down Expand Up @@ -112,7 +96,6 @@
<properties>
<property name="text_domain" type="array">
<element value="wp-starter"/>
<element value="library-wp-starter"/>
</property>
</properties>
</rule>
Expand All @@ -121,6 +104,7 @@
<properties>
<property name="prefixes" type="array">
<element value="wpstarter_"/>
<element value="WPStarter"/>
</property>
</properties>
</rule>
Expand Down
33 changes: 31 additions & 2 deletions wp-content/themes/wp-starter/blocks/alert-banner/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,47 @@
* @package WPStarter
*/

namespace WPStarter\AlertBanner;

/**
* Alert Banner Dismiss Button
*
* @param string $id Alert Banner ID
* @param string $id Alert Banner ID.
*
* @return void
*/
function alert_banner_dismiss_button( string $id ): void {
function dismiss_button( string $id ): void {
printf(
'<button class="dismiss" aria-label="%1$s" title="%2$s" @click="%3$s = !%3$s"></button>',
esc_attr__( 'Dismiss alert banner', 'wp-starter' ),
esc_attr__( 'Dismiss', 'wp-starter' ),
esc_attr( $id )
);
}

/**
* Get the ID for the Alert Banner.
*
* @param array $block The block array.
*
* @return string
*/
function get_id( array $block ): string {
return str_replace( '-', '_', get_block_id( $block ) );
}

// Make functions available in Twig.
add_filter(
'timber/twig/functions',
function ( array $functions ) {
$functions['wpstarter_alertbanner_dismiss_button'] = [
'callable' => '\\WPStarter\\AlertBanner\\dismiss_button',
];

$functions['wpstarter_alertbanner_get_id'] = [
'callable' => '\\WPStarter\\AlertBanner\\get_id',
];

return $functions;
}
);
17 changes: 11 additions & 6 deletions wp-content/themes/wp-starter/blocks/alert-banner/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
* @package WPStarter
*/

$id = 'alert' . $block['block_id'] ?? $block['id'];
$inner = [
use function WPStarter\AlertBanner\dismiss_button;
use function WPStarter\AlertBanner\get_id;

$id = get_id( $block ); // phpcs:ignore
$inner = [ // phpcs:ignore
'template' => $block['template'] ?? [],
];
$attrs = [];
$attrs = [ // phpcs:ignore
'id' => $id,
];

if ( ! is_admin() ) {
$attrs['x-data'] = '{ ' . $id . ': $persist(true) }';
$attrs['x-show'] = $id;
$attrs['x-data'] = '{ ' . $id . ': $persist(true) }'; // phpcs:ignore
$attrs['x-show'] = $id; // phpcs:ignore
}
?>
<section <?php block_attrs( $block, '', $attrs ); ?>>
<div class="acf-block-inner__container">
<?php inner_blocks( $inner ); ?>
</div>
<?php alert_banner_dismiss_button( $id ); ?>
<?php dismiss_button( $id ); ?>
</section>
20 changes: 9 additions & 11 deletions wp-content/themes/wp-starter/blocks/alert-banner/render.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@
Block: Alert Banner
#}

{% set id = 'alert' ~ block.id %}

{% if block.block_id is not empty %}
{% set id = 'alert' ~ block.block_id %}
{% endif %}
{% set id = wpstarter_alertbanner_get_id(block) %}

{% set inner = {
template: block.template ?? [],
} %}

{% set attrs = {} %}
{% set attrs = {
'id': id
} %}

{% if function('is_admin') == false %}
{% set attrs = {
{% set attrs = attrs|merge({
'x-data': '{ ' ~ id ~ ': $persist(true) }',
'x-show': id
} %}
'x-show': '"' ~ id ~ '"'
}) %}
{% endif %}

<section {{ block_attrs( block, '', attrs ) }} >
<section {{ block_attrs( block, '', attrs ) }}>
<div class="acf-block-inner__container">
{{ inner_blocks( inner ) }}
</div>
{{ function( 'alert_banner_dismiss_button', id ) }}
{{ wpstarter_alertbanner_dismiss_button(id) }}
</section>

5 changes: 3 additions & 2 deletions wp-content/themes/wp-starter/blocks/breadcrumbs/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ function () {
/**
* Breadcrumbs Output
*
* @param array $block_template
* @param ?array $block_template The block template array.
*
* @return void
*/
function wpstarter_breadcrumbs( array|null $block_template = [] ): void {
function wpstarter_breadcrumbs( ?array $block_template = [] ): void {
if ( function_exists( 'rank_math_the_breadcrumbs' ) ) {
rank_math_the_breadcrumbs();
return;
Expand Down
3 changes: 2 additions & 1 deletion wp-content/themes/wp-starter/blocks/breadcrumbs/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* @package WPStarter
*/

$template = $block['template'] ?? []; // phpcs:ignore
?>
<section <?php block_attrs( $block ); ?>>
<?php wpstarter_breadcrumbs( $block['template'] ); ?>
<?php wpstarter_breadcrumbs( $template ); ?>
</section>
3 changes: 2 additions & 1 deletion wp-content/themes/wp-starter/blocks/breadcrumbs/render.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Block: Breadcrumbs
#}

{% set template = block.template ?? [] }
<section {{ block_attrs( block ) }}>
{{ function( 'wpstarter_breadcrumbs', block.template ) }}
{{ function( 'wpstarter_breadcrumbs', template ) }}
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @package WPStarter
*/

$inner = [
$inner = [ // phpcs:ignore
'template' => $block['template'] ?? [],
'templateLock' => 'all',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
* @package WPStarter
*/

$attrs = [
'x-data="{menuIsOpen : false}"',
'x-trap="menuIsOpen"',
];

$allowed = [
$allowed = [ // phpcs:ignore
'core/group',
'core/paragraph',
'core/site-logo',
Expand All @@ -23,16 +18,16 @@
'core/spacer',
'core/separator',
];

$block_template = [
[
'core/navigation',
],
];
$inner = [
'template' => $block_template,
$inner = [ // phpcs:ignore
'template' => $block['template'] ?? [],
'allowedBlocks' => $allowed,
];
$attrs = []; // phpcs:ignore

if ( ! is_admin() ) {
$attrs['x-data'] = '{menuIsOpen : false}'; // phpcs:ignore
$attrs['x-trap'] = 'menuIsOpen'; // phpcs:ignore
}

?>
<div <?php block_attrs( $block, '', $attrs ); ?>>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{#
Block: Navigation Container
#}
{% set template = [
[
'core/navigation'
]
] %}

{% set allowed = [
'core/group',
'core/paragraph',
Expand All @@ -18,10 +14,9 @@
'core/separator'
] %}
{% set inner = {
template: template,
template: block.template ?? [],
allowedBlocks: allowed
} %}

{% set attrs = {} %}

{% if function('is_admin') == false %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"template": [
[ "core/navigation" ]
]
}
Loading