<?php
/**
 * corporate functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package WordPress
 * @subpackage corporate-fse
 * @since 1.0.0
 */
if ( ! function_exists( 'corporate_fse_support' ) ) :
    /**
     * Sets up theme defaults and registers support for various WordPress features.
     *
     * @since 1.0.0
     *
     * @return void
     */
    function corporate_fse_support() {
        // Add support for block styles.
        add_theme_support( 'wp-block-styles' );
        // Enqueue editor styles.
        add_editor_style( 'style.css' );

        load_theme_textdomain( 'corporate-fse', get_template_directory() . '/languages' );
    }
endif;
add_action( 'after_setup_theme', 'corporate_fse_support' );

if ( ! function_exists( 'corporate_fse_styles' ) ) :
    /**
     * Enqueue styles.
     *
     * @since 1.0.0
     *
     * @return void
     */
    function corporate_fse_styles() {
        // Register theme stylesheet.
        $theme_version = wp_get_theme()->get( 'Version' );
        $version_string = is_string( $theme_version ) ? $theme_version : false;
        wp_register_style(
            'corporate-fse-style',
            get_template_directory_uri() . '/style.css',
            array(),
            $version_string
        );
        // Enqueue theme stylesheet.
        wp_enqueue_style( 'corporate-fse-style' );
    }
endif;
add_action( 'wp_enqueue_scripts', 'corporate_fse_styles' );

add_post_type_support( 'page', 'excerpt' );
/**
 * Enqueue scripts and styles.
 */
function corporate_fse_scripts() {
    wp_enqueue_style('font-awesome', get_template_directory_uri(). '/assets/css/font-awesome/css/all.css','1.0.0', '5.15.3');
    wp_enqueue_script('main-script', get_template_directory_uri(). '/assets/js/index.js','1.0.0', array('jquery'), '1.0.0', true);
}
add_action( 'wp_enqueue_scripts', 'corporate_fse_scripts' );

/**
 * Load core file.
 */
require_once get_template_directory() . '/inc/pattern-category.php';
require_once get_template_directory() . '/inc/tgm-plugin/tgmpa-hook.php';

/**
 * Enqueue admin scripts and styles.
 */
function corporate_fse_admin_scripts() {

  // Register theme stylesheet.

  $deps = array();


  wp_enqueue_style( 'corporate-fse-admin-style', get_stylesheet_directory_uri() . '/assets/css/admin-style.css', $deps, date( 'Ymd-Gis', filemtime( get_theme_file_path( 'style.css' ) ) ) );

}
add_action( 'admin_enqueue_scripts', 'corporate_fse_admin_scripts' );


/**
 * Add theme page
 */
function corporate_fse_add_menu() {
  add_theme_page( esc_html__( 'Corporate FSE Theme', 'corporate-fse' ), esc_html__( 'Corporate FSE Theme', 'corporate-fse' ), 'edit_theme_options', 'corporate-fse', 'corporate_fse_theme_page_display' );
}
add_action( 'admin_menu', 'corporate_fse_add_menu' );

/**
 * Display About page
 */
function corporate_fse_theme_page_display() {
    $theme = wp_get_theme();
        include_once( 'inc/theme-info.php' );

}


/* only hook it if the user is not using pro version of rt easy builder plugin */
if ( function_exists( 'RT_Easy_Builder\rt_freemius' ) && ! RT_Easy_Builder\rt_freemius()->is_not_paying() )
    return;
else
    include_once( 'class/admin-info.php' );

function corporate_fse_excerpt_length( $length ){ 

    $excerpt_length = 25;
    if ( is_admin() ) return $length;
    return $excerpt_length;
}

add_filter( 'excerpt_length', 'corporate_fse_excerpt_length' );
