You've already forked wp-prometheus
fix: Localhost license bypass, rewrite rules flush, WooCommerce orders (v0.2.2)
All checks were successful
Create Release Package / build-release (push) Successful in 56s
All checks were successful
Create Release Package / build-release (push) Successful in 56s
- Add localhost license bypass for development environments - Flush rewrite rules when license status changes to fix 404 on /metrics - Fix wc_orders_count() missing required status parameter Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -302,10 +302,47 @@ final class Manager {
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_license_valid(): bool {
|
||||
// Bypass license check on localhost for development.
|
||||
if ( self::is_localhost() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$status = get_option( self::OPTION_LICENSE_STATUS, 'unchecked' );
|
||||
return 'valid' === $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current site is running on localhost.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_localhost(): bool {
|
||||
$host = wp_parse_url( home_url(), PHP_URL_HOST );
|
||||
|
||||
$localhost_patterns = array(
|
||||
'localhost',
|
||||
'127.0.0.1',
|
||||
'::1',
|
||||
);
|
||||
|
||||
// Check exact matches.
|
||||
if ( in_array( $host, $localhost_patterns, true ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check .localhost TLD (e.g., mysite.localhost).
|
||||
if ( str_ends_with( $host, '.localhost' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check .local TLD (common for local development).
|
||||
if ( str_ends_with( $host, '.local' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the license key.
|
||||
*
|
||||
@@ -396,9 +433,16 @@ final class Manager {
|
||||
* @return void
|
||||
*/
|
||||
private function update_cached_status( string $status, array $data = array() ): void {
|
||||
$previous_status = get_option( self::OPTION_LICENSE_STATUS, 'unchecked' );
|
||||
|
||||
update_option( self::OPTION_LICENSE_STATUS, $status );
|
||||
update_option( self::OPTION_LICENSE_DATA, $data );
|
||||
update_option( self::OPTION_LAST_CHECK, time() );
|
||||
|
||||
// Flush rewrite rules when license becomes valid to register the /metrics endpoint.
|
||||
if ( 'valid' === $status && 'valid' !== $previous_status ) {
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -465,6 +509,9 @@ final class Manager {
|
||||
update_option( self::OPTION_LICENSE_DATA, array() );
|
||||
delete_transient( self::TRANSIENT_LICENSE_CHECK );
|
||||
|
||||
// Flush rewrite rules to remove the /metrics endpoint.
|
||||
flush_rewrite_rules();
|
||||
|
||||
wp_send_json_success( array(
|
||||
'success' => true,
|
||||
'message' => __( 'License deactivated.', 'wp-prometheus' ),
|
||||
|
||||
Reference in New Issue
Block a user