文件操作 - PreviewTrigger.php
返回文件管理
返回主菜单
删除本文件
文件: /home/www/public/wp-content/plugins/tutor/components/PreviewTrigger.php
编辑文件内容
<?php /** * PreviewTrigger Component Class. * * Responsible for rendering a preview trigger with a popover card. * * @package Tutor\Components * @author Themeum * @link https://themeum.com * @since 1.0.0 */ namespace Tutor\Components; defined( 'ABSPATH' ) || exit; /** * Class PreviewTrigger * * Example Usage: * ```php * // Render a preview trigger for a course * PreviewTrigger::make() * ->id( $course_id ) * ->render(); * * // Render a preview trigger for a lesson * PreviewTrigger::make() * ->id( $lesson_id ) * ->render(); * * // Retrieve HTML without echoing * $html = PreviewTrigger::make()->id( $course_id )->get(); * ``` * * @since 1.0.0 */ class PreviewTrigger extends BaseComponent { /** * Content ID (Course or Lesson) * * @var int */ protected $id; /** * Set content ID * * @param int $id Content ID. * * @return self */ public function id( int $id ): self { $this->id = $id; return $this; } /** * Get component content * * @return string */ public function get(): string { $id = $this->id; if ( ! $id ) { return ''; } $post = get_post( $id ); if ( ! $post ) { return ''; } $post_type = $post->post_type; $title = get_the_title( $id ); $thumbnail = get_tutor_course_thumbnail_src( 'medium', $id ); // Fallback for thumbnail if empty. if ( empty( $thumbnail ) ) { $thumbnail = tutor()->url . 'assets/images/placeholder.svg'; } $instructor_name = ''; $instructor_url = ''; // Determine instructor based on post type logic matching dashboard-notes. if ( tutor()->course_post_type === $post_type ) { $author_id = $post->post_author; $instructor_name = tutor_utils()->display_name( $author_id ); $instructor_url = tutor_utils()->profile_url( $author_id, true ); } elseif ( tutor()->lesson_post_type === $post_type ) { $course_id = tutor_utils()->get_course_id_by_lesson( $id ); if ( $course_id ) { $course_post = get_post( $course_id ); $author_id = $course_post->post_author; $instructor_name = tutor_utils()->display_name( $author_id ); $instructor_url = tutor_utils()->profile_url( $author_id, true ); } } $preview_data = array( 'title' => $title, 'url' => get_permalink( $id ), 'thumbnail' => $thumbnail, 'instructor' => $instructor_name, 'instructor_url' => $instructor_url, ); ob_start(); ?> <div x-data="tutorPreviewTrigger({ data: <?php echo esc_attr( wp_json_encode( $preview_data ) ); ?>, offset: 0 })" x-ref="trigger" class="tutor-preview-trigger" > <span tabindex="0" role="button" aria-haspopup="true" :aria-expanded="open ? 'true' : 'false'" class="tutor-preview-trigger-text" ><?php echo esc_html( $title ); ?></span> <div x-ref="content" x-show="open" x-cloak x-trap="open" @keydown.escape="hide()" @click.outside="handleClickOutside()" class="tutor-popover tutor-preview-card" ></div> </div> <?php return ob_get_clean(); } }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件