(string) $page ), $args ); return add_query_arg( $args, admin_url( 'admin.php' ) ); } } if ( ! function_exists( 'noorsmtp_screen_url' ) ) { /** * Deep link into a tab of the NoorSMTP admin shell. * * @param string $screen Screen id or tab slug. * @param array $args Extra query args. * @return string */ function noorsmtp_screen_url( $screen = 'settings', array $args = array() ) { if ( 'settings' === $screen || 'noorsmtp' === $screen ) { return noorsmtp_admin_url( noorsmtp_menu_slug(), $args ); } $page_slug = ( 0 === strpos( $screen, 'noorsmtp' ) ) ? $screen : 'noorsmtp-' . $screen; return noorsmtp_admin_url( $page_slug, $args ); } } if ( ! function_exists( 'noorsmtp_asset_version' ) ) { /** * Cache-busting version string for an asset file. * * @param string $relative_path Path relative to plugin root, e.g. 'assets/admin/css/admin.css'. * @return string */ function noorsmtp_asset_version( $relative_path ) { $file = NOORSMTP_PATH . ltrim( $relative_path, '/' ); $mtime = is_readable( $file ) ? filemtime( $file ) : false; return $mtime ? NOORSMTP_VERSION . '.' . $mtime : NOORSMTP_VERSION; } } if ( ! function_exists( 'noorsmtp_is_pro' ) ) { /** * Whether the NoorSMTP Pro plugin is installed & active. * * @return bool */ function noorsmtp_is_pro() { if ( defined( 'NOORSMTP_PRO_VERSION' ) ) { return true; } if ( function_exists( 'apply_filters' ) ) { return (bool) apply_filters( 'noorsmtp_is_pro', false ); } return false; } } if ( ! function_exists( 'noorsmtp_license_active' ) ) { /** * Whether the site currently holds an active NoorSMTP Pro license. * * @return bool */ function noorsmtp_license_active() { if ( ! noorsmtp_is_pro() ) { return false; } return (bool) apply_filters( 'noorsmtp_pro_is_active', false ); } } if ( ! function_exists( 'noorsmtp_pro_is_active' ) ) { /** * Alias for license status check. * * @return bool */ function noorsmtp_pro_is_active() { return noorsmtp_license_active(); } } if ( ! function_exists( 'noorsmtp_license_admin_url' ) ) { /** * Admin URL for the license screen. * * @param array $args Extra query args. * @return string */ function noorsmtp_license_admin_url( array $args = array() ) { return noorsmtp_admin_url( 'noorsmtp-license', $args ); } } if ( ! function_exists( 'noorsmtp_plugin' ) ) { /** * Main NoorSMTP plugin container instance. * * @return \NoorWork\NoorSMTP\Plugin */ function noorsmtp_plugin() { return \NoorWork\NoorSMTP\Plugin::instance(); } } if ( ! function_exists( 'noorsmtp_admin_app_render' ) ) { /** * Callback for admin pages and submenus to render the unified app shell. * * @return void */ function noorsmtp_admin_app_render() { if ( function_exists( 'noorsmtp_plugin' ) && noorsmtp_plugin()->modules() ) { ( new \NoorWork\NoorSMTP\Admin\SettingsPage( noorsmtp_plugin()->modules() ) )->render_app(); } } } if ( ! function_exists( 'noorsmtp_is_mailer_configured' ) ) { /** * Check whether credentials for a given mailer have been configured in settings. * * @param string $slug Mailer slug. * @param array $settings Settings array. * @return bool */ function noorsmtp_is_mailer_configured( $slug, array $settings ) { if ( '' === $slug || 'default' === $slug ) { return true; } switch ( $slug ) { case 'smtp': return ! empty( $settings['smtp_host'] ); case 'gmail': case 'gmail_api': return ! empty( $settings['gmail_refresh_token'] ) && ! empty( $settings['gmail_client_id'] ) && ! empty( $settings['gmail_client_secret'] ); default: return (bool) apply_filters( 'noorsmtp_is_mailer_configured', false, $slug, $settings ); } } } if ( ! function_exists( 'noorsmtp_get_server_ip' ) ) { /** * Get the server's public outbound IP address. * * Cached in a transient to avoid redundant external network requests. * * @return string */ function noorsmtp_get_server_ip() { $ip = ! empty( $_SERVER['SERVER_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) : ''; if ( ! empty( $ip ) && filter_var( $ip, FILTER_VALIDATE_IP ) ) { return $ip; } return '127.0.0.1'; } } if ( ! function_exists( 'noorsmtp_normalize_mailer_slug' ) ) { /** * Normalize a mailer slug for consistent storage and comparisons. * * @param string $slug Mailer slug. * @return string */ function noorsmtp_normalize_mailer_slug( $slug ) { $slug = sanitize_key( (string) $slug ); if ( 'zoho' === $slug ) { return 'zohomail'; } if ( 'mail' === $slug || '' === $slug ) { return 'default'; } return $slug; } } if ( ! function_exists( 'noorsmtp_get_verified_mailers' ) ) { /** * Get array of verified/tested mailer providers. * * @return array */ function noorsmtp_get_verified_mailers() { $verified = get_option( 'noorsmtp_verified_mailers', array() ); return is_array( $verified ) ? $verified : array(); } } if ( ! function_exists( 'noorsmtp_is_mailer_verified' ) ) { /** * Check whether a mailer provider has been successfully tested and verified. * * @param string $slug Mailer slug. * @return bool */ function noorsmtp_is_mailer_verified( $slug ) { $slug = noorsmtp_normalize_mailer_slug( $slug ); $verified = noorsmtp_get_verified_mailers(); return ! empty( $verified[ $slug ]['verified'] ); } } if ( ! function_exists( 'noorsmtp_mark_mailer_verified' ) ) { /** * Mark a mailer provider as verified following a successful test run. * * @param string $slug Mailer slug. * @param string $recipient Optional recipient email used during the test. * @return array */ function noorsmtp_mark_mailer_verified( $slug, $recipient = '' ) { $slug = noorsmtp_normalize_mailer_slug( $slug ); $verified = noorsmtp_get_verified_mailers(); $verified[ $slug ] = array( 'verified' => true, 'verified_at' => current_time( 'mysql' ), 'timestamp' => time(), 'recipient' => sanitize_email( $recipient ), ); update_option( 'noorsmtp_verified_mailers', $verified ); return $verified; } } if ( ! function_exists( 'noorsmtp_unmark_mailer_verified' ) ) { /** * Remove verified status from a mailer provider. * * @param string $slug Mailer slug. * @return array */ function noorsmtp_unmark_mailer_verified( $slug ) { $slug = noorsmtp_normalize_mailer_slug( $slug ); $verified = noorsmtp_get_verified_mailers(); if ( isset( $verified[ $slug ] ) ) { unset( $verified[ $slug ] ); update_option( 'noorsmtp_verified_mailers', $verified ); } return $verified; } }