v1.6.2
This commit is contained in:
parent
1f7343cd9d
commit
3e4433cd13
11 changed files with 1720 additions and 441 deletions
|
|
@ -1,5 +1,31 @@
|
|||
== Changelog ==
|
||||
|
||||
= 1.6.2 =
|
||||
|
||||
_Release date: 2026-08-17_
|
||||
|
||||
**Added**
|
||||
|
||||
* Recommendation notice for the Manager (by ROBOTSTXT) plugin: when it is not installed and active, a dismissible notice appears on the Plugins screen and a permanent notice is shown on the plugin settings page, since updates are delivered through the Manager plugin.
|
||||
|
||||
**Changed**
|
||||
|
||||
* Updates are now handled by the Manager (by ROBOTSTXT) plugin. The bundled self-updater (robotstxt-updater.php and update.json) has been removed.
|
||||
* Plugin and update URLs moved to robotstxt.software.
|
||||
* Minimum WordPress version lowered from 6.4 to 5.6 after a full compatibility review (the code only requires WordPress 5.3+ functions, and WordPress 5.6 is the first release that runs on the required PHP 8.0).
|
||||
|
||||
**Compatibility**
|
||||
|
||||
* WordPress: 5.6 – 7.1
|
||||
* PHP: 8.0 – 8.5
|
||||
|
||||
**Tests**
|
||||
|
||||
* PHP Coding Standards: PHP_CodeSniffer 3.13.6 / WPCS 3.4.1 — 0 errors
|
||||
* PHPStan: level 9 — 0 errors
|
||||
* PHPCompatibility: 8.0–8.5 — 0 issues
|
||||
* PHPUnit: 9.6.36 — 59 tests, 148 assertions
|
||||
|
||||
= 1.6.1 =
|
||||
|
||||
_Release date: 2026-08-14_
|
||||
|
|
|
|||
184
includes/admin/class-manager-notice.php
Normal file
184
includes/admin/class-manager-notice.php
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
<?php
|
||||
/**
|
||||
* Manager plugin dependency notice.
|
||||
*
|
||||
* @package Robotstxt_2FA
|
||||
*/
|
||||
|
||||
namespace Robotstxt\TwoFA\Admin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies administrators when the Manager (by ROBOTSTXT) plugin is missing.
|
||||
*
|
||||
* The Manager plugin delivers updates for ROBOTSTXT plugins. Without it, this
|
||||
* plugin cannot receive updates. A dismissible notice is shown on the plugins
|
||||
* list screen and a persistent notice is rendered on the plugin settings page.
|
||||
*/
|
||||
class Manager_Notice {
|
||||
|
||||
/**
|
||||
* Basename of the Manager plugin main file.
|
||||
*/
|
||||
private const MANAGER_BASENAME = 'robotstxt-manager/robotstxt-manager.php';
|
||||
|
||||
/**
|
||||
* URL of the Manager plugin page.
|
||||
*/
|
||||
private const MANAGER_URL = 'https://www.robotstxt.software/plugins/robotstxt-manager/';
|
||||
|
||||
/**
|
||||
* Action used to dismiss the plugins screen notice.
|
||||
*/
|
||||
private const DISMISS_ACTION = 'robotstxt_2fa_dismiss_manager_notice';
|
||||
|
||||
/**
|
||||
* User meta key storing the dismissal flag.
|
||||
*/
|
||||
private const DISMISSED_META_KEY = 'robotstxt_2fa_manager_notice_dismissed';
|
||||
|
||||
/**
|
||||
* Register WordPress hooks.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_hooks(): void {
|
||||
add_action( 'admin_notices', array( $this, 'maybe_show_plugins_notice' ) );
|
||||
add_action( 'network_admin_notices', array( $this, 'maybe_show_plugins_notice' ) );
|
||||
add_action( 'admin_init', array( $this, 'maybe_handle_dismiss' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the Manager (by ROBOTSTXT) plugin is active.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @return bool True when the manager plugin is active.
|
||||
*/
|
||||
public static function is_manager_active(): bool {
|
||||
if ( ! function_exists( 'is_plugin_active' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
return is_plugin_active( self::MANAGER_BASENAME );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a dismissible notice on the plugins list screen when the manager is missing.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_show_plugins_notice(): void {
|
||||
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
|
||||
|
||||
if ( null === $screen ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( self::is_manager_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( get_user_meta( get_current_user_id(), self::DISMISSED_META_KEY, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dismiss_url = wp_nonce_url(
|
||||
add_query_arg( 'action', self::DISMISS_ACTION, self_admin_url( 'admin.php' ) ),
|
||||
self::DISMISS_ACTION
|
||||
);
|
||||
?>
|
||||
<div class="notice notice-warning">
|
||||
<p>
|
||||
<strong><?php esc_html_e( '2FA (by ROBOTSTXT):', 'robotstxt-2fa' ); ?></strong>
|
||||
<?php
|
||||
echo wp_kses_post(
|
||||
sprintf(
|
||||
/* translators: %s: URL of the Manager (by ROBOTSTXT) plugin page. */
|
||||
__( 'This plugin needs <a href="%s">Manager (by ROBOTSTXT)</a> to be installed and active to receive updates.', 'robotstxt-2fa' ),
|
||||
esc_url( self::MANAGER_URL )
|
||||
)
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<p style="margin-top:0;">
|
||||
<a href="<?php echo esc_url( $dismiss_url ); ?>" style="font-size:0.875em;"><?php esc_html_e( 'Dismiss this notice', 'robotstxt-2fa' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the persistent manager notice shown on the plugin settings page.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function render_settings_notice(): void {
|
||||
if ( self::is_manager_active() ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<div class="notice notice-warning inline">
|
||||
<p>
|
||||
<strong><?php esc_html_e( 'Manager (by ROBOTSTXT) is not active.', 'robotstxt-2fa' ); ?></strong>
|
||||
<?php
|
||||
echo wp_kses_post(
|
||||
sprintf(
|
||||
/* translators: %s: URL of the Manager (by ROBOTSTXT) plugin page. */
|
||||
__( 'This plugin needs <a href="%s">Manager (by ROBOTSTXT)</a> to be installed and active to receive updates.', 'robotstxt-2fa' ),
|
||||
esc_url( self::MANAGER_URL )
|
||||
)
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the dismiss-notice GET request.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_handle_dismiss(): void {
|
||||
if ( ! isset( $_GET['action'] ) || self::DISMISS_ACTION !== $_GET['action'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$nonce_raw = isset( $_GET['_wpnonce'] ) && is_string( $_GET['_wpnonce'] )
|
||||
? sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) )
|
||||
: '';
|
||||
|
||||
if ( ! wp_verify_nonce( $nonce_raw, self::DISMISS_ACTION ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
update_user_meta( get_current_user_id(), self::DISMISSED_META_KEY, 1 );
|
||||
|
||||
wp_safe_redirect( remove_query_arg( array( 'action', '_wpnonce' ) ) );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
@ -101,6 +101,8 @@ class Settings_Page {
|
|||
|
||||
settings_errors( self::OPTION_NAME );
|
||||
|
||||
Manager_Notice::render_settings_notice();
|
||||
|
||||
$form_action = $this->is_network_context()
|
||||
? network_admin_url( 'edit.php?action=robotstxt_2fa_network_save' )
|
||||
: 'options.php';
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
namespace Robotstxt\TwoFA;
|
||||
|
||||
use Robotstxt\TwoFA\Admin\Dashboard_Page;
|
||||
use Robotstxt\TwoFA\Admin\Manager_Notice;
|
||||
use Robotstxt\TwoFA\Admin\Migration_Page;
|
||||
use Robotstxt\TwoFA\Admin\Settings_Page;
|
||||
use Robotstxt\TwoFA\Cli\Cli_Command;
|
||||
|
|
@ -134,6 +135,13 @@ class Plugin {
|
|||
*/
|
||||
private Migration_Page $migration_page;
|
||||
|
||||
/**
|
||||
* Manager plugin dependency notice.
|
||||
*
|
||||
* @var Manager_Notice
|
||||
*/
|
||||
private Manager_Notice $manager_notice;
|
||||
|
||||
/**
|
||||
* REST API controller.
|
||||
*
|
||||
|
|
@ -174,6 +182,7 @@ class Plugin {
|
|||
$this->geoip_updater = new GeoIP_Updater( $config );
|
||||
$this->dashboard_page = new Dashboard_Page( $this->attempts_log, $config, $repository );
|
||||
$this->migration_page = new Migration_Page();
|
||||
$this->manager_notice = new Manager_Notice();
|
||||
$this->rest_controller = new Rest_Controller();
|
||||
}
|
||||
|
||||
|
|
@ -191,6 +200,7 @@ class Plugin {
|
|||
$this->geoip_updater->register_hooks();
|
||||
$this->dashboard_page->register_hooks();
|
||||
$this->migration_page->register_hooks();
|
||||
$this->manager_notice->register_hooks();
|
||||
$this->rest_controller->register_hooks();
|
||||
$this->login_manager->register_hooks();
|
||||
$this->profile_settings->register_hooks();
|
||||
|
|
|
|||
1468
languages/robotstxt-2fa.pot
Normal file
1468
languages/robotstxt-2fa.pot
Normal file
File diff suppressed because it is too large
Load diff
40
readme.txt
40
readme.txt
|
|
@ -1,10 +1,10 @@
|
|||
=== 2FA (by ROBOTSTXT) ===
|
||||
Contributors: robotstxt
|
||||
Contributors: robotstxt, javiercasares
|
||||
Tags: security, two-factor authentication, login, otp
|
||||
Requires at least: 6.4
|
||||
Requires at least: 5.6
|
||||
Tested up to: 7.0
|
||||
Requires PHP: 8.0
|
||||
Stable tag: 1.6.1
|
||||
Stable tag: 1.6.2
|
||||
License: GPLv3 or later
|
||||
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
|
|
@ -53,12 +53,26 @@ Yes. Activate the plugin at the network level. Network administrators can set an
|
|||
|
||||
== Compatibility ==
|
||||
|
||||
* WordPress: 6.4 – 7.0
|
||||
* WordPress: 5.6 – 7.0
|
||||
* PHP: 8.0 – 8.5
|
||||
* MariaDB: 11.4 or newer
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.6.2 =
|
||||
|
||||
_Release date: 2026-08-17_
|
||||
|
||||
**Added**
|
||||
|
||||
* Recommendation notice for the Manager (by ROBOTSTXT) plugin: when it is not installed and active, a dismissible notice appears on the Plugins screen and a permanent notice is shown on the plugin settings page, since updates are delivered through the Manager plugin.
|
||||
|
||||
**Changed**
|
||||
|
||||
* Updates are now handled by the Manager (by ROBOTSTXT) plugin. The bundled self-updater (`robotstxt-updater.php` and `update.json`) has been removed.
|
||||
* Plugin and update URLs moved to `robotstxt.software`.
|
||||
* Minimum WordPress version lowered from 6.4 to 5.6 after a full compatibility review (the code only requires WordPress 5.3+ functions, and WordPress 5.6 is the first release that runs on the required PHP 8.0).
|
||||
|
||||
= 1.6.1 =
|
||||
|
||||
_Release date: 2026-08-14_
|
||||
|
|
@ -82,25 +96,9 @@ _Release date: 2026-08-07_
|
|||
|
||||
* `wp 2fa list` now shows separate **Enabled**, **Methods** (configured), and **Required** (role-enforced) columns, plus a new `--required` filter to list only users whose role enforces 2FA.
|
||||
|
||||
= 1.5.3 =
|
||||
|
||||
_Release date: 2026-08-07_
|
||||
|
||||
**Added**
|
||||
|
||||
* Per-user preferred sign-in method — a new "Preferred method" dropdown on the user profile (visible when two or more methods are enabled) lets each user choose which verification method is requested first at the login screen. Users can still switch methods on the login screen via the existing alternate-method links.
|
||||
|
||||
**Changed**
|
||||
|
||||
* Role enforcement is now a floor, not a ceiling. When a role requires specific methods, those methods are still forced on the user's profile (enforced setup), but at login users may authenticate with any method they have configured — not only the role-required ones. Previously, users who configured extra methods (e.g. an authenticator app) only saw the role-required method at login.
|
||||
|
||||
**Fixed**
|
||||
|
||||
* Security: the "Require 2FA to create Application Passwords" check could be bypassed via the `/wp/v2/users/me/application-passwords` REST route. The route matcher now accepts the `me` alias.
|
||||
|
||||
= Previous versions =
|
||||
|
||||
For the full changelog see the [changelog.txt](https://git.robotstxt.es/ROBOTSTXT/robotstxt-2fa/raw/branch/main/changelog.txt) file.
|
||||
For the full changelog see the [changelog](https://www.robotstxt.software/plugins/robotstxt-2fa/) page.
|
||||
|
||||
== Compliance ==
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin Name: 2FA (by ROBOTSTXT)
|
||||
* Plugin URI: https://www.robotstxt.es/plugins/robotstxt-2fa/
|
||||
* Plugin URI: https://www.robotstxt.software/plugins/robotstxt-2fa/
|
||||
* Update URI: https://www.robotstxt.software/plugins/robotstxt-2fa/
|
||||
* Description: Adds two-factor authentication to the WordPress login flow.
|
||||
* Version: 1.6.1
|
||||
* Version: 1.6.2
|
||||
* Author: ROBOTSTXT
|
||||
* Author URI: https://www.robotstxt.es/
|
||||
* Author URI: https://www.robotstxt.software/
|
||||
* Text Domain: robotstxt-2fa
|
||||
* Requires at least: 6.4
|
||||
* Domain Path: /languages
|
||||
* Requires at least: 5.6
|
||||
* Requires PHP: 8.0
|
||||
* Network: true
|
||||
* License: GPLv3 or later
|
||||
|
|
@ -23,7 +25,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
}
|
||||
|
||||
if ( ! defined( 'ROBOTSTXT_2FA_VERSION' ) ) {
|
||||
define( 'ROBOTSTXT_2FA_VERSION', '1.6.1' );
|
||||
define( 'ROBOTSTXT_2FA_VERSION', '1.6.2' );
|
||||
}
|
||||
|
||||
if ( ! defined( 'ROBOTSTXT_2FA_FILE' ) ) {
|
||||
|
|
|
|||
|
|
@ -1,384 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Generic JSON-based updater for ROBOTSTXT plugins.
|
||||
*
|
||||
* This file is designed to be copied to any ROBOTSTXT plugin.
|
||||
* It auto-configures itself by reading the plugin headers.
|
||||
*
|
||||
* @package ROBOTSTXT
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Robotstxt_Updater' ) ) {
|
||||
/**
|
||||
* Class Robotstxt_Updater
|
||||
*
|
||||
* Generic updater that works with any plugin.
|
||||
* Reads plugin headers and constructs update URL automatically.
|
||||
*/
|
||||
class Robotstxt_Updater {
|
||||
|
||||
/**
|
||||
* Plugin file path.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $plugin_file_path;
|
||||
|
||||
/**
|
||||
* Plugin basename (e.g., 'my-plugin/my-plugin.php').
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $plugin_basename;
|
||||
|
||||
/**
|
||||
* Plugin slug (directory name).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $plugin_slug;
|
||||
|
||||
/**
|
||||
* Remote JSON URL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $json_url;
|
||||
|
||||
/**
|
||||
* Cache key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $cache_key;
|
||||
|
||||
/**
|
||||
* Plugin headers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private array $plugin_data;
|
||||
|
||||
/**
|
||||
* Initialize the updater.
|
||||
*
|
||||
* Usage in your main plugin file:
|
||||
* require_once __DIR__ . '/robotstxt-updater.php';
|
||||
* Robotstxt_Updater::init( __FILE__ );
|
||||
*
|
||||
* @param string $plugin_file_path Absolute path to the main plugin file.
|
||||
*/
|
||||
public static function init( string $plugin_file_path ): void {
|
||||
$instance = new self( $plugin_file_path );
|
||||
$instance->register();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $plugin_file_path Absolute path to the main plugin file.
|
||||
*/
|
||||
private function __construct( string $plugin_file_path ) {
|
||||
$this->plugin_file_path = $plugin_file_path;
|
||||
$this->plugin_basename = plugin_basename( $plugin_file_path );
|
||||
$this->plugin_slug = dirname( $this->plugin_basename );
|
||||
$this->plugin_data = $this->get_plugin_data();
|
||||
$this->json_url = $this->build_json_url();
|
||||
$this->cache_key = 'robotstxt_updater_' . md5( $this->plugin_basename );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register WordPress hooks.
|
||||
*/
|
||||
private function register(): void {
|
||||
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'inject_update_info' ) );
|
||||
add_filter( 'plugins_api', array( $this, 'provide_plugin_details' ), 10, 3 );
|
||||
add_action( 'admin_init', array( $this, 'handle_cache_clear' ) );
|
||||
add_action( 'robotstxt_updater_clear_cache', array( $this, 'clear_cache' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin headers.
|
||||
*
|
||||
* @return array Plugin data.
|
||||
*/
|
||||
private function get_plugin_data(): array {
|
||||
if ( ! function_exists( 'get_plugin_data' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
return get_plugin_data( $this->plugin_file_path, false, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build JSON URL from plugin headers.
|
||||
*
|
||||
* Tries to use "Gitea Plugin URI" header to construct the URL.
|
||||
* Falls back to Plugin URI if Gitea URI is not available.
|
||||
*
|
||||
* @return string JSON URL.
|
||||
*/
|
||||
private function build_json_url(): string {
|
||||
// Try Gitea Plugin URI (format: "OWNER/REPO" or full URL).
|
||||
if ( ! empty( $this->plugin_data['Gitea Plugin URI'] ) ) {
|
||||
$gitea_uri = $this->plugin_data['Gitea Plugin URI'];
|
||||
|
||||
// If it's already a full URL, use it.
|
||||
if ( str_starts_with( $gitea_uri, 'http' ) ) {
|
||||
// Extract base URL and construct JSON path.
|
||||
return rtrim( $gitea_uri, '/' ) . '/raw/branch/main/update.json';
|
||||
}
|
||||
|
||||
// If it's in format "OWNER/REPO", construct full URL.
|
||||
if ( preg_match( '#^[^/]+/[^/]+$#', $gitea_uri ) ) {
|
||||
return "https://git.robotstxt.es/{$gitea_uri}/raw/branch/main/update.json";
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: try to extract from Plugin URI.
|
||||
if ( ! empty( $this->plugin_data['PluginURI'] ) ) {
|
||||
$plugin_uri = $this->plugin_data['PluginURI'];
|
||||
if ( str_contains( $plugin_uri, 'git.robotstxt.es' ) ) {
|
||||
return rtrim( $plugin_uri, '/' ) . '/raw/branch/main/update.json';
|
||||
}
|
||||
}
|
||||
|
||||
// Last resort: construct from plugin slug.
|
||||
return "https://git.robotstxt.es/ROBOTSTXT/{$this->plugin_slug}/raw/branch/main/update.json";
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject update info into WP's plugin update transient.
|
||||
*
|
||||
* @param object|mixed $transient The update_plugins transient.
|
||||
*
|
||||
* @return object The modified transient.
|
||||
*/
|
||||
public function inject_update_info( $transient ) {
|
||||
if ( ! is_object( $transient ) ) {
|
||||
$transient = new stdClass();
|
||||
}
|
||||
|
||||
if ( empty( $transient->checked ) || ! is_array( $transient->checked ) ) {
|
||||
return $transient;
|
||||
}
|
||||
|
||||
if ( empty( $transient->checked[ $this->plugin_basename ] ) ) {
|
||||
return $transient;
|
||||
}
|
||||
|
||||
$current_version = $transient->checked[ $this->plugin_basename ];
|
||||
$remote = $this->get_remote_data();
|
||||
|
||||
if ( empty( $remote['version'] ) || empty( $remote['download_url'] ) ) {
|
||||
return $transient;
|
||||
}
|
||||
|
||||
if ( ! $this->is_compatible( $remote ) ) {
|
||||
return $transient;
|
||||
}
|
||||
|
||||
if ( version_compare( $remote['version'], $current_version, '>' ) ) {
|
||||
$update = (object) array(
|
||||
'slug' => $remote['slug'] ?? $this->plugin_slug,
|
||||
'plugin' => $this->plugin_basename,
|
||||
'new_version' => $remote['version'],
|
||||
'url' => $remote['homepage'] ?? $this->plugin_data['PluginURI'] ?? '',
|
||||
'package' => $remote['download_url'],
|
||||
'tested' => $remote['tested'] ?? '',
|
||||
'requires' => $remote['requires'] ?? '',
|
||||
'requires_php' => $remote['requires_php'] ?? '',
|
||||
);
|
||||
|
||||
$transient->response[ $this->plugin_basename ] = $update;
|
||||
}
|
||||
|
||||
return $transient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide "View details" modal content.
|
||||
*
|
||||
* @param false|object|array $result The result object or array.
|
||||
* @param string $action The type of information being requested.
|
||||
* @param object $args Plugin API arguments.
|
||||
*
|
||||
* @return false|object The plugin information object or false.
|
||||
*/
|
||||
public function provide_plugin_details( $result, string $action, object $args ) {
|
||||
if ( 'plugin_information' !== $action ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( empty( $args->slug ) || $args->slug !== $this->plugin_slug ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$remote = $this->get_remote_data();
|
||||
|
||||
if ( empty( $remote['version'] ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return (object) array(
|
||||
'name' => $remote['name'] ?? $this->plugin_data['Name'] ?? $this->plugin_slug,
|
||||
'slug' => $remote['slug'] ?? $this->plugin_slug,
|
||||
'version' => $remote['version'],
|
||||
'author' => $remote['author'] ?? $this->plugin_data['Author'] ?? '',
|
||||
'homepage' => $remote['homepage'] ?? $this->plugin_data['PluginURI'] ?? '',
|
||||
'requires' => $remote['requires'] ?? '',
|
||||
'tested' => $remote['tested'] ?? '',
|
||||
'requires_php' => $remote['requires_php'] ?? '',
|
||||
'sections' => array(
|
||||
'description' => $remote['description'] ?? $this->plugin_data['Description'] ?? '',
|
||||
'changelog' => $remote['changelog'] ?? '',
|
||||
),
|
||||
'download_link' => $remote['download_url'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get remote data with caching and HMAC signature verification.
|
||||
*
|
||||
* @return array Remote data.
|
||||
*/
|
||||
private function get_remote_data(): array {
|
||||
$cached = get_site_transient( $this->cache_key );
|
||||
|
||||
// Verify HMAC signature if AUTH_SALT is defined and cache has signature.
|
||||
if ( false !== $cached && defined( 'AUTH_SALT' ) && '' !== AUTH_SALT ) {
|
||||
if ( is_array( $cached ) && isset( $cached['signature'], $cached['data'] ) ) {
|
||||
$expected_sig = hash_hmac( 'sha256', $this->cache_key . serialize( $cached['data'] ), AUTH_SALT ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Used for HMAC signing, not for unserializing untrusted data.
|
||||
|
||||
if ( hash_equals( $expected_sig, $cached['signature'] ) ) {
|
||||
// Signature valid, return data.
|
||||
return is_array( $cached['data'] ) ? $cached['data'] : array();
|
||||
}
|
||||
|
||||
// Signature invalid, delete corrupted cache.
|
||||
delete_site_transient( $this->cache_key );
|
||||
$cached = false;
|
||||
}
|
||||
}
|
||||
|
||||
// If no valid cache, fetch fresh data.
|
||||
if ( false === $cached ) {
|
||||
$remote = $this->fetch_json();
|
||||
|
||||
// Store with HMAC signature if AUTH_SALT is available.
|
||||
if ( defined( 'AUTH_SALT' ) && '' !== AUTH_SALT ) {
|
||||
$remote_data = is_array( $remote ) ? $remote : array();
|
||||
$payload = array(
|
||||
'data' => $remote_data,
|
||||
'timestamp' => time(),
|
||||
'signature' => hash_hmac( 'sha256', $this->cache_key . serialize( $remote_data ), AUTH_SALT ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Used for HMAC signing, not for unserializing untrusted data.
|
||||
);
|
||||
set_site_transient( $this->cache_key, $payload, 6 * HOUR_IN_SECONDS );
|
||||
} else {
|
||||
// Fallback to standard caching.
|
||||
set_site_transient( $this->cache_key, is_array( $remote ) ? $remote : array(), 6 * HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
return is_array( $remote ) ? $remote : array();
|
||||
}
|
||||
|
||||
// Legacy cache format without signature (backward compatibility).
|
||||
return is_array( $cached ) ? $cached : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch JSON from remote URL.
|
||||
*
|
||||
* @return array Decoded JSON data.
|
||||
*/
|
||||
private function fetch_json(): array {
|
||||
$response = wp_remote_get(
|
||||
$this->json_url,
|
||||
array(
|
||||
'timeout' => 10,
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$code = (int) wp_remote_retrieve_response_code( $response );
|
||||
if ( $code < 200 || $code >= 300 ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
$data = json_decode( $body, true );
|
||||
|
||||
return is_array( $data ) ? $data : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check compatibility.
|
||||
*
|
||||
* @param array $remote Remote data.
|
||||
*
|
||||
* @return bool True if compatible.
|
||||
*/
|
||||
private function is_compatible( array $remote ): bool {
|
||||
if ( ! empty( $remote['requires_php'] ) ) {
|
||||
if ( version_compare( PHP_VERSION, $remote['requires_php'], '<' ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $remote['requires'] ) ) {
|
||||
if ( version_compare( get_bloginfo( 'version' ), $remote['requires'], '<' ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle manual cache clear via URL parameter.
|
||||
*/
|
||||
public function handle_cache_clear(): void {
|
||||
// Check if this is a cache clear request first.
|
||||
$clear_cache = filter_input( INPUT_GET, 'robotstxt_clear_update_cache', FILTER_UNSAFE_RAW );
|
||||
if ( null === $clear_cache ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// This is a cache clear request - now verify nonce.
|
||||
$nonce_raw = filter_input( INPUT_GET, '_wpnonce', FILTER_UNSAFE_RAW );
|
||||
$nonce = $nonce_raw ? sanitize_text_field( wp_unslash( $nonce_raw ) ) : '';
|
||||
|
||||
if ( ! wp_verify_nonce( $nonce, 'robotstxt_clear_update_cache' ) ) {
|
||||
wp_die( esc_html__( 'Security check failed', 'robotstxt-2fa' ) );
|
||||
}
|
||||
|
||||
// Check permissions.
|
||||
if ( ! current_user_can( 'update_plugins' ) ) {
|
||||
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'robotstxt-2fa' ) );
|
||||
}
|
||||
|
||||
$this->clear_cache();
|
||||
wp_safe_redirect( remove_query_arg( array( 'robotstxt_clear_update_cache', '_wpnonce' ) ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear update cache.
|
||||
*/
|
||||
public function clear_cache(): void {
|
||||
delete_site_transient( $this->cache_key );
|
||||
delete_site_transient( 'update_plugins' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"name": "2FA (by ROBOTSTXT)",
|
||||
"slug": "robotstxt-2fa",
|
||||
"version": "1.6.1",
|
||||
"download_url": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-2fa/releases/download/1.6.1/robotstxt-2fa-1.6.1.zip",
|
||||
"version": "1.6.2",
|
||||
"download_url": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-2fa/releases/download/1.6.2/robotstxt-2fa-1.6.2.zip",
|
||||
"requires": "6.4",
|
||||
"requires_php": "8.0",
|
||||
"tested": "7.1",
|
||||
|
|
@ -11,10 +11,10 @@
|
|||
"author_profile": "https://www.robotstxt.es/",
|
||||
"homepage": "https://www.robotstxt.es/plugins/robotstxt-2fa/",
|
||||
"description": "Adds per-role two-factor authentication to the WordPress login flow. Supports email codes, authenticator apps (TOTP), and recovery codes.",
|
||||
"changelog": "<h3>1.6.1 - 2026-08-14</h3><ul><li><strong>Fixed:</strong> Fatal error during editor autosaves — the <code>[robotstxt_2fa_profile]</code> shortcode expanded when WordPress applied content filters to a post revision via REST (e.g. an article that merely mentions the shortcode). The shortcode now bails out early on REST requests and loads the required wp-admin includes on demand elsewhere.</li></ul>",
|
||||
"changelog": "",
|
||||
"sections": {
|
||||
"description": "Adds per-role two-factor authentication to the WordPress login flow. Supports email codes, authenticator apps (TOTP), and recovery codes.",
|
||||
"changelog": "<h3>1.6.1 - 2026-08-14</h3><ul><li><strong>Fixed:</strong> Fatal error during editor autosaves — the <code>[robotstxt_2fa_profile]</code> shortcode expanded when WordPress applied content filters to a post revision via REST (e.g. an article that merely mentions the shortcode). The shortcode now bails out early on REST requests and loads the required wp-admin includes on demand elsewhere.</li></ul>"
|
||||
"changelog": ""
|
||||
},
|
||||
"banners": { "low": "", "high": "" },
|
||||
"icons": { "1x": "", "2x": "" }
|
||||
|
|
|
|||
2
vendor/composer/autoload_real.php
vendored
2
vendor/composer/autoload_real.php
vendored
|
|
@ -22,8 +22,6 @@ class ComposerAutoloaderInit3c8f2c10a8655d88b9115205b533c7e2
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
require __DIR__ . '/platform_check.php';
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit3c8f2c10a8655d88b9115205b533c7e2', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit3c8f2c10a8655d88b9115205b533c7e2', 'loadClassLoader'));
|
||||
|
|
|
|||
25
vendor/composer/platform_check.php
vendored
25
vendor/composer/platform_check.php
vendored
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
// platform_check.php @generated by Composer
|
||||
|
||||
$issues = array();
|
||||
|
||||
if (!(PHP_VERSION_ID >= 80200)) {
|
||||
$issues[] = 'Your Composer dependencies require a PHP version ">= 8.2.0". You are running ' . PHP_VERSION . '.';
|
||||
}
|
||||
|
||||
if ($issues) {
|
||||
if (!headers_sent()) {
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
if (!ini_get('display_errors')) {
|
||||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
|
||||
} elseif (!headers_sent()) {
|
||||
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
|
||||
}
|
||||
}
|
||||
throw new \RuntimeException(
|
||||
'Composer detected issues in your platform: ' . implode(' ', $issues)
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue