<?php
/**
 * Setup functions and some filters
 *
 * Here are the feature declarations, code includes and other code needed for the theme to set up.
 *
 * @package Multi
 */

if ( ! defined( 'ABSPATH' ) ) {
	die;
}

/**
 * Compatibility marker for Multi Pro and other plugins that extend this theme.
 * The value is the snake_case prefix used for all theme hooks, functions,
 * globals, theme mods and constants. Forks keep the constant name and change
 * the value (e.g. 'something_new' for a fork called "Something New").
 */
define( 'MULTIMAGAZINE_THEME_COMPATIBLE', 'multimagazine' );

define( 'MULTIMAGAZINE_THEME_DIR', get_template_directory() );
define( 'MULTIMAGAZINE_THEME_URI', get_template_directory_uri() );

if ( ! function_exists( 'is_plugin_active' ) ) {
	require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

require_once get_theme_file_path( '/customize/defaults.php' );

require_once get_theme_file_path( '/functions/class-multimagazine-menu-walker.php' );
require_once get_theme_file_path( '/functions/menus.php' );
require_once get_theme_file_path( '/functions/post-list.php' );
require_once get_theme_file_path( '/functions/footer.php' );
require_once get_theme_file_path( '/functions/comments.php' );
require_once get_theme_file_path( '/functions/post-slider.php' );
require_once get_theme_file_path( '/functions/related-posts.php' );
require_once get_theme_file_path( '/functions/featured-posts.php' );
require_once get_theme_file_path( '/functions/latest-posts.php' );
/* Sharing links are handled by the Multi Pro plugin (Multi_Pro_Sharing feature). */
require_once get_theme_file_path( '/functions/widget-areas.php' );
require_once get_theme_file_path( '/functions/styles.php' );
require_once get_theme_file_path( '/functions/scripts.php' );
require_once get_theme_file_path( '/functions/css-vars-parts/cursor.php' );
require_once get_theme_file_path( '/functions/css-vars-parts/header.php' );
require_once get_theme_file_path( '/functions/css-vars-parts/preloader.php' );
require_once get_theme_file_path( '/functions/css-vars-parts/scrollbar.php' );
require_once get_theme_file_path( '/functions/css-vars-parts/subheader.php' );

if ( is_admin() ) {
	require get_theme_file_path( '/functions/metaboxes.php' );
}

if ( class_exists( 'Woocommerce' ) ) {
	include get_theme_file_path( '/functions/woocommerce-support.php' );
}

/* Multi Builder Support */
require_once get_theme_file_path( '/functions/featured-projects.php' );

/* Other functions */
require get_theme_file_path( '/functions/utils.php' );
require get_theme_file_path( '/functions/css-variables.php' );
require get_theme_file_path( '/functions/setting-classes.php' );
require get_theme_file_path( '/functions/social.php' );
require get_theme_file_path( '/functions/categories.php' );
require get_theme_file_path( '/functions/class-multimagazine-sanitizer.php' );
require get_theme_file_path( '/functions/typography.php' );
require get_theme_file_path( '/functions/content-filters.php' );
require get_theme_file_path( '/functions/cleanup.php' );
require get_theme_file_path( '/functions/theme-setup.php' );

/**
 * Theme customizations
 */
require get_theme_file_path( '/functions/class-multimagazine-customize.php' );
global $wp_customize;
$multimagazine_customize = new Multimagazine_Customize( $wp_customize );

require get_theme_file_path( '/customize/class-multimagazine-customize-forms.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-messages.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-site-identity.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-general.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-layout.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-top-bar.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-header.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-subheader.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-buttons.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-social.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-sidebar.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-footer.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-go-top-link.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-blog.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-typography.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-colors.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-preloader.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-pagination.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-cursor.php' );
/* Sharing links customizer section is registered by the Multi Pro plugin. */
require get_theme_file_path( '/customize/class-multimagazine-customize-performance.php' );
require get_theme_file_path( '/customize/class-multimagazine-customize-pages.php' );

require get_theme_file_path( '/functions/tgm-plugin-activation/plugins.php' );
if ( ! isset( $content_width ) ) {
	$content_width = get_theme_mod( 'multi_layout_width', MULTIMAGAZINE_LAYOUT_WIDTH ); // phpcs:ignore WPThemeReview.CoreFunctionality.PrefixAllGlobals.NonPrefixedVariableFound
}

add_action( 'after_setup_theme', 'multimagazine_setup' );

add_action( 'widgets_init', 'multimagazine_widgets' );

add_action( 'wp_enqueue_scripts', 'multimagazine_styles', 1 );
add_action( 'wp_enqueue_scripts', 'multimagazine_css_vars', 1 );

add_action( 'admin_enqueue_scripts', 'multimagazine_add_admin_style' );

add_action( 'enqueue_block_editor_assets', 'multimagazine_block_editor_styles' );
add_action( 'enqueue_block_editor_assets', 'multimagazine_css_vars' );

add_action( 'wp_enqueue_scripts', 'multimagazine_scripts', 10 );

add_action( 'customize_preview_init', 'multimagazine_add_customizer_refresh_script' );

add_filter( 'paginate_links', 'untrailingslashit' );
add_filter( 'get_pagenum_link', 'untrailingslashit' );

/**
 * Calls the breadcrumbs rendering function
 */
function multimagazine_render_breadcrumbs() {
	if ( apply_filters( 'multimagazine_breadcrumbs_override', false ) ) {
		return;
	}
	if ( function_exists( 'diagnoseo_render_breadcrumbs' ) ) {
		diagnoseo_render_breadcrumbs();
	}
}
add_action( 'multimagazine_breadcrumbs', 'multimagazine_render_breadcrumbs' );

