Skip to content

Commit

Permalink
Merge remote-tracking branch 'legacy-plugin/trunk' into legacy-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
bordoni committed Sep 13, 2023
2 parents e57dc2a + 542ea3c commit 95e8768
Show file tree
Hide file tree
Showing 43 changed files with 2,718 additions and 2 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and push to build branch.

on:
push:
branches: [trunk]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0

- name: Install NodeJS
uses: actions/setup-node@5b52f097d36d4b0b2f94ed6de710023fbb8b2236 # v3.1.0
with:
node-version-file: '.nvmrc'

- name: Install all dependencies
run: |
npm install
npm run wp-env start
npm run wp-env run composer 'install --no-dev'
npm run setup:readme-parser
- name: Trim the repo down to just the plugin files
run: |
rm -rf node_modules
rm -rf tests
rm -rf .github
rm -f .gitignore .nvmrc .wp-env.json
rm -f package.*
rm -f composer.*
rm -f *.xml*
- name: Add all the plugin files
run: |
git add * --force
- name: Commit and push
uses: actions-js/push@a52398fac807b0c1e5f1492c969b477c8560a0ba # 1.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: build
force: true
message: 'Build: ${{ github.sha }}'
34 changes: 34 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deploy

# Run deploy only on published releases.
on:
release:
types: [published]

jobs:

deploy:
name: Deploy to WordPress.org
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: WordPress Plugin Deploy
id: deploy
uses: 10up/action-wordpress-plugin-deploy@stable
with:
generate-zip: true
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}

- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ steps.deploy.outputs.zip-path }}
asset_name: ${{ github.event.repository.name }}.zip
asset_content_type: application/zip
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test

on: [push, pull_request]

jobs:

lint:
name: Test
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install NodeJS
uses: actions/setup-node@5b52f097d36d4b0b2f94ed6de710023fbb8b2236 # v3.1.0
with:
node-version-file: '.nvmrc'

- name: Setup PHP and Composer
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer:v2

- name: Install all dependencies
run: |
npm install
npm run wp-env start
npm run wp-env run composer 'install --no-dev'
npm run setup:readme-parser
- name: Setup environment tools
run: npm run setup:tools

- name: Test
run: npm test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
composer.lock
package-lock.json
vendor/
node_modules/
readme-parser.php
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14
5 changes: 5 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": [
"."
]
}
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# plugin-check
A repository for the new Plugin Check plugin from the WordPress Performance team
Plugin Check
===============
* Contributors:
* Requires at least: 6.2
* Tested up to: 6.3.1
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html

Plugin Check is a tool for the WordPress.org plugins review team.

## Description ##

Plugin Check is a tool for the WordPress.org plugins review team.
This is intended as a generic tool that is not at all intended on being complete.

Setup steps:
- `npm install`
- `npm run wp-env start`
- `npm run setup:tools`

Commands:
- `npm run wp-env start`
- `npm test`
74 changes: 74 additions & 0 deletions admin/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
namespace WordPressdotorg\Plugin_Check\Admin;
use function WordPressdotorg\Plugin_Check\run_all_checks;

add_action( 'admin_menu', function() {
add_submenu_page(
'tools.php',
__( 'Plugin Check', 'plugin-check' ),
__( 'Plugin Check', 'plugin-check' ),
'manage_options',
'plugin-check',
__NAMESPACE__ . '\render_page'
);
} );

function render_page() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}

echo '<div class="wrap">';
echo '<h1>' . esc_html__( 'Plugin Check', 'plugin-check' ) . '</h1>';
echo '<p>' . esc_html__( 'Select a plugin to run the checks against.', 'plugin-check' ) . '</p>';
echo '<form method="get" action="' . esc_url( admin_url( 'tools.php' ) ) . '">';
echo '<input type="hidden" name="page" value="plugin-check" />';
echo '<input type="hidden" name="action" value="check" />';
wp_nonce_field( 'plugin-check' );
echo '<label for="plugin">' . esc_html__( 'Plugin', 'plugin-check' ) . '</label>';
echo '<select name="plugin" id="plugin">';
$selected_plugin = false;
foreach ( get_plugins() as $plugin_file => $plugin_data ) {
// Only list plugins that are in their own directories.
if ( ! str_contains( $plugin_file, '/' ) ) {
continue;
}

$plugin_dir = dirname( $plugin_file );
$selected = selected( $plugin_dir, $_REQUEST['plugin'] ?? '', false );
if ( $selected ) {
$selected_plugin = $plugin_data;
}

echo '<option value="' . esc_attr( $plugin_dir ) . '"' . $selected . '>' . esc_html( $plugin_data['Name'] ) . '</option>';
}
echo '</select>';
echo '<input type="submit" class="button button-primary" value="' . esc_attr__( 'Check', 'plugin-check' ) . '" />';

echo '</form>';
echo '</div>';

if ( ! empty( $_REQUEST['action'] ) && 'check' === $_REQUEST['action'] ) {
check_admin_referer( 'plugin-check' );

$plugin = wp_unslash( $_REQUEST['plugin'] );
$path = path_join( WP_PLUGIN_DIR, $plugin );
$result = run_all_checks( $path );

echo '<h2>' . sprintf( esc_html__( 'Results for %s', 'plugin-check' ), esc_html( $selected_plugin['Name'] ?? $plugin ) ) . '</h2>';

if ( true === $result ) {
echo '<div class="notice inline notice-success"><p>' . esc_html__( 'No issues found.', 'plugin-check' ) . '</p></div>';
} else {
echo '<p>' . esc_html__( 'The following issues were found:', 'plugin-check' ) . '</p>';
foreach ( $result as $error ) {
printf(
'<div class="notice inline notice-%s" data-code="%s"><p>%s</p></div>',
esc_attr( $error->error_class ),
esc_attr( $error->get_error_code() ),
$error->get_error_message()
);
}
}
}
}
45 changes: 45 additions & 0 deletions bin/check-plugin-by-slug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
namespace WordPressdotorg\Plugin_Check;

$_SERVER['HTTP_HOST'] = 'wordpress.org';
$_SERVER['REQUEST_URI'] = '/plugins/';
require dirname( __DIR__, 4 ) . '/wp-load.php';
require ABSPATH . '/wp-admin/includes/admin.php';

include_once dirname( __DIR__ ) . '/plugin.php';

$slug = $argv[1] ?? false;
if ( ! $slug ) {
die( "Usage: {$argv[0]} <slug>" );
}

$tempname = wp_tempnam( 'plugin-check' );
unlink( $tempname );
mkdir( $tempname );

$zipfile = download_url( "https://downloads.wordpress.org/plugin/{$slug}.latest-stable.zip" );
if ( is_file( $zipfile ) ) {
exec( "unzip -q {$zipfile} -d {$tempname}" );
}

add_action( 'shutdown', function() use( $tempname, $zipfile ) {
if ( $zipfile ) {
unlink( $zipfile );
}

$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator( $tempname, \RecursiveDirectoryIterator::SKIP_DOTS ),
\RecursiveIteratorIterator::CHILD_FIRST
);

foreach ( $files as $fileinfo ) {
$todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink' );
$todo( $fileinfo->getRealPath() );
}

rmdir( $tempname );
} );

var_dump(
run_all_checks( $tempname )
);
12 changes: 12 additions & 0 deletions bin/test-self.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace WordPressdotorg\Plugin_Check;

$_SERVER['HTTP_HOST'] = 'wordpress.org';
$_SERVER['REQUEST_URI'] = '/plugins/';
require dirname( __DIR__, 4 ) . '/wp-load.php';

include_once dirname( __DIR__ ) . '/plugin.php';

var_dump(
run_all_checks( dirname( __DIR__ ) )
);
Loading

0 comments on commit 95e8768

Please sign in to comment.