<?php
/**
 * Dynamic Tag: Post Author Name
 *
 * @package captain-widgets-kit
 * @since   1.1.0
 */

use Elementor\Core\DynamicTags\Tag;
use Elementor\Modules\DynamicTags\Module;
if ( ! defined( 'ABSPATH' ) ) {
	exit; }
/**
 * Class Captwiki_Tag_Post_Author
 * Outputs the current post author display name.
 */
class Captwiki_Tag_Post_Author extends Tag {
	/**
	 * Get tag name.
	 *
	 * @return string
	 */
	public function get_name(): string {
		return 'captwiki-tag-post-author-name'; }
	/**
	 * Get tag title.
	 *
	 * @return string
	 */
	public function get_title(): string {
		return esc_html__( 'Post Author Name', 'captain-widgets-kit' ); }
	/**
	 * Get tag group.
	 *
	 * @return array
	 */
	public function get_group(): array {
		return array( 'captwiki-post' ); }
	/**
	 * Get tag categories.
	 *
	 * @return array
	 */
	public function get_categories(): array {
		return array( Module::TEXT_CATEGORY ); }
	/**
	 * Check whether settings are required.
	 *
	 * @return bool
	 */
	public function is_settings_required() {
		return true; }
	/**
	 * Register tag controls.
	 *
	 * @return void
	 */
	protected function register_controls(): void {}
	/**
	 * Render tag output.
	 *
	 * @return void
	 */
	public function render(): void {
		$post_id = get_the_ID();
		if ( ! $post_id ) {
			return; }
		$author_id = get_post_field( 'post_author', $post_id );
		if ( ! $author_id ) {
			return; }
		$name = get_the_author_meta( 'display_name', $author_id );
		if ( $name ) {
			echo esc_html( $name ); }
	}
}
