Your IP : 216.73.216.1


Current Path : /home/fotouserdopd8j/agenciacrabli.com/wp-contentn/themes/pally/inc/classes/
Upload File :
Current File : /home/fotouserdopd8j/agenciacrabli.com/wp-contentn/themes/pally/inc/classes/Biography.php

<?php
/**
 * pally Author biography section
 *
 * @package pally
 * @since 1.0.0
 */

namespace Pally;

use WP_Customize_Manager;
use Pally\Customizer;

/**
 * Author Biography
 *
 * @since 1.0.0
 */
class Biography {

	/**
	 * Constructor.
	 *
	 * @since 1.0.0
	 * @access public
	 */
	public function __construct() {
		add_action( 'customize_register', [ $this, 'action_register_customizer_control' ] );
	}

	/**
	 * Adds a Customizer setting and control
	 *
	 * @param WP_Customize_Manager $wp_customize Customizer manager instance.
	 * @since 1.0.0
	 * @access public
	 */
	public function action_register_customizer_control( WP_Customize_Manager $wp_customize ) {

		$wp_customize->add_section(
			'about_options',
			array(
				'title' => __( 'Author Biography options', 'pally' ),
				'panel' => 'theme_options',
			)
		);

		$wp_customize->add_setting(
			'author_information',
			array(
				'default'           => false,
				'sanitize_callback' => 'Pally\Customizer::sanitize_checkbox',
			)
		);

		$wp_customize->add_control(
			'author_information',
			array(
				'type'        => 'checkbox',
				'label'       => __( 'Enable the author biography on posts', 'pally' ),
				'description' => __( 'Show the authors biography and links below posts. The content is generated from the users settings.', 'pally' ),
				'section'     => 'about_options',
			)
		);

		$wp_customize->selective_refresh->add_partial(
			'author_information',
			array(
				'selector'        => '.type-post .author-info',
				'render_callback' => 'author_information',
			)
		);

		$wp_customize->add_setting(
			'author_website',
			array(
				'default'           => true,
				'sanitize_callback' => 'Pally\Customizer::sanitize_checkbox',
			)
		);

		$wp_customize->add_control(
			'author_website',
			array(
				'type'        => 'checkbox',
				'label'       => __( 'Display the authors website link', 'pally' ),
				'description' => __( '(Useful for guest authors)', 'pally' ),
				'section'     => 'about_options',
			)
		);

		$wp_customize->add_setting(
			'gravatar_style',
			array(
				'default'           => 'circle',
				'sanitize_callback' => 'Pally\Customizer::sanitize_select',
			)
		);

		$wp_customize->add_control(
			'gravatar_style',
			array(
				'label'       => __( 'Author Gravatar', 'pally' ),
				'description' => __( 'Select a style for the gravatar', 'pally' ),
				'section'     => 'about_options',
				'type'        => 'radio',
				'choices'     =>
				[
					'circle' => __( 'Circle (Default)', 'pally' ),
					'square' => __( 'Square', 'pally' ),
					'hide'   => __( 'Hide Gravatar', 'pally' ),
				],
			)
		);
	}

	/**
	 * Output the author biography
	 *
	 * @since 1.0.0
	 * @access public
	 */
	public static function author_biography() {
        $gravatar_style = "";
        if( get_theme_mod( 'gravatar_style', 'circle' ) !== 'hide'){
            $gravatar_style = get_theme_mod( 'gravatar_style', 'circle' );
        }

		echo '<div class="author-info '.$gravatar_style.'">';
		echo '<h2 class="entry-title">' , esc_html__( 'About the author', 'pally' ) ,'</h2>';
		if ( !empty( $gravatar_style ) ) {
			echo get_avatar( get_the_author_meta( 'ID' ), '120' );
		}

		echo '<span class="post-author">' , the_author_posts_link() , '</span>';

		echo '<div class="author-description">';
		if ( get_theme_mod( 'author_information', true ) === true ) {
			echo wp_kses_post( the_author_meta( 'user_description' ) );
		}

		if ( get_theme_mod( 'author_website', true ) === true && get_the_author_meta( 'user_url' ) ) {
			echo '<p><a href="' , esc_url( get_the_author_meta( 'user_url' ) ) , '">' , esc_html__( 'Visit the authors website', 'pally' ) , '</a></p>';
		}
		echo '</div></div>';
	}
}