Skip to content

Commit

Permalink
Merge pull request #63 from alleyinteractive/feature/plugin-update
Browse files Browse the repository at this point in the history
Misc: several updates to the plugin
  • Loading branch information
renatonascalves authored Nov 13, 2023
2 parents bd86603 + cac3e30 commit 8d9b71d
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 98 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab
indent_size = 4

[*.{ts,tsx,js,jsx,scss,css,json,yaml,yml,feature,xml}]
indent_style = space
indent_size = 2

# Dotfiles
[.*]
indent_style = space
indent_size = 2
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
php-tests:
strategy:
matrix:
php: [8.0]
php: [8.0, 8.1, 8.2]
wordpress: ["latest"]
uses: alleyinteractive/.github/.github/workflows/php-tests.yml@main
with:
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

All notable changes to this plugin will be documented in this file.

## 1.1.2

- Github Action: Updated matrix to test the following PHP versions: 8.0, 8.1, and 8.2;
- Added `.editorconfig`;
- Composer: upgraded packages;
- PHPStan: added support;
- Bumped the plugin version from `0.2` to `1.1.2`;
- Tested the plugin with the WordPress 6.4;
- Use `declare(strict_types=1);`, when possible;
- Update Alley domain to `https://alley.com`;


## 1.1.1

- See <https://github.com/alleyinteractive/archiveless/releases/tag/v1.1.1>

### 1.1.0

- See <https://github.com/alleyinteractive/archiveless/releases/tag/v1.1.0>

## 1.0.1

- Bug fix from previous use of the archiveless plugin that broke backwards
Expand Down
15 changes: 10 additions & 5 deletions archiveless.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* Plugin Name: Archiveless
* Plugin URI: https://github.com/alleyinteractive/archiveless
* Description: Hide posts from archives performantly
* Version: 0.2
* Version: 1.1.2
* Author: Alley Interactive
* Author URI: https://alley.co/
* Author URI: https://alley.com
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Tested up to: 6.2
* Tested up to: 6.4
* Requires PHP: 8.0
*
* @package Archiveless
Expand All @@ -32,5 +32,10 @@
require_once __DIR__ . '/inc/assets.php';
require_once __DIR__ . '/inc/class-archiveless.php';

// Add action hook to initialize the plugin.
add_action( 'after_setup_theme', [ 'Archiveless', 'instance' ] );
// Initialize Archiveless.
add_action(
'after_setup_theme',
function (): void {
Archiveless::instance();
}
);
81 changes: 45 additions & 36 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
{
"name": "alleyinteractive/archiveless",
"description": "WordPress plugin to hide posts from archives (lists)",
"homepage": "https://github.com/alleyinteractive/archiveless",
"type": "wordpress-plugin",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "Alley",
"email": "[email protected]"
}
],
"support": {
"issues": "https://github.com/alleyinteractive/archiveless/issues",
"source": "https://github.com/alleyinteractive/archiveless"
},
"require-dev": {
"alleyinteractive/alley-coding-standards": "^1.0",
"mantle-framework/testkit": "^0.10"
},
"config": {
"allow-plugins": {
"alleyinteractive/composer-wordpress-autoloader": true,
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"phpcbf": "phpcbf .",
"phpcs": "phpcs .",
"phpunit": "phpunit",
"test": [
"@phpcs",
"@phpunit"
]
"name": "alleyinteractive/archiveless",
"description": "WordPress plugin to hide posts from archives (lists)",
"keywords": [
"alleyinteractive",
"archive",
"archiveless"
],
"homepage": "https://github.com/alleyinteractive/archiveless",
"type": "wordpress-plugin",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "Alley Interactive",
"email": "[email protected]"
}
],
"support": {
"issues": "https://github.com/alleyinteractive/archiveless/issues",
"source": "https://github.com/alleyinteractive/archiveless"
},
"require-dev": {
"php": "^8.0",
"alleyinteractive/alley-coding-standards": "^2.0",
"mantle-framework/testkit": "^0.12",
"szepeviktor/phpstan-wordpress": "^1.1"
},
"config": {
"allow-plugins": {
"alleyinteractive/composer-wordpress-autoloader": true,
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"phpcbf": "phpcbf .",
"phpcs": "phpcs .",
"phpunit": "phpunit",
"phpstan": "phpstan --memory-limit=512M",
"test": [
"@phpcs",
"@phpstan",
"@phpunit"
]
}
}
37 changes: 19 additions & 18 deletions inc/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package Archiveless
*/

declare(strict_types=1);

namespace Archiveless;

use Archiveless;
Expand All @@ -21,7 +23,7 @@
/**
* A callback for the enqueue_block_editor_assets action hook.
*/
function action_enqueue_block_editor_assets() {
function action_enqueue_block_editor_assets(): void {
if ( ! Archiveless::instance()->is_block_editor() ) {
return;
}
Expand All @@ -40,10 +42,9 @@ function action_enqueue_block_editor_assets() {
* Gets asset dependencies from the generated asset manifest.
*
* @param string $asset Entry point and asset type separated by a '.'.
*
* @return array An array of dependencies for this asset.
* @return array<string, string> An array of dependencies for this asset.
*/
function get_asset_dependencies( string $asset ) : array {
function get_asset_dependencies( string $asset ): array {
// Get the path to the PHP file containing the dependencies.
$dependency_file = get_asset_path( $asset, true );
if ( empty( $dependency_file ) ) {
Expand All @@ -58,6 +59,7 @@ function get_asset_dependencies( string $asset ) : array {
// Try to load the dependencies.
// phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
$dependencies = require $dependency_file;

if ( empty( $dependencies['dependencies'] ) || ! is_array( $dependencies['dependencies'] ) ) {
return [];
}
Expand All @@ -69,10 +71,9 @@ function get_asset_dependencies( string $asset ) : array {
* Get the contentHash for a given asset.
*
* @param string $asset Entry point and asset type separated by a '.'.
*
* @return string The asset's hash.
*/
function get_asset_hash( string $asset ) : string {
function get_asset_hash( string $asset ): string {
return get_asset_property( $asset, 'hash' )
?? ARCHIVELESS_ASSET_MAP['hash']
?? '1.0.0';
Expand All @@ -83,10 +84,9 @@ function get_asset_hash( string $asset ) : string {
*
* @param string $asset Entry point and asset type separated by a '.'.
* @param boolean $dir Optional. Whether to return the directory path or the plugin URL path. Defaults to false (returns URL).
*
* @return string The asset URL.
*/
function get_asset_path( string $asset, bool $dir = false ) : string {
function get_asset_path( string $asset, bool $dir = false ): string {
// Try to get the relative path.
$relative_path = get_asset_property( $asset, 'path' );
if ( empty( $relative_path ) ) {
Expand All @@ -106,27 +106,24 @@ function get_asset_path( string $asset, bool $dir = false ) : string {
*
* @param string $asset Entry point and asset type separated by a '.'.
* @param string $prop The property to get from the entry object.
*
* @return string|null The asset property based on entry and type.
*/
function get_asset_property( string $asset, string $prop ) : ?string {
function get_asset_property( string $asset, string $prop ): ?string {
/*
* Appending a '.' ensures the explode() doesn't generate a notice while
* allowing the variable names to be more readable via list().
*/
list( $entrypoint, $type ) = explode( '.', "$asset." );

$asset_property = ARCHIVELESS_ASSET_MAP[ $entrypoint ][ $type ][ $prop ] ?? null;

return $asset_property ? $asset_property : null;
return ARCHIVELESS_ASSET_MAP[ $entrypoint ][ $type ][ $prop ] ?? null;
}

/**
* Creates a new Jed instance with specified locale data configuration.
*
* @param string $to_handle The script handle to attach the inline script to.
*/
function inline_locale_data( string $to_handle ) {
function inline_locale_data( string $to_handle ): void {
// Define locale data for Jed.
$locale_data = [
'' => [
Expand All @@ -146,14 +143,18 @@ function inline_locale_data( string $to_handle ) {
* Decode the asset map at the given file path.
*
* @param string $path File path.
*
* @return array The asset map.
* @return array<string, string> The asset map.
*/
function read_asset_map( string $path ) : array {
function read_asset_map( string $path ): array {
if ( file_exists( $path ) && 0 === validate_file( $path ) ) {
ob_start();
include $path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.IncludingFile, WordPressVIPMinimum.Files.IncludingFile.UsingVariable
return json_decode( ob_get_clean(), true );

$retval = json_decode( (string) ob_get_clean(), true );

if ( is_array( $retval ) ) {
return $retval;
}
}

return [];
Expand Down
Loading

0 comments on commit 8d9b71d

Please sign in to comment.