<?php

function charity_funds_template_setup() {

if ( ! defined( 'PRIME_CHARITY_TRUST_FOOTER_URL' ) ) {
  define( 'PRIME_CHARITY_TRUST_FOOTER_URL', esc_url( 'https://www.themeignite.com/products/free-charity-wordpress-theme', 'charity-funds') );
}
if ( ! defined( 'PRIME_CHARITY_TRUST_URL' ) ) {
    define( 'PRIME_CHARITY_TRUST_URL', esc_url( 'https://www.themeignite.com/products/charitable-trust-wordpress-theme', 'charity-funds') );
}
if ( ! defined( 'PRIME_CHARITY_TRUST_TEXT' ) ) {
    define( 'PRIME_CHARITY_TRUST_TEXT', __( 'Charity Funds PRO','charity-funds' ));
}
}
add_action('after_setup_theme', 'charity_funds_template_setup');

add_action( 'after_setup_theme', 'charity_funds_after_setup_theme' );
function charity_funds_after_setup_theme() {
    add_theme_support( 'title-tag' );
    add_theme_support( 'automatic-feed-links' );
    add_theme_support( "responsive-embeds" );
    add_theme_support( 'align-wide' );
    add_theme_support( 'post-thumbnails' );
    add_image_size( 'charity-funds-featured-image', 2000, 1200, true );
    add_image_size( 'charity-funds-thumbnail-avatar', 100, 100, true );

    // Set the default content width.
    $GLOBALS['content_width'] = 525;

    // Add theme support for Custom Logo.
    add_theme_support( 'custom-logo' , array(
        'height'        =>45,
        'width'         =>45,
        'flex-height'   =>true, 
        'flex-width'    =>true,
    ));

    add_theme_support( 'custom-background', array(
        'default-color' => 'ffffff'
    ) );

    add_theme_support( 'html5', array('comment-form','comment-list','gallery','caption',) );

    add_editor_style( array( 'assets/css/editor-style.css') );
}

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function charity_funds_widgets_init() {
    register_sidebar( array(
        'name'          => esc_html__( 'Sidebar', 'charity-funds' ),
        'id'            => 'sidebar-1',
        'description'   => esc_html__( 'Add widgets here.', 'charity-funds' ),
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );
    register_sidebar( array(
        'name'          => esc_html__( 'Footer 1', 'charity-funds' ),
        'id'            => 'footer-1',
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );
    register_sidebar( array(
        'name'          => esc_html__( 'Footer 2', 'charity-funds' ),
        'id'            => 'footer-2',
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );
    register_sidebar( array(
        'name'          => esc_html__( 'Footer 3', 'charity-funds' ),
        'id'            => 'footer-3',
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );
    register_sidebar( array(
        'name'          => esc_html__( 'Footer 4', 'charity-funds' ),
        'id'            => 'footer-4',
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );
}
add_action( 'widgets_init', 'charity_funds_widgets_init' );

// enqueue styles for child theme
function charity_funds_enqueue_styles() {
    // enqueue parent styles
    wp_enqueue_style('prime-charity-trust-style', get_template_directory_uri() .'/style.css');
    
    // enqueue child styles
    wp_enqueue_style('charity-funds-child-style', get_stylesheet_directory_uri() .'/style.css', array('prime-charity-trust-style'));

    wp_enqueue_script( 'comment-reply', '/wp-includes/js/comment-reply.min.js', array(), false, true );
}
add_action('wp_enqueue_scripts', 'charity_funds_enqueue_styles');

if ( ! function_exists( 'prime_charity_trust_footer_section' ) ) :

  /**
   * Footer copyright
   *
   * @since 1.0.0
   */
  function prime_charity_trust_footer_section() { ?>
     <?php
    $prime_charity_trust_footer_setting  = prime_charity_trust_get_option( 'prime_charity_trust_footer_setting' );
     if ( $prime_charity_trust_footer_setting ){ ?>
      <div class="site-info">
        <?php 
          $prime_charity_trust_copyright_footer = prime_charity_trust_get_option('copyright_text'); 
          if ( ! empty( $prime_charity_trust_copyright_footer ) ) {
            $prime_charity_trust_copyright_footer = wp_kses_data( $prime_charity_trust_copyright_footer );
          }
        ?>
        <div class="wrapper">
           <span class="copy-right"><a href="<?php echo esc_url( PRIME_CHARITY_TRUST_FOOTER_URL) ?>"><?php echo esc_html($prime_charity_trust_copyright_footer);?></a></span>
        </div><!-- .wrapper --> 
      </div> <!-- .site-info -->
    <?php } ?>

    <?php
    $prime_charity_trust_scroll_top  = prime_charity_trust_get_option( 'header_donate_scroll_to_top', true );
     if ( $prime_charity_trust_scroll_top ){ ?>
        <a id="button"><i class="fas fa-arrow-up"></i></a>
    <?php } ?>
    
  <?php }

endif;
add_action( 'prime_charity_trust_action_footer', 'prime_charity_trust_footer_section', 20 );

/**
 * Display the admin notice unless dismissed.
 */
// Remove parent notice
add_action( 'admin_init', function() {
    remove_action( 'admin_notices', 'prime_charity_trust_dashboard_notice' );
}, 100 );

// Add child notice
function prime_charity_trust_dashboard_notice_child() {
    $dismissed = get_user_meta( get_current_user_id(), 'prime_charity_trust_dismissable_notice', true );

    if ( ! $dismissed ) {
        $theme_name = wp_get_theme()->get( 'Name' );
        ?>
        <div class="updated notice notice-success is-dismissible notice-get-started-class" data-notice="get-start">
            <div class="notice-details">
                <div class="notice-content">
                    <h2>
                        <?php printf(
                            esc_html__( 'Thank you for installing %s.', 'prime-charity-trust' ),
                            '<strong>' . esc_html( $theme_name ) . '</strong>'
                        ); ?>
                    </h2>
                    <p><?php echo esc_html__( 'Your journey to a powerful and stylish website begins here. Let’s get everything set up in just a few clicks!', 'prime-charity-trust' ); ?></p>
                    <div class="notice-btns" style="padding-bottom: 25px">
                        <a class="button button-primary getstart"
                           href="<?php echo esc_url( admin_url( 'themes.php?page=prime-charity-trust' ) ); ?>">
                           <?php esc_html_e( 'Getting Started', 'prime-charity-trust' ); ?>
                        </a>
                       	<a class="button button-primary premium" target="_blank" href="<?php echo esc_url(PRIME_CHARITY_TRUST_URL); ?>"><?php esc_html_e('Go To Premium', 'prime-charity-trust') ?></a>
						<a class="button button-primary demo" target="_blank" href="<?php echo esc_url(PRIME_CHARITY_TRUST_DEMO_URL); ?>"><?php esc_html_e('View Demo', 'prime-charity-trust') ?></a>
                    </div>
                </div>
                <div class="notice-img">
                    <a href="<?php echo esc_url( PRIME_CHARITY_TRUST_BUNDLE_URL ); ?>" target="_blank"><img src="<?php echo esc_url( get_template_directory_uri() . '/assets/images/notice.png' ); ?>"></a>
                </div>
            </div>
        </div>
        <?php
    }
}
add_action( 'admin_notices', 'prime_charity_trust_dashboard_notice_child' );
