<?php

/* Magazi, WP FUNCTIONS FILE */

add_action('after_setup_theme', 'magazi_theme_setup');

function magazi_theme_setup() {

load_theme_textdomain('magazi', get_template_directory() . '/languages');

//CONTENT WIDTH
global $content_width;
if ( ! isset( $content_width ) )
$content_width = 800;

//THEME SUPPORT

add_theme_support( 'post-formats', array(
		'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video'
	) );

add_theme_support( 'title-tag' );

add_theme_support('post-thumbnails');

add_theme_support('automatic-feed-links');

add_editor_style( 'editor-style.css' );

add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
	) );
	
add_theme_support( 'custom-logo' );
	
add_filter( 'excerpt_length', function($length) { return 24; } );
	
//BLOCKS theme support
	
add_theme_support( 'wp-block-styles' );
	
add_theme_support( 'align-wide' );
	
add_theme_support( 'responsive-embeds' );
	
	//CUSTOM BACKGROUND
$args = array(
	'default-color' => '#FFFFFF',
);
add_theme_support( 'custom-background', $args );

//ADD NAVIGATION
add_action( 'init', 'magazi_register_my_menus' );

//ADD SIDEBARS
add_action( 'widgets_init', 'magazi_register_sidebars' );

//ENQUE STYLESHEETS AND SCRIPTS
add_action( 'wp_enqueue_scripts', 'magazi_enqueue_style' );

}


//FUNCTIONS


//ADD STYLESHEET TO PAGE
function magazi_enqueue_style() {
    wp_enqueue_style( 'magazi-style', get_stylesheet_uri() ); 
}


//MENU NAVIGATION
function magazi_register_my_menus() {
  register_nav_menus(
	array(
	'primary-menu' => __( 'Primary Menu','magazi' ),
	'secondary-menu' => __( 'Secondary Menu','magazi' )
	)
	);
}


//WIDGET AREAS
function magazi_register_sidebars() {
	
		register_sidebar( array(
		'name' => __( 'Large top banner', 'magazi' ),
		'id' => __( 'banner-1', 'magazi' ),
		'description' => __( 'Banner widget area on first page', 'magazi' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h2 class="widget-title">',
		'after_title' => '</h2>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Single post sidebar', 'magazi' ),
		'id' => __( 'sidebar-1', 'magazi' ),
		'description' => __( 'Sidebar widget area', 'magazi' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h2 class="widget-title">',
		'after_title' => '</h2>',
	) );
	
		register_sidebar( array(
		'name' => __( 'Front & page sidebar', 'magazi' ),
		'id' => __( 'sidebar-2', 'magazi' ),
		'description' => __( 'Sidebar widget area', 'magazi' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h2 class="widget-title">',
		'after_title' => '</h2>',
	) );

	register_sidebar( array(
		'name' => __( 'Footer with 4 widget areas', 'magazi' ),
		'id' => __( 'footer-1', 'magazi' ),
		'description' => __( 'Footer widget area', 'magazi' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h2 class="widget-title">',
		'after_title' => '</h2>',
	) );

}

//BLOCKS
function magazi_register_block_style( $block_name, $style_properties ) {
    return WP_Block_Styles_Registry::get_instance()->register( $block_name, $style_properties );
}

function magazi_register_block_pattern( $pattern_name, $pattern_properties ) {
    return WP_Block_Patterns_Registry::get_instance()->register( $pattern_name, $pattern_properties );
}

//SCRIPTS THREADED COMMENTS
function magazi_load_scripts() {

	if ( is_singular() && get_option( 'thread_comments' ) && comments_open() )
		wp_enqueue_script( 'comment-reply' );
}

// REPLACES THE EXCERPT "READ MORE" WITH AN ARROW
function new_excerpt_more($more) {
       global $post;
	return '<a class="moretag" href="'. get_permalink($post->ID) . '"> &nbsp; &rarr;</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

?>