Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'build-tools/composer-update' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
admturner committed Mar 22, 2024
2 parents 9d2e0f4 + bae3645 commit e8a3bee
Show file tree
Hide file tree
Showing 12 changed files with 642 additions and 257 deletions.
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
"name": "Adam Turner"
}
],
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"prefer-stable": true,
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "*",
"squizlabs/php_codesniffer": "^3.6.2",
"phpcompatibility/phpcompatibility-wp": "^2",
"wp-coding-standards/wpcs": "*",
"wp-coding-standards/wpcs": "^3.0.0",
"sirbrillig/phpcs-variable-analysis": "^2.11.2",
"roave/security-advisories": "dev-master"
},
"prefer-stable": true,
"scripts": {
"format": "phpcbf --standard=phpcs.xml.dist --report=summary,source",
"lint": "phpcs --colors . "
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
747 changes: 558 additions & 189 deletions composer.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions hrswp-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
register_activation_hook(
__FILE__,
function(): void {
function (): void {
// Delete legacy option.
delete_option( 'hrswp_blocks_plugin-status' );

Expand All @@ -39,14 +39,14 @@ function(): void {
);

// Load blocks, asset loader, settinsg, and REST API.
require_once dirname( __FILE__ ) . '/inc/blocks.php';
require_once dirname( __FILE__ ) . '/inc/asset-loader.php';
require_once dirname( __FILE__ ) . '/inc/settings.php';
require_once dirname( __FILE__ ) . '/inc/api.php';
require_once dirname( __FILE__ ) . '/inc/query.php';
require_once __DIR__ . '/inc/blocks.php';
require_once __DIR__ . '/inc/asset-loader.php';
require_once __DIR__ . '/inc/settings.php';
require_once __DIR__ . '/inc/api.php';
require_once __DIR__ . '/inc/query.php';

// Load plugin classes.
require_once dirname( __FILE__ ) . '/inc/classes/class-sideload-image.php';
require_once __DIR__ . '/inc/classes/class-sideload-image.php';

/**
* Uninstalls the plugin.
Expand Down Expand Up @@ -81,11 +81,11 @@ function verify_plugin_dependencies(): bool {

add_action(
'plugins_loaded',
function(): void {
function (): void {
if ( ! verify_plugin_dependencies() ) {
add_action(
'admin_notices',
function(): void {
function (): void {
printf(
'<div class="error"><p>%s</p></div>',
esc_html__( 'The HRSWP Blocks plugin requires the HRSWP Sqlsrv DB plugin to function properly. Please install before continuing.', 'hrswp-blocks' )
Expand Down
10 changes: 5 additions & 5 deletions inc/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
add_action(
'rest_api_init',
function(): void {
function (): void {
$namespace = 'hrswp-blocks/v1';

// Register a gated route to access available tables.
Expand All @@ -49,7 +49,7 @@ function(): void {
'callback' => 'HRSWP\Blocks\Query\get_job_classification_data',
'args' => array(
'table' => array(
'sanitize_callback' => function( string $param ): string {
'sanitize_callback' => function ( string $param ): string {
return sanitize_key( $param );
},
),
Expand All @@ -69,7 +69,7 @@ function(): void {
'callback' => 'HRSWP\Blocks\Query\get_salary_data',
'args' => array(
'table' => array(
'sanitize_callback' => function( string $param ): string {
'sanitize_callback' => function ( string $param ): string {
return sanitize_key( $param );
},
),
Expand All @@ -89,12 +89,12 @@ function(): void {
'callback' => 'HRSWP\Blocks\Query\import_awards_data',
'args' => array(
'table' => array(
'sanitize_callback' => function( string $param ): string {
'sanitize_callback' => function ( string $param ): string {
return sanitize_key( $param );
},
),
'post' => array(
'sanitize_callback' => function( string $param ): string {
'sanitize_callback' => function ( string $param ): string {
return absint( sanitize_key( $param ) );
},
),
Expand Down
18 changes: 9 additions & 9 deletions inc/asset-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
* @return void
*/
function action_register_editor_assets(): void {
$asset_file = include plugin_dir_path( dirname( __FILE__ ) ) . 'build/index.asset.php';
$asset_file = include plugin_dir_path( __DIR__ ) . 'build/index.asset.php';

wp_register_script(
'hrswp-blocks-script',
plugins_url( 'build/index.js', dirname( __FILE__ ) ),
plugins_url( 'build/index.js', __DIR__ ),
$asset_file['dependencies'],
$asset_file['version'],
true
);

wp_register_style(
'hrswp-blocks-editor-style',
plugins_url( 'build/index.css', dirname( __FILE__ ) ),
plugins_url( 'build/index.css', __DIR__ ),
array(),
$asset_file['version']
);
Expand All @@ -49,20 +49,20 @@ function action_register_editor_assets(): void {
* @return void
*/
function action_register_frontend_assets(): void {
$filter_asset_file = include plugin_dir_path( dirname( __FILE__ ) ) . 'build/filter.asset.php';
$accordion_asset_file = include plugin_dir_path( dirname( __FILE__ ) ) . 'build/accordion.asset.php';
$filter_asset_file = include plugin_dir_path( __DIR__ ) . 'build/filter.asset.php';
$accordion_asset_file = include plugin_dir_path( __DIR__ ) . 'build/accordion.asset.php';

wp_register_script(
'hrswp-blocks-filter-view',
plugins_url( 'build/filter.js', dirname( __FILE__ ) ),
plugins_url( 'build/filter.js', __DIR__ ),
$filter_asset_file['dependencies'],
$filter_asset_file['version'],
true
);

wp_register_script(
'hrswp-blocks-accordion-view',
plugins_url( 'build/accordion.js', dirname( __FILE__ ) ),
plugins_url( 'build/accordion.js', __DIR__ ),
$accordion_asset_file['dependencies'],
$accordion_asset_file['version'],
true
Expand All @@ -79,11 +79,11 @@ function action_register_frontend_assets(): void {
* @return void
*/
function action_register_assets(): void {
$asset_file = include plugin_dir_path( dirname( __FILE__ ) ) . 'build/index.asset.php';
$asset_file = include plugin_dir_path( __DIR__ ) . 'build/index.asset.php';

wp_register_style(
'hrswp-blocks-style',
plugins_url( 'build/style-index.css', dirname( __FILE__ ) ),
plugins_url( 'build/style-index.css', __DIR__ ),
array(),
$asset_file['version']
);
Expand Down
14 changes: 7 additions & 7 deletions inc/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
}

// Include files required for dynamic block registration.
require plugin_dir_path( dirname( __FILE__ ) ) . 'build/blocks/posts-list/index.php';
require plugin_dir_path( dirname( __FILE__ ) ) . 'build/blocks/list-awards/index.php';
require plugin_dir_path( dirname( __FILE__ ) ) . 'build/blocks/salary-data/index.php';
require plugin_dir_path( dirname( __FILE__ ) ) . 'build/blocks/job-classifications/index.php';
require plugin_dir_path( __DIR__ ) . 'build/blocks/posts-list/index.php';
require plugin_dir_path( __DIR__ ) . 'build/blocks/list-awards/index.php';
require plugin_dir_path( __DIR__ ) . 'build/blocks/salary-data/index.php';
require plugin_dir_path( __DIR__ ) . 'build/blocks/job-classifications/index.php';

/**
* Registers HRSWP blocks.
Expand All @@ -27,7 +27,7 @@
*/
add_action(
'init',
function(): void {
function (): void {
$block_folders = array(
'accordion-heading',
'accordion-section',
Expand All @@ -42,7 +42,7 @@ function(): void {
);
foreach ( $block_folders as $block_folder ) {
register_block_type(
plugin_dir_path( dirname( __FILE__ ) ) . 'build/blocks/' . $block_folder
plugin_dir_path( __DIR__ ) . 'build/blocks/' . $block_folder
);
}
}
Expand All @@ -60,7 +60,7 @@ function(): void {
*/
add_filter(
'block_categories_all',
function( array $default_categories ): array {
function ( array $default_categories ): array {
$plugin_categories = array(
array(
'slug' => 'hrswp-blocks-external',
Expand Down
26 changes: 21 additions & 5 deletions inc/classes/class-sideload-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,26 @@ public function __construct( $props ) {
'skip_if_exists' => false,
);

$args = wp_parse_args( $props, $defaults );
$this->args = wp_parse_args( $props, $defaults );
$this->process_image();
}

/**
* Sideload the image into the media library.
*
* @since 3.6.0
*
* @access private
*/
private function process_image() {
if ( $this->args['skip_if_exists'] ) {
$query_args = array(
'post_type' => 'attachment',
'title' => $this->args['title'],
'numberposts' => 1,
);

if ( $args['skip_if_exists'] ) {
$existing_attachment = get_page_by_title( $args['title'], OBJECT, 'attachment' );
$existing_attachment = get_posts( $query_args );

// If the attachment already exists, populate the class property and exit early.
if ( $existing_attachment ) {
Expand All @@ -117,10 +133,10 @@ public function __construct( $props ) {
$this->includes();

// Define some useful file attributes of the sideloaded file.
$this->set_file_info( $args['image_contents'], $args['title'], $args['description'], $args['group_year'] );
$this->set_file_info( $this->args['image_contents'], $this->args['title'], $this->args['description'], $this->args['group_year'] );

// Sideload the file and create the attachment, then populate the default alt text and award group meta.
$this->sideload_file( $args['image_contents'], $args['page_id'] );
$this->sideload_file( $this->args['image_contents'], $this->args['page_id'] );
update_post_meta( $this->attachment['id'], '_wp_attachment_image_alt', $this->fileinfo['description'] );
update_post_meta( $this->attachment['id'], '_hrswp_sqlsrv_db_award_group', $this->fileinfo['group_year'] );

Expand Down
2 changes: 1 addition & 1 deletion inc/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function import_awards_data( \WP_REST_Request $request ): object {
'post_type' => 'attachment',
'posts_per_page' => -1,
'orderby' => 'meta_value_num',
'meta_key' => '_hrswp_sqlsrv_db_award_group',
'meta_key' => '_hrswp_sqlsrv_db_award_group', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'order' => 'ASC',
)
);
Expand Down
4 changes: 2 additions & 2 deletions inc/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function sanitize_setting_int_list( string $value ): string {
$value = array_filter( array_map( 'trim', $value ) );
$value = array_filter(
array_map(
function( string $number ): string {
function ( string $number ): string {
$number = preg_replace( '/[^\-0-9]/', '', wp_specialchars_decode( $number ) );
$number = ! is_numeric( $number ) ? '' : $number;
$number = ( 0 > $number ) ? '' : $number;
Expand All @@ -75,7 +75,7 @@ function( string $number ): string {
*/
add_action(
'admin_init',
function(): void {
function (): void {
$slug = 'hrswp-theme';
$option = 'hrswp_plugins_protected_ids';

Expand Down
12 changes: 7 additions & 5 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
<!-- Loads the PHP Compatibility ruleset. -->
<rule ref="PHPCompatibilityWP"/>

<rule ref="WordPress-Core"/>
<rule ref="WordPress-Docs"/>
<rule ref="WordPress.WP.I18n"/>
<!-- Loads the WP rulesets -->
<rule ref="WordPress"/>

<!-- Loads the variable analysis ruleset. -->
<rule ref="VariableAnalysis"/>

<arg value="ps"/>
<arg name="extensions" value="php"/>
Expand All @@ -29,8 +31,8 @@
<!-- Sets the minimum supported PHP version to 7.4, which is also WordPress's. -->
<config name="testVersion" value="7.4-"/>

<!-- Sets the minimum supported WP version to 5.0. -->
<config name="minimum_supported_wp_version" value="5.0" />
<!-- Sets the minimum supported WP version to 5.4. -->
<config name="minimum_wp_version" value="5.4" />

<!-- Defines the valid textdomain options. -->
<config name="text_domain" value="hrswp-blocks,default"/>
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/list-awards/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function render( $attributes ) {
'post_type' => 'attachment',
'posts_per_page' => -1,
'orderby' => 'meta_value_num',
'meta_key' => '_hrswp_sqlsrv_db_award_group',
'meta_key' => '_hrswp_sqlsrv_db_award_group', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'order' => 'ASC',
)
);
Expand Down
32 changes: 15 additions & 17 deletions src/blocks/posts-list/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,20 @@ public function render( $attributes ) {
);

$post_meta_markup .= get_the_term_list( $post->ID, $taxonomy_name, $prefix, ', ', '</p>' );
} else {
if (
'post_tag' !== $taxonomy_name &&
'category' !== $taxonomy_name &&
isset( $attributes['displayPostTaxonomy'] ) &&
$attributes['displayPostTaxonomy']
) {
$taxonomy_object = get_taxonomy( $taxonomy_name );
$prefix = sprintf(
'<p class="hrswp-block-posts-list__%1$s-list"><span>%2$s: </span>',
esc_attr( $taxonomy_name ),
esc_html( $taxonomy_object->labels->singular_name )
);

$post_meta_markup .= get_the_term_list( $post->ID, $taxonomy_name, $prefix, ', ', '</p>' );
}
} elseif (
'post_tag' !== $taxonomy_name &&
'category' !== $taxonomy_name &&
isset( $attributes['displayPostTaxonomy'] ) &&
$attributes['displayPostTaxonomy']
) {
$taxonomy_object = get_taxonomy( $taxonomy_name );
$prefix = sprintf(
'<p class="hrswp-block-posts-list__%1$s-list"><span>%2$s: </span>',
esc_attr( $taxonomy_name ),
esc_html( $taxonomy_object->labels->singular_name )
);

$post_meta_markup .= get_the_term_list( $post->ID, $taxonomy_name, $prefix, ', ', '</p>' );
}
}
}
Expand Down Expand Up @@ -317,7 +315,7 @@ public function render( $attributes ) {
*/
add_action(
'init',
function() {
function () {
return new PostsList();
},
25
Expand Down

0 comments on commit e8a3bee

Please sign in to comment.