<?php
/**
 * Custom hooks
 *
 * @package Wrock Metro
 */

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

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

add_action( 'wrockmetro_site_info', 'wrockmetro_add_site_info' );
if ( ! function_exists( 'wrockmetro_add_site_info' ) ) {
	/**
	 * Add site info content.
	 */
	function wrockmetro_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/', 'wrock-metro' ) ),
			sprintf(
				/* translators: WordPress */
				esc_html__( 'Proudly powered by %s', 'wrock-metro' ),
				'WordPress'
			),
			sprintf(
				/* translators: 1: Theme name, 2: Theme author */
				esc_html__( 'Design %1$s by %2$s', 'wrock-metro' ),
				$the_theme->get( 'Name' ),
				'<a href="' . esc_url( __( 'https://www.insertcart.com/product/wrockmetro-wordpress-theme/', 'wrock-metro' ) ) . '">InsertCart.com</a>'
			)
		);

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

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

	}
}
