<?php
/**
 * WordPress function Page
 */
if ( ! isset( $content_width ) ) {
  $content_width = 1170;
}
if ( ! function_exists( 'magazina_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 *
 */
function magazina_setup() {
  /*
   * Make theme available for translation.
   * Translations can be filed in the /languages/ directory.
   */
   load_theme_textdomain('magazina', get_parent_theme_file_uri('/languages'));
    // Add RSS feed links to <head> for posts and comments.
    add_theme_support( 'automatic-feed-links' );
    /* Set the image size by cropping the image */
    add_theme_support('post-thumbnails');
    add_image_size( 'magazina-two-grid-thumb', 562, 320, true );
    add_image_size( 'magazina-related-post', 225, 140, true );
    /*
     * Switch default core markup for search form, comment form, and comments
     * to output valid HTML5.
     */
    add_theme_support( 'html5', array('comment-form', 'comment-list', 'gallery', 'caption'
    ) );
    /*
   * Let WordPress manage the document title.
   * By adding theme support, we declare that this theme does not use a
   * hard-coded <title> tag in the document head, and expect WordPress to
   * provide it for us.
   */
  add_theme_support( 'title-tag' );
  add_theme_support( 'custom-logo', array(
    'height'      => 70,
    'width'       => 300,
    'flex-height' => true,
  ) );
  $args = array(
  'default-color' => 'f5f5f5',
);
add_theme_support( 'custom-background', $args );  
// Add custom-header
  $defaults = array(
    'default-image'          =>'',
    'flex-height'            => false,
    'flex-width'             => false,
    'uploads'                => true,
    'random-default'         => false,
    'header-text'            => true,
    'default-text-color'     => '',
    'wp-head-callback'       => '',
    'admin-head-callback'    => '',
    'admin-preview-callback' => '',
);
  // Add support for Block Styles.
        add_theme_support( 'wp-block-styles' );

        // Add support for full and wide align images.
        add_theme_support( 'align-wide' );

        // Add support for editor styles.
        add_theme_support( 'editor-styles' );

        // Enqueue editor styles.
        add_editor_style( 'style-editor.css' );
        // Add support for responsive embedded content.
        add_theme_support( 'responsive-embeds' );
        
  add_theme_support( 'custom-header',$defaults );
// Add custom-background
  add_theme_support( 'custom-background' );
  // Recommend plugins
        add_theme_support( 'recommend-plugins', array(
            'blogwings-companion' => array(
                'name' => esc_html__( 'Blogwings Companion', 'magazina' ),
                'active_filename' => 'blogwings-companion/blogwings-companion.php',
            ),
            'one-click-demo-import' => array(
                'name' => esc_html__( 'One Click Demo Import', 'magazina' ),
                'active_filename' => 'one-click-demo-import/one-click-demo-import.php',
            ),'mailchimp-for-wp' => array(
                'name' => esc_html__( 'MailChimp for WordPress', 'magazina' ),
                'active_filename' => 'mailchimp-for-wp/mailchimp-for-wp.php',
            )) 
      );
}
endif;  
add_action( 'after_setup_theme', 'magazina_setup' );
require_once( get_parent_theme_file_path('/inc/include.php') );

// Load demo.
require_once trailingslashit( get_template_directory() ) . 'demo/class-demo.php';
require_once trailingslashit( get_template_directory() ) . 'demo/import-data.php';

// google-font-call
function magazina_fonts_url() {
  $fonts_url = '';
  /*
  Translators: If there are characters in your language that are not
  * supported by Roboto or Roboto Slab, translate this to 'off'. Do not translate
  * into your own language.
   */
  $Lato = _x( 'on', 'Lato font: on or off', 'magazina' );
  $Lato_slab = _x( 'on', 'Lato Slab font: on or off', 'magazina' );

  if ( 'off' !== $Lato || 'off' !== $Lato_slab ) {
    $font_families = array();

    if ( 'off' !== $Lato ) {
      $font_families[] = 'Lato:300,400,500,700';
    }

    if ( 'off' !== $Lato_slab ) {
      $font_families[] = 'Lato Slab:400,700';
    }

    $query_args = array(
      'family' => urlencode( implode( '|', $font_families ) ),
      'subset' => urlencode( 'latin,latin-ext' ),
    );
    $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  }
  return $fonts_url;
}


/**
 * Enqueue scripts and styles for the front end.

 */
function magazina_scripts() {
  // Add Genericons font, used in the main stylesheet.
  wp_enqueue_style( 'magazina_fonts', magazina_fonts_url(), array(), '1.0.0' );
    wp_enqueue_style( 'magazina-font-awesome-new', get_parent_theme_file_uri('/font-awesome/css/fontawesome-all.css'), array(), '1.0.0' );
  wp_enqueue_style( 'magazina-font-awesome-old', get_parent_theme_file_uri('/font-awesome/css/font-awesome.css'), array(), '1.0.0' );
  // Load our main stylesheet.
  wp_enqueue_style('magazina-style', get_stylesheet_uri(), array(), '1.0.0' );
  wp_add_inline_style( 'magazina-style', magazina_custom_header() );

  wp_enqueue_script( 'classie', get_parent_theme_file_uri('/js/classie.js'), array( 'jquery' ), '', true );
  wp_enqueue_script( 'magazina-custom', get_parent_theme_file_uri('/js/custom.js'), array( 'jquery' ), '', true );
  // Comment reply
    if (is_singular() && get_option('thread_comments')){
    wp_enqueue_script('comment-reply');
  }
}
add_action( 'wp_enqueue_scripts', 'magazina_scripts' );
// home page post meta
function magazina_home_post_meta($search,$default=false){
 $home_post_meta = get_theme_mod('home_post_meta');
$value = (!empty($home_post_meta) && !empty($home_post_meta[0]))?in_array($search, $home_post_meta):$default;
return $value;
}


function mytheme_setup_theme_supported_features() {
    add_theme_support( 'editor-color-palette',
        '#a156b4',
        '#d0a5db',
        '#eee',
        '#444'
    );
}

add_action( 'after_setup_theme', 'mytheme_setup_theme_supported_features' );