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

Adds a plugin family package to be shared across our plugins #1

Merged
merged 32 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3413a8e
Initial commit
jeawhanlee Oct 15, 2024
d8ec457
Added phpcs
jeawhanlee Oct 15, 2024
f92f8d5
Added lint config
jeawhanlee Oct 15, 2024
f402c43
Updated config file
jeawhanlee Oct 15, 2024
7742694
Added gitignore
jeawhanlee Oct 15, 2024
4cbcbc2
Fixed phpcs errors
jeawhanlee Oct 15, 2024
1bd7fcf
Ignore composer.lock
jeawhanlee Oct 15, 2024
1e10a4b
Added tests
jeawhanlee Oct 15, 2024
5553a85
Added patchwork config
jeawhanlee Oct 15, 2024
88ea2d3
Updated composer packages and script
jeawhanlee Oct 15, 2024
d53b905
Updated method
jeawhanlee Oct 15, 2024
a514056
Updated namespace
jeawhanlee Oct 15, 2024
14f6702
Updated namespace and methods
jeawhanlee Oct 15, 2024
a191bd0
Added test workflow
jeawhanlee Oct 15, 2024
e2f0d80
Remove test cache
jeawhanlee Oct 15, 2024
3672163
Ignore test cache
jeawhanlee Oct 15, 2024
d5af0e3
Updated README
jeawhanlee Oct 16, 2024
58cf829
Updated README
jeawhanlee Oct 16, 2024
d0002d4
Updated README
jeawhanlee Oct 16, 2024
4e9ae88
Updated README
jeawhanlee Oct 16, 2024
4b11dda
Updated test
jeawhanlee Oct 16, 2024
4bec6fe
Updated README
jeawhanlee Oct 17, 2024
d12ca1d
Updated namespace
jeawhanlee Oct 17, 2024
a23f4dc
Added phpstan
jeawhanlee Oct 17, 2024
f8454ab
Fixed phpstan errors
jeawhanlee Oct 17, 2024
ecf9f67
Updated composer.json
jeawhanlee Oct 17, 2024
ce0f113
Added phpstan config
jeawhanlee Oct 17, 2024
2c7bb56
Added workflow file for phpstan
jeawhanlee Oct 17, 2024
e25931f
Updated namespace
jeawhanlee Oct 17, 2024
276981e
use defined var
jeawhanlee Oct 17, 2024
a72f32d
Updated README
jeawhanlee Oct 17, 2024
7bf9c44
Updated tests
jeawhanlee Oct 18, 2024
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
38 changes: 38 additions & 0 deletions .github/workflows/lint_phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: PHP CodeSniffer lint

on:
pull_request:
branches:
- trunk
- develop
- branch-*
- enhancement/*

jobs:
run:
runs-on: ${{ matrix.operating-system }}

strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.2']

name: WP Media Plugin Family lint with PHPCS. PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}.
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none # XDebug can be enabled here 'coverage: xdebug'
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-scripts

- name: Lint with phpcs
run: composer phpcs

35 changes: 35 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PHP Stan lint

on:
pull_request:
branches:
- trunk
- develop

jobs:
run:
runs-on: ${{ matrix.operating-system }}

strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.2']

name: Lint with PHP Stan. PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}.
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none # XDebug can be enabled here 'coverage: xdebug'
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-scripts

- name: Lint with PHP Stan
run: composer phpstan -- --error-format=github
64 changes: 64 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Unit tests

on:
pull_request:
branches:
- trunk
- develop

jobs:
run:
runs-on: ${{ matrix.operating-system }}

strategy:
fail-fast: true
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2']
wp-versions: ['latest']

name: WP ${{ matrix.wp-versions }} with PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}.

env:
WP_TESTS_DIR: "/tmp/tests/phpunit"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug
tools: composer:v2, phpunit

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Require phpcov for coverage reporting
run: composer require --dev --no-scripts phpunit/phpcov -W

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-scripts

- name: Unit/Integration tests
run: composer test-unit

- name: Code Coverage Report
if: ${{ matrix.php-versions == '8.2' }}
run: composer report-code-coverage
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor
/composer.lock
tests/Unit/.phpunit.result.cache
97 changes: 96 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,96 @@
# wp-media-plugin-family
# Plugin Family

This package bundles the WP Media plugin collection within a single plugin.

## Functionality

This package gathers essential data about each member plugin and provides their installation and activation links, similar to the [Imagify Partner](https://github.com/wp-media/wp-imagify-partner/) package. It returns an installation link for plugins that are not installed, and an activation link for those that are installed but not active.
For Imagify, the link generated by the Imagify Partner package is used.

PS: The Imagify Partner package needs be installed along side. refer [here](https://github.com/wp-media/wp-imagify-partner/) for more information.

## Usage Instructions

- Install using composer: `composer require wp-media/plugin-family`
- Import the model that holds the filtered data into your view class.

```php
use WPMedia\PluginFamily\Model\PluginFamily;

class View {
protected $plugin_family;

public function __construct( $plugin_family ) {
$this->plugin_family = $plugin_family;
}

public function display_page() {
$plugin_family = $this->plugin_family->get_filtered_plugins( 'imagify-plugin/imagify' );

$data = [
'plugin_family' => $plugin_family['uncategorized'],
];

$this->print_template( 'page-settings', $data );
}
}
```
The model returns an array with 2 keys ( categorized & uncategorized ). This for plugins like WP Rocket that needs to display the plugins by category.

- The categorized version has the plugins grouped by their categories.
- The uncategorized version is the reverse of the former.

Next, we need to invoke the controller responsible for managing the installation and activation. This controller has a corresponding interface that needs to be implemented.

```php
use WPMedia\PluginFamily\Controller\{ PluginFamily, PluginFamilyInterface };

class Subscriber implements SubscriberInterface, PluginFamilyInterface {

protected $plugin_family;

public function __construct( $plugin_family ) {
$this->plugin_family = $plugin_family;
}

public static function get_subscribed_events() {
$events = PluginFamily::get_subscribed_events();

return $events;
}

public function install_activate() {
$this->plugin_family->install_activate();
}

public function display_error_notice() {
$this->plugin_family->display_error_notice();
}
}
```
The methods ( `install_activate` & `display_error_notice` ) are required.

PS: This example is based on the assumption that your plugin utilizes EDA. If EDA is not available, you can iterate through the events returned by `PluginFamily::get_subscribed_events()` and use `add_action` accordingly.

## Development & Testing

To facilitate development and testing of the package, it is recommended to specify a development branch in the composer.json file of your project.

## Taking WP Rocket as example

```JSON
"require": {
"wp-media/plugin-family": "dev-whatever-dev-branch"
}
```

PS: Always have the dev prefix before the actual branch.

```JSON
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wp-media/plugin-family"
}
]
```
45 changes: 45 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "wp-media/plugin-family",
"description": "Organizes and displays WP Media plugin family across other members.",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "WP Media",
"email": "[email protected]",
"homepage": "https://wp-media.me"
}
],
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"require-dev": {
"phpcompatibility/phpcompatibility-wp": "^2.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"wp-coding-standards/wpcs": "^3",
"wp-media/phpunit": "^3",
"phpstan/extension-installer": "^1.4",
"szepeviktor/phpstan-wordpress": "^1.3"
},
"autoload": {
"psr-4": {
"WPMedia\\PluginFamily\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"WPMedia\\PluginFamily\\Tests\\": "tests/"
}
},
"scripts": {
"install-codestandards": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run",
"phpcs": "phpcs --basepath=.",
"phpcs:fix": "phpcbf",
"test-unit": "\"vendor/bin/phpunit\" --testsuite unit --colors=always --configuration tests/Unit/phpunit.xml.dist --coverage-php tests/report/unit.cov",
"report-code-coverage": "\"vendor/bin/phpcov\" merge tests/report --clover tests/report/coverage.clover",
"phpstan": "vendor/bin/phpstan analyze --memory-limit=2G --no-progress"
}
}
3 changes: 3 additions & 0 deletions patchwork.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"redefinable-internals": ["file_exists"]
}
55 changes: 55 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WP Rocket" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<description>The custom ruleset for WP Media Plugin Family.</description>

<!-- For help in understanding this file: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<!-- For help in using PHPCS: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->

<!-- ** WHAT TO SCAN ** -->
<file>src</file>
<!-- ** HOW TO SCAN ** -->
<arg value="sp"/><!-- Show sniff and progress -->
<arg name="colors"/><!-- Show results with colors -->
<arg name="parallel" value="50"/><!-- Enables parallel processing when available for faster results. -->
<arg name="extensions" value="php"/><!-- Limit to PHP files -->

<!-- Rules: Check PHP version compatibility - see https://github.com/PHPCompatibility/PHPCompatibilityWP -->
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="7.3-"/>
<config name="minimum_supported_wp_version" value="5.8"/>

<rule ref="WordPress">
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found"/>
<exclude name="Universal.Operators.DisallowShortTernary.Found"/>
<exclude name="Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound"/>
<exclude name="Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma"/>
<exclude name="Generic.PHP.NoSilencedErrors.Discouraged"/>
<exclude name="PEAR.Functions.FunctionCallSignature.Indent"/>
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace"/>
<exclude name="Squiz.Commenting.FileComment.Missing"/>
<exclude name="Squiz.Commenting.FileComment.MissingPackageTag"/>
<exclude name="Squiz.PHP.CommentedOutCode.Found"/>
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
<exclude name="Generic.Arrays.DisallowShortArraySyntax" />
<!-- Allow cURL. -->
<exclude name="WordPress.WP.AlternativeFunctions.curl_curl_init" />
<exclude name="WordPress.WP.AlternativeFunctions.curl_curl_exec" />
<exclude name="WordPress.WP.AlternativeFunctions.curl_curl_error" />
<exclude name="WordPress.WP.AlternativeFunctions.curl_curl_getinfo" />
<exclude name="WordPress.WP.AlternativeFunctions.curl_curl_close" />
<exclude name="WordPress.WP.AlternativeFunctions.curl_curl_setopt_array" />
<exclude name="WordPress.WP.AlternativeFunctions.curl_curl_setopt" />
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="prefixes" type="array" value="WPMedia" />
</properties>
</rule>
<rule ref="WordPress.Files.FileName">
<properties>
<property name="strict_class_file_names" value="false" />
</properties>
</rule>
<!-- Enforce short array syntax: `[]` in place of `array()`. -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
</ruleset>
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- phar://phpstan.phar/conf/bleedingEdge.neon
parameters:
level: 5
paths:
- %currentWorkingDirectory%/src
Loading
Loading