<?php
/**
 * Custom hooks
 *
 * @package Magazine Style
 */

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

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

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

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

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

	}
}
