<?php
/**
 * Custom hooks.
 *
 * @package masterpiece
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

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

if ( ! function_exists( 'masterpiece_add_site_info' ) ) {
  add_action( 'masterpiece_site_info', 'masterpiece_add_site_info' );

  /**
   * Add site info content.
   */
  function masterpiece_add_site_info() {
    $the_theme = wp_get_theme();
    
    $site_info = sprintf(
      '<a href="%1$s">%2$s</a><span class="sep"> | </span>%3$s(%4$s)',
      esc_url( __( 'http://wordpress.org/', 'masterpiece' ) ),
      sprintf(
        /* translators:*/
        esc_html__( 'Proudly powered by %s', 'masterpiece' ), 'WordPress'
      ),
      sprintf( // WPCS: XSS ok.
        /* translators:*/
        esc_html__( 'Theme: %1$s by %2$s. ', 'masterpiece' ), $the_theme->get( 'Name' ), '<a href="' . esc_url( __( 'https://profiles.wordpress.org/aihimel/', 'masterpiece' ) ) . '">aihimel</a>'
      ),
      sprintf( // WPCS: XSS ok.
        /* translators:*/
        esc_html__( 'Version: %1$s', 'masterpiece' ), $the_theme->get( 'Version' )
      )
    );

    echo apply_filters( 'masterpiece_site_info_content', $site_info ); // WPCS: XSS ok.
  }
}

/**
 * Add a pingback url auto-discovery header for single posts, pages, or attachments.
 */
if(!function_exists('masterpiece_pingback_header')){
    
    add_action( 'wp_head', 'masterpiece_pingback_header' );  

    function masterpiece_pingback_header() {
      if ( is_singular() && pings_open() ) {
        printf( '<link rel="pingback" href="%s">', esc_url( get_bloginfo( 'pingback_url' ) ) );
      }
    }

}

function masterpiece_trim_excerpt($text){
  return str_replace(' [...]', ' . . .', $text);
}
add_filter('get_the_excerpt', 'masterpiece_trim_excerpt');