Skip to content

Commit

Permalink
Merge branch 'develop' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
afragen committed Apr 7, 2023
2 parents bdf8dbf + 9446ce4 commit 0a34b0a
Show file tree
Hide file tree
Showing 30 changed files with 300 additions and 1,786 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ vendor/bin
vendor/dealerdirect
vendor/squizlabs
vendor/wp-coding-standards
vendor
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[unreleased]

#### 1.8.0 / 2023-04-07
* update to work natively with `<slug>|<URI>` format in `Requires Plugins` header
* split PD and PDv2 into different classes
* add more tests

#### 1.7.9 / 2023-04-05
* update action link to keep `Cannot Activate | Manage Dependencies` together
* fix for multisite plugin card
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Parses a 'Requires Plugins' header and adds a Dependencies tab in the plugin ins
My solution to [#22316](https://core.trac.wordpress.org/ticket/22316). Feature plugin version of [PR #3032](https://github.com/WordPress/wordpress-develop/pull/3032)

* Parses the **Requires Plugins** header that defines plugin dependencies using a comma separated list of wp.org slugs.
* Plugins not in dot org may use the format `<slug>|<URI>` in the **Requires Plugins** header. `URI` should return a JSON compatible with the `plugins_api()` response.
* Displays a single admin notice with link to **Plugins > Add New > Dependencies** if not all plugin dependencies have been installed.
* Adds a new view/tab to plugins install page ( **Plugins > Add New** ) titled **Dependencies** that contains plugin cards for all plugin dependencies.
* This view also lists which plugins require which plugin dependencies in the plugin card, though that feature requires the filter below to function. 😅
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
},
"prefer-stable": true,
"require": {
"php": ">=5.6",
"afragen/add-plugin-dependency-api": "^0"
"php": ">=5.6"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
Expand Down
53 changes: 2 additions & 51 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 33 additions & 38 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Plugin URI: https://wordpress.org/plugins/wp-plugin-dependencies
* Description: Parses 'Requires Plugins' header, add plugin install dependencies tab, and information about dependencies.
* Author: Andy Fragen, Colin Stewart
* Version: 1.7.9
* Version: 1.8.0
* License: MIT
* Network: true
* Requires at least: 6.0
Expand All @@ -32,34 +32,25 @@
die;
}

// Deactivate plugin when committed to core.
// TODO: update with correct version.
if ( version_compare( get_bloginfo( 'version' ), '6.3-alpha-99999', '>=' ) ) {
deactivate_plugins( __FILE__ );
define( 'WP_PLUGIN_DEPENDENCIES1_COMMITTED', true );
} else {
define( 'WP_PLUGIN_DEPENDENCIES1_COMMITTED', false );
}

// Load the Composer autoloader.
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require __DIR__ . '/vendor/autoload.php';
// TODO: update with correct version.
if ( version_compare( get_bloginfo( 'version' ), '6.3-beta-1', '>=' ) ) {
define( 'WP_PLUGIN_DEPENDENCIES2_COMMITTED', true );
} else {
deactivate_plugins( __FILE__ );

wp_die(
wp_kses_post(
__( 'Plugin Dependencies is missing required composer dependencies.', 'wp-plugin-dependencies' )
)
);
define( 'WP_PLUGIN_DEPENDENCIES2_COMMITTED', false );
}

// Add the sites with REST endpoints that return plugins_api() data when passed `slug` query arg.
add_filter(
'plugin_dependency_endpoints',
function () {
return array(
'https://git-updater.com/wp-json/git-updater/v1/plugins-api/',
'https://pub.thefragens.com/gravityforms.json',
);
}
);
// Deactivate plugin when committed to core.
if ( WP_PLUGIN_DEPENDENCIES2_COMMITTED ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
deactivate_plugins( __FILE__ );
}

/**
* Class Init
Expand All @@ -72,22 +63,26 @@ class Init {
* @return void
*/
public function __construct() {
require_once __DIR__ . '/wp-admin/includes/class-wp-plugin-dependencies.php';

add_filter( 'install_plugins_tabs', array( $this, 'add_install_tab' ), 10, 1 );
add_filter( 'install_plugins_table_api_args_dependencies', array( $this, 'add_install_dependency_args' ), 10, 1 );

add_action( 'install_plugins_dependencies', 'display_plugins_table' );
add_action(
'install_plugins_table_header',
function() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$tab = isset( $_GET['tab'] ) ? sanitize_title_with_dashes( wp_unslash( $_GET['tab'] ) ) : '';
if ( 'dependencies' === $tab ) {
echo '<p>' . esc_html__( 'These suggestions are based on dependencies required by installed plugins.' ) . '</p>';
if ( ! WP_PLUGIN_DEPENDENCIES1_COMMITTED ) {
require_once __DIR__ . '/wp-admin/includes/class-wp-plugin-dependencies.php';

add_filter( 'install_plugins_tabs', array( $this, 'add_install_tab' ), 10, 1 );
add_filter( 'install_plugins_table_api_args_dependencies', array( $this, 'add_install_dependency_args' ), 10, 1 );

add_action( 'install_plugins_dependencies', 'display_plugins_table' );
add_action(
'install_plugins_table_header',
function() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$tab = isset( $_GET['tab'] ) ? sanitize_title_with_dashes( wp_unslash( $_GET['tab'] ) ) : '';
if ( 'dependencies' === $tab ) {
echo '<p>' . esc_html__( 'These suggestions are based on dependencies required by installed plugins.' ) . '</p>';
}
}
}
);
);
}

require_once __DIR__ . '/wp-admin/includes/class-wp-plugin-dependencies-2.php';
}

/**
Expand Down
9 changes: 7 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Network: true
Requires at least: 6.0
Requires PHP: 5.6
Tested up to: 6.2
Stable tag: 1.7.9
Stable tag: 1.8.0

## Description

Expand All @@ -20,7 +20,7 @@ Please open issues at [WordPress/wp-plugin-dependencies issues](https://github.c
My solution to [#22316](https://core.trac.wordpress.org/ticket/22316). Feature plugin version of [PR #3032](https://github.com/WordPress/wordpress-develop/pull/3032)

* Parses the **Requires Plugins** header that defines plugin dependencies using a comma separated list of wp.org slugs. To test, you will need to add the header and content to a plugin.
* Adds a new view/tab to plugins install page ( **Plugins > Add New** ) titled **Dependencies** that contains plugin cards for all plugin dependencies.
* Plugins not in dot org may use the format `<slug>|<URI>` in the **Requires Plugins** header. `URI` should return a JSON compatible with the `plugins_api()` response.* Adds a new view/tab to plugins install page ( **Plugins > Add New** ) titled **Dependencies** that contains plugin cards for all plugin dependencies.
* This view also lists which plugins require which plugin dependencies in the plugin card. 😅
* In the plugins page, a dependent plugin is unable to be deleted or deactivated if the requiring plugin is active.
* Plugin dependencies can be deactivated or deleted if the requiring plugin is not active.
Expand All @@ -45,6 +45,11 @@ PRs should be made against the `develop` branch.

## Changelog

#### 1.8.0 / 2023-04-07
* update to work natively with `<slug>|<URI>` format in `Requires Plugins` header
* split PD and PDv2 into different classes
* add more tests

#### 1.7.9 / 2023-04-05
* update action link to keep `Cannot Activate | Manage Dependencies` together
* fix for multisite plugin card
Expand Down
2 changes: 1 addition & 1 deletion test-plugins/test-dependencies1.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
* Author: WordPress Core Contributors
* Version: 0.1
* Description: Testing inclusion of dot org plugins in the Dependencies tab.
* Requires Plugins: wp-plugin-dependencies
* Requires Plugins: hello-dolly
*/
2 changes: 1 addition & 1 deletion test-plugins/test-dependencies2.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
* Author: WordPress Core Contributors
* Version: 0.1
* Description: Testing inclusion of non-dot org plugins in the Dependencies tab.
* Requires Plugins: gravityforms, git-updater
* Requires Plugins: gravityforms|https://pub.thefragens.com/gravityforms.json, git-updater|https://git-updater.com/wp-json/git-updater/v1/plugins-api/?slug=git-updater
*/
2 changes: 1 addition & 1 deletion test-plugins/test-dependencies3.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
* Author: WordPress Core Contributors
* Version: 0.1
* Description: Testing inclusion of dot org plugins in the Dependencies tab.
* Requires Plugins: gutenberg, wp-plugin-dependencies, akismet
* Requires Plugins: gutenberg, akismet
*/
72 changes: 70 additions & 2 deletions tests/phpunit/tests/admin/wpPluginDependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public function data_slug_sanitization() {
),
'a dependency with an underscore' => array(
'requires_plugins' => 'hello_dolly',
'expected' => array(),
'expected' => array( 'hello_dolly' ),
),
'a dependency with a space' => array(
'requires_plugins' => 'hello dolly',
Expand Down Expand Up @@ -391,7 +391,7 @@ public function data_slug_sanitization() {
),
'symbol dependencies' => array(
'requires_plugins' => '★-wpsymbols-★',
'expected' => array( '★-wpsymbols-★' ),
'expected' => array(),
),
);
}
Expand Down Expand Up @@ -544,4 +544,72 @@ public function test_get_dependency_filepaths_with_unmatched_dirnames_and_dirnam

$this->assertSame( $expected, $get_filepaths->invoke( $dependencies ) );
}

/**
* Tests that dependency filepaths are retrieved correctly.
*
* @covers WP_Plugin_Dependencies_2::split_slug
*
* @dataProvider data_split_slug
*
* @param string $slug A slug string.
* @param array $expected A string of expected slug results.
*/
public function test_split_slug( $slug, $expected ) {
$dependencies2 = new WP_Plugin_Dependencies_2();
$split_slug = $this->make_method_accessible( $dependencies2, 'split_slug' );

$actual = $split_slug->invoke( $dependencies2, trim( $slug ) );
$this->assertSame( $expected, $actual );
}

/**
* Data provider for test_split_slug().
*
* @return array
*/
public function data_split_slug() {
return array(
'no_spaces_pipe_at_end' => array(
'slug' => 'slug|',
'expected' => 'slug|',
),
'no_spaces_pipe_at_front' => array(
'slug' => '|endpoint',
'expected' => '|endpoint',
),
'double_pipe_in_middle' => array(
'slug' => 'slug||endpoint',
'expected' => 'slug||endpoint',
),
'pipes_front_middle_end' => array(
'slug' => '|slug||endpoint|',
'expected' => '|slug||endpoint|',
),
'single_pipe_in_middle' => array(
'slug' => 'slug|endpoint',
'expected' => 'slug',
),
'single_pipe_in_middle_pipe_at_end' => array(
'slug' => 'slug|endpoint|',
'expected' => 'slug|endpoint|',
),
'spaces_and_pipe_in_middle' => array(
'slug' => 'slug |endpoint',
'expected' => 'slug',
),
'pipe_and_spaces_in_middle' => array(
'slug' => 'slug| endpoint',
'expected' => 'slug',
),
'pipe_in_middle_pipe_spaces_at_end' => array(
'slug' => 'slug|endpoint| ',
'expected' => 'slug|endpoint|',
),
'spaces_pipe_at_front_pipe_in_middle' => array(
'slug' => ' |slug|endpoint',
'expected' => '|slug|endpoint',
),
);
}
}
21 changes: 0 additions & 21 deletions vendor/afragen/add-plugin-dependency-api/LICENSE

This file was deleted.

Loading

0 comments on commit 0a34b0a

Please sign in to comment.