文件操作 - Alert.php
返回文件管理
返回主菜单
删除本文件
文件: /home/www/public/wp-content/plugins/tutor/components/Alert.php
编辑文件内容
<?php /** * Alert Component Class. * * Provides a fluent builder for rendering alerts with * different variants and actions. * * @package Tutor\Components * @author Themeum * @link https://themeum.com * @since 4.0.0 */ namespace Tutor\Components; defined( 'ABSPATH' ) || exit; /** * Alert Component Class. * * Example usage: * ``` * // Default (neutral) alert * Alert::make() * ->text( 'Your changes have been saved.' ) * ->render(); * * // Success alert with icon * Alert::make() * ->text( 'Course published successfully.' ) * ->variant( Alert::SUCCESS ) * ->icon( Icon::PRIME_CHECK_CIRCLE ) * ->render(); * * // Info alert with action button * Alert::make() * ->text( 'You have an incomplete quiz. Resume where you left off.' ) * ->variant( Alert::INFO ) * ->icon( Icon::INFO ) * ->action( '<button class="tutor-btn tutor-btn-primary tutor-btn-small">Resume</button>' ) * ->render(); * * // Warning alert * Alert::make() * ->text( 'Your subscription expires in 3 days.' ) * ->variant( Alert::WARNING ) * ->icon( Icon::WARNING ) * ->render(); * * // Error alert with custom icon size * Alert::make() * ->text( 'Payment failed. Please try again.' ) * ->variant( Alert::ERROR ) * ->icon( Icon::CLOSE_CIRCLE, 24, 24 ) * ->render(); * * // Alert with extra HTML attributes * Alert::make() * ->text( 'Draft saved.' ) * ->variant( Alert::SUCCESS ) * ->attr( 'id', 'draft-alert' ) * ->attr( 'x-show', 'showAlert' ) * ->render(); * ``` * * @since 4.0.0 */ class Alert extends BaseComponent { /** * Variant constants. * * @since 4.0.0 */ public const DEFAULT = 'default'; public const INFO = 'info'; public const SUCCESS = 'success'; public const WARNING = 'warning'; public const ERROR = 'error'; /** * Alert text content. * * @since 4.0.0 * * @var string */ protected $text = ''; /** * Alert variant style. * * @since 4.0.0 * * @var string */ protected $variant = self::DEFAULT; /** * The SVG icon markup or name. * * @since 4.0.0 * * @var string */ protected $icon = ''; /** * Icon width. * * @var int */ protected $icon_width = 20; /** * Icon height. * * @var int */ protected $icon_height = 20; /** * Alert action HTML. * * @since 4.0.0 * * @var string */ protected $action = ''; /** * Set alert text content. * * @since 4.0.0 * * @param string $text Alert text content. * * @return $this */ public function text( string $text ): self { $this->text = $text; return $this; } /** * Set alert variant style. * * @since 4.0.0 * * @param string $variant Alert variant (default|info|success|warning|error). * * @return $this */ public function variant( string $variant ): self { $this->variant = $variant; return $this; } /** * Set the SVG icon for the alert. * * @since 4.0.0 * * @param string $icon SVG icon name or markup. * @param int $width Optional. Icon width. * @param int $height Optional. Icon height. * * @return $this */ public function icon( string $icon, int $width = 20, int $height = 20 ): self { $this->icon = $icon; $this->icon_width = $width; $this->icon_height = $height; return $this; } /** * Set alert action HTML. * * @since 4.0.0 * * @param string $action Alert action HTML. * * @return $this */ public function action( string $action ): self { $this->action = $action; return $this; } /** * Get the final alert HTML. * * @since 4.0.0 * * @return string HTML output. */ public function get(): string { $classes = sprintf( 'tutor-alert tutor-alert-%s', esc_attr( $this->variant ) ); // Merge with any custom class attribute. $this->attributes['class'] = trim( "{$classes} " . ( $this->attributes['class'] ?? '' ) ); $attributes = $this->get_attributes_string(); // Build icon HTML if exists. $icon_html = ''; if ( ! empty( $this->icon ) ) { if ( false !== strpos( $this->icon, '<svg' ) ) { $icon_html = $this->icon; } else { ob_start(); SvgIcon::make()->name( $this->icon )->width( $this->icon_width )->height( $this->icon_height )->render(); $icon_html = ob_get_clean(); } } // Build content wrapper. $content_html = sprintf( '<div class="tutor-alert-content"> %s <div class="tutor-alert-text">%s</div> </div>', ! empty( $icon_html ) ? '<div class="tutor-alert-icon">' . $icon_html . '</div>' : '', $this->text // Allow HTML in text if needed, or we could esc_html here. Usually components like this might need small HTML in text. ); // Build action wrapper. $action_html = ! empty( $this->action ) ? sprintf( '<div class="tutor-alert-action">%s</div>', $this->action ) : ''; $this->component_string = sprintf( '<div %s>%s%s</div>', $attributes, $content_html, $action_html ); return $this->component_string; } }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件