<?php
/**
 * Custom hooks
 *
 * @package Poster
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'poster_site_info' ) ) {
	/**
	 * Add site info hook to WP hook library.
	 */
	function poster_site_info() {
		do_action( 'poster_site_info' );
	}
}

add_action( 'poster_site_info', 'poster_add_site_info' );
if ( ! function_exists( 'poster_add_site_info' ) ) {
	/**
	 * Add site info content.
	 */
	function poster_add_site_info() {
		$the_theme = wp_get_theme();
		$credit = '</a>';

		$site_info = sprintf(
			'<a href="%1$s">%2$s</a><span class="sep"> | </span>%3$s',
			esc_url( __( 'https://wordpress.org/', 'poster' ) ),
			sprintf(
				/* translators: WordPress */
				esc_html__( 'Proudly powered by %s', 'poster' ),
				'WordPress'
			),
			sprintf(
				/* translators: 1: Theme name, 2: Theme author */
				esc_html__( 'Design %1$s by %2$s', 'poster' ),
				$the_theme->get( 'Name' ),
				'<a href="' . esc_url( __( 'https://www.insertcart.com/product/poster-wordpress-theme/', 'poster' ) ) . '">InsertCart.com</a>'
			)
		);

		// Check if customizer site info has value.
		if ( get_theme_mod( 'poster_site_info_override' ) ) {
			$site_info = get_theme_mod( 'poster_site_info_override' ) . $credit;
			$credit = sprintf(
				/* translators: 1: Theme name, 2: Theme author */
				esc_html__( 'Design %1$s by %2$s', 'poster' ),
				$the_theme->get( 'Name' ),
				'<a href="' . esc_url( __( 'https://www.insertcart.com/product/poster-wordpress-theme/', 'poster' ) ) . '">InsertCart.com</a>'
			);
		}

		echo apply_filters( 'poster_site_info_content', $site_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

	}
}
