This commit is contained in:
Javier Casares 2026-08-17 19:16:01 +00:00
commit 1f308e8917

View file

@ -90,6 +90,16 @@ class Plugin {
return self::$instance;
}
/**
* URL of the Manager (by ROBOTSTXT) plugin page.
*/
public const MANAGER_PLUGIN_URL = 'https://www.robotstxt.software/plugins/robotstxt-manager/';
/**
* User meta key used to store the manager notice dismissal.
*/
public const MANAGER_NOTICE_DISMISSED_KEY = 'robotstxt_smtp_manager_notice_dismissed';
/**
* Determines whether the Amazon SES integration plugin is active.
*
@ -106,11 +116,36 @@ class Plugin {
return (bool) \apply_filters( 'robotstxt_smtp_amazon_ses_active', false );
}
/**
* Sets up the plugin.
*
* @return void
*/
/**
* Determines whether the Manager (by ROBOTSTXT) plugin is active.
*
* Updates for this plugin are delivered through the Manager plugin, so its
* presence is required to receive new versions.
*
* @since 2.2.4
*
* @return bool True when the Manager plugin is installed and active.
*/
public static function is_manager_plugin_active(): bool {
$active = array_merge(
(array) get_option( 'active_plugins', array() ),
array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) )
);
foreach ( $active as $basename ) {
if ( is_string( $basename ) && str_starts_with( $basename, 'robotstxt-manager/' ) ) {
return true;
}
}
return false;
}
/**
* Sets up the plugin.
*
* @return void
*/
public function run(): void {
add_action( 'phpmailer_init', array( $this, 'configure_phpmailer' ) );
add_filter( 'pre_wp_mail', array( $this, 'pre_wp_mail_rate_limit_check' ), 1 );
@ -134,8 +169,11 @@ class Plugin {
if ( is_admin() ) {
add_action( 'admin_init', array( $this, 'migrate_plaintext_credentials' ) );
add_action( 'admin_init', array( $this, 'handle_encryption_notice_dismissal' ) );
add_action( 'admin_init', array( $this, 'handle_manager_notice_dismissal' ) );
add_action( 'admin_notices', array( $this, 'display_encryption_unavailable_notice' ) );
add_action( 'network_admin_notices', array( $this, 'display_encryption_unavailable_notice' ) );
add_action( 'admin_notices', array( $this, 'display_manager_notice' ) );
add_action( 'network_admin_notices', array( $this, 'display_manager_notice' ) );
$this->register_admin();
}
}
@ -555,6 +593,95 @@ class Plugin {
exit;
}
/**
* Displays an admin notice on the plugins list pages when the Manager plugin is missing.
*
* Updates for this plugin are delivered through the Manager (by ROBOTSTXT)
* plugin. When it is not active, a dismissible notice is shown on the site
* and network plugins list pages.
*
* @since 2.2.4
*
* @return void
*/
public function display_manager_notice(): void {
$screen = get_current_screen();
if ( null === $screen || ! in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) ) {
return;
}
if ( self::is_manager_plugin_active() ) {
return;
}
if ( get_user_meta( get_current_user_id(), self::MANAGER_NOTICE_DISMISSED_KEY, true ) ) {
return;
}
$dismiss_url = wp_nonce_url(
add_query_arg( 'robotstxt_smtp_dismiss_manager_notice', '1' ),
'robotstxt_smtp_dismiss_manager_notice'
);
?>
<div class="notice notice-warning">
<p>
<strong><?php esc_html_e( 'SMTP (by ROBOTSTXT)', 'robotstxt-smtp' ); ?></strong>
</p>
<p>
<?php
printf(
/* translators: %s: Manager plugin page link. */
esc_html__( 'To receive updates for this plugin, the %s plugin must be installed and active.', 'robotstxt-smtp' ),
'<a href="' . esc_url( self::MANAGER_PLUGIN_URL ) . '">' . esc_html__( 'Manager (by ROBOTSTXT)', 'robotstxt-smtp' ) . '</a>'
);
?>
</p>
<p>
<a href="<?php echo esc_url( $dismiss_url ); ?>" class="button button-secondary">
<?php esc_html_e( 'Dismiss', 'robotstxt-smtp' ); ?>
</a>
</p>
</div>
<?php
}
/**
* Handles dismissal of the missing Manager plugin notice.
*
* Stores a per-user preference so the notice is not shown again on the
* plugins list pages until the preference is cleared.
*
* @since 2.2.4
*
* @return void
*/
public function handle_manager_notice_dismissal(): void {
$dismiss_action = filter_input( INPUT_GET, 'robotstxt_smtp_dismiss_manager_notice', FILTER_UNSAFE_RAW );
if ( '1' !== $dismiss_action ) {
return;
}
// 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_smtp_dismiss_manager_notice' ) ) {
return;
}
// Check capability.
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
update_user_meta( get_current_user_id(), self::MANAGER_NOTICE_DISMISSED_KEY, '1' );
// Redirect to clean URL.
$redirect_url = remove_query_arg( array( 'robotstxt_smtp_dismiss_manager_notice', '_wpnonce' ) );
wp_safe_redirect( $redirect_url );
exit;
}
/**
* Configures PHPMailer to use the stored SMTP settings.
*