robotstxt-smtp/robotstxt-smtp.php
2025-11-26 08:24:18 +00:00

120 lines
3.4 KiB
PHP

<?php
/**
* Plugin Name: SMTP (by ROBOTSTXT)
* Plugin URI: https://www.robotstxt.es/
* Description: Configure WordPress to send emails through SMTP with detailed controls.
* Version: 1.2.0
* Requires at least: 6.0
* Requires PHP: 8.2
* Author: ROBOTSTXT
* Author URI: https://www.robotstxt.es/
* Text Domain: robotstxt-smtp
* Domain Path: /languages
* License: GPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Gitea Plugin URI: ROBOTSTXT/robotstxt-smtp
* Gitea Plugin URI: https://git.robotstxt.es/ROBOTSTXT/robotstxt-smtp
* Plugin ID: did:plc:yodoiqooeu3l3lwuolyha3zs
*
* @package Robotstxt_SMTP
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! defined( 'ROBOTSTXT_SMTP_VERSION' ) ) {
define( 'ROBOTSTXT_SMTP_VERSION', '1.2.0' );
}
if ( ! defined( 'ROBOTSTXT_SMTP_FILE' ) ) {
define( 'ROBOTSTXT_SMTP_FILE', __FILE__ );
}
if ( ! defined( 'ROBOTSTXT_SMTP_URL' ) ) {
define( 'ROBOTSTXT_SMTP_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'ROBOTSTXT_SMTP_PATH' ) ) {
define( 'ROBOTSTXT_SMTP_PATH', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'ROBOTSTXT_SMTP_SLUG' ) ) {
define( 'ROBOTSTXT_SMTP_SLUG', 'robotstxt-smtp' );
}
if ( ! defined( 'ROBOTSTXT_SMTP_BASENAME' ) ) {
define( 'ROBOTSTXT_SMTP_BASENAME', plugin_basename( ROBOTSTXT_SMTP_FILE ) );
}
if ( ! class_exists( 'PHPMailer\PHPMailer\PHPMailer' ) ) {
require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
}
if ( ! class_exists( 'PHPMailer\PHPMailer\Exception' ) ) {
require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
}
if ( ! class_exists( 'PHPMailer\PHPMailer\SMTP' ) ) {
require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
}
require_once ROBOTSTXT_SMTP_PATH . 'includes/class-smtp-diagnostics-client.php';
require_once ROBOTSTXT_SMTP_PATH . 'includes/class-settings-page.php';
require_once ROBOTSTXT_SMTP_PATH . 'includes/class-plugin.php';
if ( ! function_exists( 'robotstxt_smtp_dependencies_satisfied' ) ) {
/**
* Determines whether the plugin dependencies are available.
*
* @since 1.1.1
*
* @return bool
*/
function robotstxt_smtp_dependencies_satisfied(): bool {
return class_exists( '\\PHPMailer\\PHPMailer\\PHPMailer' );
}
}
if ( ! function_exists( 'robotstxt_smtp_register_dependency_notice' ) ) {
/**
* Registers an admin notice when dependencies are missing.
*
* @since 1.1.1
*
* @return void
*/
function robotstxt_smtp_register_dependency_notice(): void {
if ( ! is_admin() ) {
return;
}
$callback = static function (): void {
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
if ( $screen && 'plugins' !== $screen->id && 'plugins-network' !== $screen->id ) {
return;
}
$message = sprintf(
/* translators: %s: plugin name. */
esc_html__( 'The %s plugin requires the PHPMailer library to be available.', 'robotstxt-smtp' ),
esc_html__( 'ROBOTSTXT SMTP', 'robotstxt-smtp' )
);
?>
<div class="notice notice-error">
<p><?php echo esc_html( $message ); ?></p>
</div>
<?php
};
add_action( 'admin_notices', $callback );
add_action( 'network_admin_notices', $callback );
}
}
if ( robotstxt_smtp_dependencies_satisfied() ) {
\Robotstxt_SMTP\Plugin::get_instance()->run();
} else {
robotstxt_smtp_register_dependency_notice();
}