Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.git
/.github
/.wordpress.org
/.distignore
/tests
/README.md
/composer.json
29 changes: 16 additions & 13 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,34 @@ on:
tags:
- "v*"

permissions:
contents: read

jobs:
tag:
name: New tag
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@main
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@stable
uses: 10up/action-wordpress-plugin-deploy@54bd289b8525fd23a5c365ec369185f2966529c2 # 2.3.0
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
# SLUG: pp-disable-xml-rpc # optional, remove if GitHub repo name matches SVN slug, including capitalization
build:
name: Create Release
needs: tag
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RELEASE_TAG: ${{ github.ref_name }}
run: gh release create "$RELEASE_TAG" --verify-tag --title "Release $RELEASE_TAG" --notes ""
15 changes: 13 additions & 2 deletions .github/workflows/lint-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
pull_request:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand All @@ -22,14 +25,22 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Setup PHP
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
with:
php-version: ${{ matrix.php }}
tools: parallel-lint
coverage: none

- name: Lint PHP files
run: parallel-lint .

- name: Test plugin bootstrap
run: |
for scenario in direct xmlrpc normal false; do
php tests/plugin.php "$scenario" || exit 1
done
18 changes: 14 additions & 4 deletions .github/workflows/playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Playground Comment
on:
pull_request:

permissions:
contents: read

jobs:
playground:
runs-on: ubuntu-latest
Expand All @@ -14,16 +17,19 @@ jobs:
LANDING_PAGE: "/wp-admin/"

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

# Prepare a folder named exactly like the repo as the plugin root.
# If the repo already has such a folder (common for WP plugins), use it.
# Otherwise, stage one and copy root files into it (excluding CI junk).
- name: Prepare plugin folder
id: prep
env:
REPO: ${{ github.event.repository.name }}
run: |
set -euxo pipefail
REPO="${{ github.event.repository.name }}"
if [ -d "$REPO" ]; then
# Plugin already lives in a subfolder named like the repo
echo "PKG_DIR=$REPO" >> "$GITHUB_OUTPUT"
Expand All @@ -35,6 +41,7 @@ jobs:
--exclude='.git' \
--exclude='.github' \
--exclude='node_modules' \
--exclude='tests' \
--exclude="${STAGE}" \
./ "$STAGE/$REPO/"
echo "PKG_DIR=$STAGE/$REPO" >> "$GITHUB_OUTPUT"
Expand All @@ -43,17 +50,20 @@ jobs:
# Upload the FOLDER (not a .zip). The artifact service zips it for us,
# keeping the top-level folder name inside the archive.
- name: Upload plugin artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ${{ github.event.repository.name }}
path: ${{ steps.prep.outputs.PKG_DIR }}
# Optional: faster uploads for already-compressed assets
compression-level: 0

# Comment with a Playground link that installs from the artifact ZIP
- uses: mshick/add-pr-comment@v2
- uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2
if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'
with:
message: |
**Test on Playground**
[Test this pull request on the Playground](https://playground.wordpress.net/#{"landingPage":"${{ env.LANDING_PAGE }}","features":{"networking":true},"steps":[{"step":"defineWpConfigConsts","consts":{"IS_PLAYGROUND_PREVIEW":true}},{"step":"login","username":"admin","password":"password"},{"step":"installPlugin","pluginZipFile":{"resource":"url","url":"https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip"},"options":{"activate":true}}]})
or [download the zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip)

This disposable preview downloads the PR artifact through the third-party nightly.link service; do not enter production credentials or private data.
8 changes: 6 additions & 2 deletions .github/workflows/wpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
pull_request:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand All @@ -17,12 +20,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: WPCS check
uses: 10up/wpcs-action@stable
uses: 10up/wpcs-action@39f1a9eb6139795e6798d11b51eeecf5a9678ccc # stable
with:
enable_warnings: true
standard: WordPress
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Once activated, the plugin:

- disables WordPress XML-RPC through the relevant filter
- blocks XML-RPC requests directly
- shows a clear “XML-RPC Disabled” response when access is attempted
- returns HTTP 403 with an empty body when XML-RPC access is attempted

There are no settings to configure.

Expand All @@ -72,6 +72,28 @@ This is a deliberately small utility plugin. If you want to review behavior, sta

- `pp-disable-xml-rpc.php`

XML-RPC requests receive HTTP 403 and stop when this plugin loads. Some WordPress
bootstrap work has already happened at that point. For protection against request
floods, block `xmlrpc.php` at your web server or edge before PHP runs.

Releases are deployed by pushing a `v*` tag. The repository's active release-tag
ruleset restricts creating, changing, and deleting these tags to repository admins.
Review the tagged commit before pushing it. The GitHub release is created only
after the WordPress.org deployment succeeds.

Playground previews use nightly.link to serve the workflow artifact publicly.
Use them only as disposable test sites without production credentials or private
data. Fork and Dependabot PRs still upload artifacts but skip posting comments
because their workflow tokens cannot write PR comments.

Run the plugin regression checks with:

```sh
for scenario in direct xmlrpc normal false; do
php tests/plugin.php "$scenario" || exit 1
done
```

## License

MIT. See [LICENSE](LICENSE).
Expand Down
35 changes: 8 additions & 27 deletions pp-disable-xml-rpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,14 @@
* Text Domain: pp-disable-xml-rpc
*/

// Disable XML-RPC using the 'xmlrpc_enabled' filter.
add_filter( 'xmlrpc_enabled', '__return_false' );

/**
* Die to prevent XMLRPC requests.
*/
function pp_disable_xml_rpc_die() {
wp_die(
__( 'XML-RPC services are disabled on this site.', 'pp-disable-xml-rpc' ),
__( 'XML-RPC Disabled', 'pp-disable-xml-rpc' ),
array( 'response' => 403 )
);
}
defined( 'ABSPATH' ) || exit;

// Add an empty class to bypass Core.
class pp_wp_xmlrpc_server {
public function serve_request() {
pp_disable_xml_rpc_die();
}
// Stop XML-RPC during plugin loading, before the remaining WordPress bootstrap.
// The XML-RPC wp_die() handler cannot send this response before its server exists.
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
status_header( 403 );
exit;
}
add_filter( 'wp_xmlrpc_server_class', function() {
return 'pp_wp_xmlrpc_server';
} );

// Bail early if XMLRPC_REQUEST is defined.
add_action( 'init', function() {
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
pp_disable_xml_rpc_die();
}
} );
// Disable XML-RPC using the 'xmlrpc_enabled' filter.
add_filter( 'xmlrpc_enabled', '__return_false' );
71 changes: 71 additions & 0 deletions tests/plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Minimal bootstrap regression checks; run each scenario in a separate process.
*
* @package Progress_Planner_Disable_XMLRPC
*/

// CLI-only fixture: WordPress filesystem and escaping helpers are unavailable.
// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_fwrite

$scenario = isset( $argv[1] ) ? $argv[1] : '';
if ( ! in_array( $scenario, array( 'direct', 'xmlrpc', 'normal', 'false' ), true ) ) {
fwrite( STDERR, "Expected scenario: direct, xmlrpc, normal, or false.\n" );
exit( 1 );
}

$completed = false;
$filters = array();

// Turn PHP notices and warnings into failures, including direct-access errors.
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler -- Fail on warnings in the test process.
set_error_handler(
function ( $severity, $message ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- CLI exception, not HTML output.
throw new ErrorException( $message, 0, $severity );
}
);

register_shutdown_function(
function () use ( $scenario, &$completed, &$filters ) {
$blocked = in_array( $scenario, array( 'direct', 'xmlrpc' ), true );
$output = ob_get_clean();
$valid = null === error_get_last() && ( $blocked ? ! $completed : $completed );
$valid = $valid && '' === $output;
$valid = $valid && http_response_code() === ( 'xmlrpc' === $scenario ? 403 : 200 );
$valid = $valid && ( $blocked ? array() : array( 'xmlrpc_enabled' => '__return_false' ) ) === $filters;
fwrite( $valid ? STDOUT : STDERR, ( $valid ? 'PASS: ' : 'FAIL: ' ) . $scenario . "\n" );
exit( $valid ? 0 : 1 );
}
);

/**
* Record filter registration without bootstrapping WordPress.
*
* @param string $hook Filter name.
* @param string $callback Callback name.
*/
function add_filter( $hook, $callback ) {
$GLOBALS['filters'][ $hook ] = $callback;
}

/**
* Set a response code without bootstrapping WordPress.
*
* @param int $status HTTP response code.
*/
function status_header( $status ) {
http_response_code( $status );
}

http_response_code( 200 );
ob_start();
if ( 'direct' !== $scenario ) {
define( 'ABSPATH', __DIR__ . '/' );
}
if ( in_array( $scenario, array( 'xmlrpc', 'false' ), true ) ) {
define( 'XMLRPC_REQUEST', 'xmlrpc' === $scenario );
}

require dirname( __DIR__ ) . '/pp-disable-xml-rpc.php';
$completed = true;
Loading