This commit is contained in:
Javier Casares 2026-08-17 16:03:39 +00:00
commit 0e617fa428
12 changed files with 286 additions and 259 deletions

View file

@ -64,13 +64,78 @@ class Robotstxt_Manager_Admin {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'robotstxt-manager' ) );
}
$client = Robotstxt_Manager_Core_Client::from_options();
$catalog = $client->get_catalog();
$local = $this->resolve_local_state( $catalog );
$client = Robotstxt_Manager_Core_Client::from_options();
$catalog = $client->get_catalog();
$local = $this->resolve_local_state( $catalog );
$subscriptions = $client->get_subscriptions();
// Admin notices for subscriptions needing attention.
$manager_notices = $this->build_subscription_notices( $catalog, $subscriptions );
$manager_subscriptions = $subscriptions;
require ROBOTSTXT_MANAGER_DIR . 'admin/views/page-catalog.php';
}
/**
* Builds admin notices for subscriptions that need attention.
*
* - payment_failed: persistent warning per plugin.
* - expiring within 14 days: per-plugin warning.
* - expired while the plugin is still installed+active: per-plugin warning.
*
* @param list<array<string, mixed>> $catalog Catalog entries.
* @param array<string, array<string, mixed>> $subscriptions Rows keyed by slug.
*
* @return list<array{type:string, message:string}>
*/
private function build_subscription_notices( array $catalog, array $subscriptions ): array {
$notices = array();
$local = $this->resolve_local_state( $catalog );
foreach ( $subscriptions as $slug => $sub ) {
$raw_status = $sub['status'] ?? '';
$raw_expires_at = $sub['expires_at'] ?? '';
$status = is_string( $raw_status ) ? $raw_status : '';
$expires_at = is_string( $raw_expires_at ) ? $raw_expires_at : '';
if ( 'payment_failed' === $status ) {
$notices[] = array(
'type' => 'warning',
/* translators: %s: plugin slug. */
'message' => sprintf( __( 'The payment for %s failed. Update your payment method from your ROBOTSTXT account page to keep access.', 'robotstxt-manager' ), $slug ),
);
continue;
}
if ( 'expired' === $status ) {
$state = $local[ $slug ] ?? array();
if ( ! empty( $state['active'] ) ) {
$notices[] = array(
'type' => 'warning',
/* translators: %s: plugin slug. */
'message' => sprintf( __( 'The subscription for %s has expired, but the plugin is still active on this site. Renew from your ROBOTSTXT account page to keep receiving updates.', 'robotstxt-manager' ), $slug ),
);
}
continue;
}
if ( 'active' === $status && '' !== $expires_at ) {
$days = (int) floor( ( (int) strtotime( $expires_at ) - time() ) / DAY_IN_SECONDS );
if ( $days >= 0 && $days <= 14 ) {
$notices[] = array(
'type' => 'warning',
/* translators: 1: plugin slug, 2: days remaining. */
'message' => sprintf( _n( 'The subscription for %1$s expires in %2$d day.', 'The subscription for %1$s expires in %2$d days.', $days, 'robotstxt-manager' ), $slug, $days ),
);
}
}
}
return $notices;
}
/**
* Handles the "Refresh catalog" admin-post action.
*
@ -100,6 +165,7 @@ class Robotstxt_Manager_Admin {
$client = Robotstxt_Manager_Core_Client::from_options();
$client->clear_catalog_cache();
$client->clear_subscriptions_cache();
delete_site_transient( 'update_plugins' );
$redirect = add_query_arg(

View file

@ -348,6 +348,7 @@ class Robotstxt_Manager_Settings {
}
delete_transient( 'robotstxt_manager_catalog' );
delete_transient( 'robotstxt_manager_subscriptions' );
return Robotstxt_Manager_Encryption::encrypt( $plain );
}
@ -406,6 +407,7 @@ class Robotstxt_Manager_Settings {
delete_option( 'robotstxt_manager_api_key' );
delete_transient( 'robotstxt_manager_catalog' );
delete_transient( 'robotstxt_manager_subscriptions' );
wp_send_json_success(
array(

View file

@ -7,6 +7,10 @@
* (website link + description), an intro paragraph, and Support /
* Payments sections below the table.
*
* Also available:
* $manager_subscriptions array<string, array{status:string, expires_at:string}>
* Account subscriptions keyed by slug (may be empty).
*
* @package Robotstxt_Manager
*/
@ -19,6 +23,8 @@ if ( ! defined( 'ABSPATH' ) ) {
*
* @var list<array<string,mixed>> $catalog
* @var array<string, array{installed:bool, active:bool, version:string}> $local
* @var array<string, array<string,mixed>> $manager_subscriptions
* @var list<array{type:string, message:string}> $manager_notices
*/
$client_configured = Robotstxt_Manager_Core_Client::from_options()->is_configured();
@ -65,6 +71,12 @@ $compat_warnings = 0;
<div class="notice notice-success is-dismissible"><p><?php esc_html_e( 'Catalog refreshed.', 'robotstxt-manager' ); ?></p></div>
<?php endif; ?>
<?php foreach ( ( $manager_notices ?? array() ) as $manager_notice ) : ?>
<div class="notice notice-<?php echo esc_attr( is_string( $manager_notice['type'] ?? '' ) ? $manager_notice['type'] : 'warning' ); ?>">
<p><?php echo esc_html( is_string( $manager_notice['message'] ?? '' ) ? $manager_notice['message'] : '' ); ?></p>
</div>
<?php endforeach; ?>
<?php if ( '' !== $notice_message && in_array( $notice_result, array( 'success', 'error' ), true ) ) : ?>
<div class="notice notice-<?php echo esc_attr( $notice_result ); ?> is-dismissible"><p><?php echo esc_html( $notice_message ); ?></p></div>
<?php endif; ?>
@ -209,6 +221,46 @@ $compat_warnings = 0;
number_format_i18n( $cost, 0 )
)
);
// Subscription pill for premium plugins.
$sub_row = $manager_subscriptions[ $slug ] ?? null;
$sub_text = '';
if ( is_array( $sub_row ) ) {
$raw_sub_status = $sub_row['status'] ?? '';
$raw_sub_expiry = $sub_row['expires_at'] ?? '';
$sub_status = is_string( $raw_sub_status ) ? $raw_sub_status : '';
$sub_expiry = is_string( $raw_sub_expiry ) ? $raw_sub_expiry : '';
if ( 'active' === $sub_status && '' !== $sub_expiry ) {
$days_left = (int) floor( ( (int) strtotime( $sub_expiry ) - time() ) / DAY_IN_SECONDS );
if ( $days_left >= 0 && $days_left <= 14 ) {
$sub_text = sprintf(
/* translators: %d: days remaining. */
__( 'Subscribed — %d days left', 'robotstxt-manager' ),
$days_left
);
} else {
$sub_text = __( 'Subscribed', 'robotstxt-manager' );
}
} elseif ( 'payment_failed' === $sub_status ) {
$sub_text = __( 'Payment failed', 'robotstxt-manager' );
} elseif ( 'cancelled' === $sub_status ) {
$sub_text = __( 'Cancelled', 'robotstxt-manager' );
} elseif ( 'expired' === $sub_status ) {
$sub_text = __( 'Expired', 'robotstxt-manager' );
}
}
if ( '' !== $sub_text ) {
$raw_pill_status = is_array( $sub_row ) ? ( $sub_row['status'] ?? '' ) : '';
$pill_status = is_string( $raw_pill_status ) ? $raw_pill_status : '';
echo '<br /><span class="robotstxt-manager-subscription robotstxt-manager-subscription--'
. esc_attr( $pill_status )
. '">' . esc_html( $sub_text ) . '</span>';
}
} else {
echo esc_html__( 'Free', 'robotstxt-manager' );
}