Skip to content

Commit

Permalink
Merge pull request #269 from 10up/update/static-fixes
Browse files Browse the repository at this point in the history
Static analysis fixes for block theme
  • Loading branch information
darylldoyle authored Jan 20, 2025
2 parents 890ab03 + dadb9f8 commit 1bac75d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ includes:
parameters:
paths:
- themes/10up-theme
- themes/10up-block-theme
- mu-plugins/10up-plugin
- mu-plugins/10up-plugin-loader.php
8 changes: 8 additions & 0 deletions phpstan/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@
define( 'TENUP_THEME_DIST_URL', TENUP_THEME_TEMPLATE_URL . '/dist/' );
define( 'TENUP_THEME_INC', TENUP_THEME_PATH . 'includes/' );
define( 'TENUP_THEME_BLOCK_DIR', TENUP_THEME_INC . 'blocks/' );

define( 'TENUP_BLOCK_THEME_VERSION', '1.0.0' );
define( 'TENUP_BLOCK_THEME_TEMPLATE_URL', '' );
define( 'TENUP_BLOCK_THEME_PATH', '/' );
define( 'TENUP_BLOCK_THEME_DIST_PATH', TENUP_BLOCK_THEME_PATH . 'dist/' );
define( 'TENUP_BLOCK_THEME_DIST_URL', TENUP_BLOCK_THEME_TEMPLATE_URL . '/dist/' );
define( 'TENUP_BLOCK_THEME_INC', TENUP_BLOCK_THEME_PATH . 'includes/' );
define( 'TENUP_BLOCK_THEME_BLOCK_DIST_DIR', TENUP_BLOCK_THEME_DIST_PATH . '/blocks/' );
5 changes: 4 additions & 1 deletion themes/10up-block-theme/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

if ( $is_local && file_exists( __DIR__ . '/dist/fast-refresh.php' ) ) {
require_once __DIR__ . '/dist/fast-refresh.php';
TenUpToolkit\set_dist_url_path( basename( __DIR__ ), TENUP_BLOCK_THEME_DIST_URL, TENUP_BLOCK_THEME_DIST_PATH );

if ( function_exists( 'TenUpToolkit\set_dist_url_path' ) ) {
TenUpToolkit\set_dist_url_path( basename( __DIR__ ), TENUP_BLOCK_THEME_DIST_URL, TENUP_BLOCK_THEME_DIST_PATH );
}
}

require_once TENUP_BLOCK_THEME_INC . 'core.php';
Expand Down
16 changes: 16 additions & 0 deletions themes/10up-block-theme/includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ function register_theme_blocks() {
$block_json_files = glob( TENUP_BLOCK_THEME_BLOCK_DIST_DIR . '*/block.json' );
$block_names = [];

if ( empty( $block_json_files ) ) {
return;
}

foreach ( $block_json_files as $filename ) {
$block_folder = dirname( $filename );
$block = register_block_type_from_metadata( $block_folder );

if ( ! $block ) {
continue;
}

$block_names[] = $block->name;
}

Expand All @@ -50,9 +59,16 @@ function ( array|bool $allowed_blocks ) use ( $block_names ): array|bool {

/**
* Enqueue block specific styles.
*
* @return void
*/
function enqueue_theme_block_styles() {
$stylesheets = glob( TENUP_BLOCK_THEME_DIST_PATH . '/blocks/autoenqueue/**/*.css' );

if ( empty( $stylesheets ) ) {
return;
}

foreach ( $stylesheets as $stylesheet_path ) {
$block_type = str_replace( TENUP_BLOCK_THEME_DIST_PATH . '/blocks/autoenqueue/', '', $stylesheet_path );
$block_type = str_replace( '.css', '', $block_type );
Expand Down
13 changes: 13 additions & 0 deletions themes/10up-block-theme/includes/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function i18n() {

/**
* Sets up theme defaults and registers support for various WordPress features.
*
* @return void
*/
function theme_setup() {
add_theme_support( 'editor-styles' );
Expand Down Expand Up @@ -104,17 +106,28 @@ function editor_style_overrides() {

/**
* register all icons located in the dist/svg folder
*
* @return void
*/
function register_all_icons() {
if ( ! function_exists( '\UIKitCore\Helpers\register_icons' ) ) {
return;
}

$icon_paths = glob( TENUP_BLOCK_THEME_DIST_PATH . 'svg/*.svg' );

if ( ! $icon_paths ) {
return;
}

$icons = array_map(
function ( $icon_path ) {
$icon_name = preg_replace( '#\..*$#', '', basename( $icon_path ) );

if ( ! $icon_name || ! class_exists( '\UIKitCore\Icon' ) ) {
return false;
}

return new \UIKitCore\Icon(
$icon_name,
ucwords( str_replace( '-', ' ', $icon_name ) ),
Expand Down

0 comments on commit 1bac75d

Please sign in to comment.