<?php

/* ------------------------------------------------------------------------------
* Author: web-zone.org
* @package Airin Blog
* Description: Hook windows
* ------------------------------------------------------------------------------ */
/*--------------------------------------------------------------
Content:
----------------------------------------------------------------
# Placing the settings
    # Main
    # Top menu
    # Main menu
    # Wide slider
    # Footer
    # Home
    # Breadcrumbs
    # Categories
    # Posts
    # Pages
    # WooCommerce
    # bbPress
    # BuddyPress
# Display input fields
# Input validation
--------------------------------------------------------------*/
//? ========== Placing the settings
function airinblog_fun_theme_option_settings_hooks() {
    $section = 'airinblog_set_section_hook';
    $slug = 'hook-tab';
    $add = 'add_settings_field';
    $typ = 'textarea';
    $display = 'airinblog_fun_theme_display_settings_hooks';
    // Adding a settings section
    add_settings_section(
        $section,
        // ID
        esc_html__( 'Page for adding codes', 'airin-blog' ),
        // Title
        'airinblog_fun_callback_dis_hooks',
        // Additional function
        $slug
    );
    // Registering settings (settings are stored in the database - theme_options_hooks)
    register_setting( $slug, 'theme_options_hooks', 'airinblog_fun_theme_validate_settings_hooks' );
    //? ========== Main
    $set = array(
        'type' => $typ,
        'id'   => 'hook_before_head',
        'desc' => '',
    );
    $add(
        'airinblog_set_hook_before_head',
        sprintf( esc_html__( 'Before the closing %s tag', 'airin-blog' ), 'HEAD' ),
        $display,
        $slug,
        $section,
        $set
    );
    $set = array(
        'type' => $typ,
        'id'   => 'hook_before_body',
        'desc' => '',
    );
    $add(
        'airinblog_set_hook_before_body',
        sprintf( esc_html__( 'Before the closing %s tag', 'airin-blog' ), 'BODY' ),
        $display,
        $slug,
        $section,
        $set
    );
    // Display text premium
    $add(
        'airinblog_set_hook_text_premium',
        '',
        'airinblog_fun_callback_hook_premium',
        $slug,
        $section
    );
}

add_action( 'admin_init', 'airinblog_fun_theme_option_settings_hooks' );
//? ========== Display text dis hooks
function airinblog_fun_callback_dis_hooks() {
    echo esc_html__( 'On this page you can insert counters, banners, or any other content that will be displayed on the front of the site', 'airin-blog' );
}

//? ========== Display text premium
function airinblog_fun_callback_hook_premium() {
    echo '<div class="airinblog-css-set-admin-premium-block">';
    echo esc_html__( 'Get even more windows to insert codes in the premium version', 'airin-blog' ) . ' - ';
    echo '<a href="//web-zone.org/airin-blog/premium" target="_blank" rel="nofollow">' . esc_html__( 'Read More', 'airin-blog' ) . '</a>';
    echo '</div>';
}

//? ========== Display input fields
function airinblog_fun_theme_display_settings_hooks(  $args  ) {
    $desc = '';
    extract( $args );
    $opt_name = 'theme_options_hooks';
    $o = get_option( $opt_name );
    $text = ( isset( $o[$id] ) ? $o[$id] : '' );
    if ( $desc != '' ) {
        $d = "<br><span class='description'>{$desc}</span>";
    } else {
        $d = "";
    }
    switch ( $type ) {
        case 'textarea':
            echo "<textarea class='code large-text' cols='50' rows='10' type='text' id='" . esc_attr( $id ) . "' name='" . esc_attr( $opt_name ) . "[{$id}]'>" . trim( $text ) . "</textarea>";
            echo wp_kses_post( $d );
            break;
    }
}

//? ========== Input validation
function airinblog_fun_theme_validate_settings_hooks(  $input  ) {
    foreach ( $input as $k => $v ) {
        $valid_input[$k] = trim( $v );
    }
    return $valid_input;
}
