angelovcom.net

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

functions.php (11261B)


      1 <?php
      2 /**
      3  * Twenty Nineteen functions and definitions
      4  *
      5  * @link https://developer.wordpress.org/themes/basics/theme-functions/
      6  *
      7  * @package WordPress
      8  * @subpackage Twenty_Nineteen
      9  * @since Twenty Nineteen 1.0
     10  */
     11 
     12 /**
     13  * Twenty Nineteen only works in WordPress 4.7 or later.
     14  */
     15 if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
     16 	require get_template_directory() . '/inc/back-compat.php';
     17 	return;
     18 }
     19 
     20 if ( ! function_exists( 'twentynineteen_setup' ) ) :
     21 	/**
     22 	 * Sets up theme defaults and registers support for various WordPress features.
     23 	 *
     24 	 * Note that this function is hooked into the after_setup_theme hook, which
     25 	 * runs before the init hook. The init hook is too late for some features, such
     26 	 * as indicating support for post thumbnails.
     27 	 */
     28 	function twentynineteen_setup() {
     29 		/*
     30 		 * Make theme available for translation.
     31 		 * Translations can be filed in the /languages/ directory.
     32 		 * If you're building a theme based on Twenty Nineteen, use a find and replace
     33 		 * to change 'twentynineteen' to the name of your theme in all the template files.
     34 		 */
     35 		load_theme_textdomain( 'twentynineteen', get_template_directory() . '/languages' );
     36 
     37 		// Add default posts and comments RSS feed links to head.
     38 		add_theme_support( 'automatic-feed-links' );
     39 
     40 		/*
     41 		 * Let WordPress manage the document title.
     42 		 * By adding theme support, we declare that this theme does not use a
     43 		 * hard-coded <title> tag in the document head, and expect WordPress to
     44 		 * provide it for us.
     45 		 */
     46 		add_theme_support( 'title-tag' );
     47 
     48 		/*
     49 		 * Enable support for Post Thumbnails on posts and pages.
     50 		 *
     51 		 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
     52 		 */
     53 		add_theme_support( 'post-thumbnails' );
     54 		set_post_thumbnail_size( 1568, 9999 );
     55 
     56 		// This theme uses wp_nav_menu() in two locations.
     57 		register_nav_menus(
     58 			array(
     59 				'menu-1' => __( 'Primary', 'twentynineteen' ),
     60 				'footer' => __( 'Footer Menu', 'twentynineteen' ),
     61 				'social' => __( 'Social Links Menu', 'twentynineteen' ),
     62 			)
     63 		);
     64 
     65 		/*
     66 		 * Switch default core markup for search form, comment form, and comments
     67 		 * to output valid HTML5.
     68 		 */
     69 		add_theme_support(
     70 			'html5',
     71 			array(
     72 				'search-form',
     73 				'comment-form',
     74 				'comment-list',
     75 				'gallery',
     76 				'caption',
     77 				'script',
     78 				'style',
     79 				'navigation-widgets',
     80 			)
     81 		);
     82 
     83 		/**
     84 		 * Add support for core custom logo.
     85 		 *
     86 		 * @link https://codex.wordpress.org/Theme_Logo
     87 		 */
     88 		add_theme_support(
     89 			'custom-logo',
     90 			array(
     91 				'height'      => 190,
     92 				'width'       => 190,
     93 				'flex-width'  => false,
     94 				'flex-height' => false,
     95 			)
     96 		);
     97 
     98 		// Add theme support for selective refresh for widgets.
     99 		add_theme_support( 'customize-selective-refresh-widgets' );
    100 
    101 		// Add support for Block Styles.
    102 		add_theme_support( 'wp-block-styles' );
    103 
    104 		// Add support for full and wide align images.
    105 		add_theme_support( 'align-wide' );
    106 
    107 		// Add support for editor styles.
    108 		add_theme_support( 'editor-styles' );
    109 
    110 		// Enqueue editor styles.
    111 		add_editor_style( 'style-editor.css' );
    112 
    113 		// Add custom editor font sizes.
    114 		add_theme_support(
    115 			'editor-font-sizes',
    116 			array(
    117 				array(
    118 					'name'      => __( 'Small', 'twentynineteen' ),
    119 					'shortName' => __( 'S', 'twentynineteen' ),
    120 					'size'      => 19.5,
    121 					'slug'      => 'small',
    122 				),
    123 				array(
    124 					'name'      => __( 'Normal', 'twentynineteen' ),
    125 					'shortName' => __( 'M', 'twentynineteen' ),
    126 					'size'      => 22,
    127 					'slug'      => 'normal',
    128 				),
    129 				array(
    130 					'name'      => __( 'Large', 'twentynineteen' ),
    131 					'shortName' => __( 'L', 'twentynineteen' ),
    132 					'size'      => 36.5,
    133 					'slug'      => 'large',
    134 				),
    135 				array(
    136 					'name'      => __( 'Huge', 'twentynineteen' ),
    137 					'shortName' => __( 'XL', 'twentynineteen' ),
    138 					'size'      => 49.5,
    139 					'slug'      => 'huge',
    140 				),
    141 			)
    142 		);
    143 
    144 		// Editor color palette.
    145 		add_theme_support(
    146 			'editor-color-palette',
    147 			array(
    148 				array(
    149 					'name'  => 'default' === get_theme_mod( 'primary_color' ) ? __( 'Blue', 'twentynineteen' ) : null,
    150 					'slug'  => 'primary',
    151 					'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 33 ),
    152 				),
    153 				array(
    154 					'name'  => 'default' === get_theme_mod( 'primary_color' ) ? __( 'Dark Blue', 'twentynineteen' ) : null,
    155 					'slug'  => 'secondary',
    156 					'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 23 ),
    157 				),
    158 				array(
    159 					'name'  => __( 'Dark Gray', 'twentynineteen' ),
    160 					'slug'  => 'dark-gray',
    161 					'color' => '#111',
    162 				),
    163 				array(
    164 					'name'  => __( 'Light Gray', 'twentynineteen' ),
    165 					'slug'  => 'light-gray',
    166 					'color' => '#767676',
    167 				),
    168 				array(
    169 					'name'  => __( 'White', 'twentynineteen' ),
    170 					'slug'  => 'white',
    171 					'color' => '#FFF',
    172 				),
    173 			)
    174 		);
    175 
    176 		// Add support for responsive embedded content.
    177 		add_theme_support( 'responsive-embeds' );
    178 
    179 		// Add support for custom line height.
    180 		add_theme_support( 'custom-line-height' );
    181 	}
    182 endif;
    183 add_action( 'after_setup_theme', 'twentynineteen_setup' );
    184 
    185 /**
    186  * Register widget area.
    187  *
    188  * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
    189  */
    190 function twentynineteen_widgets_init() {
    191 
    192 	register_sidebar(
    193 		array(
    194 			'name'          => __( 'Footer', 'twentynineteen' ),
    195 			'id'            => 'sidebar-1',
    196 			'description'   => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ),
    197 			'before_widget' => '<section id="%1$s" class="widget %2$s">',
    198 			'after_widget'  => '</section>',
    199 			'before_title'  => '<h2 class="widget-title">',
    200 			'after_title'   => '</h2>',
    201 		)
    202 	);
    203 
    204 }
    205 add_action( 'widgets_init', 'twentynineteen_widgets_init' );
    206 
    207 /**
    208  * Replaces "[...]" (appended to automatically generated excerpts) with ... and
    209  * a 'Continue reading' link.
    210  *
    211  * @since Twenty Nineteen 2.0
    212  *
    213  * @param string $link Link to single post/page.
    214  * @return string 'Continue reading' link prepended with an ellipsis.
    215  */
    216 function twentynineteen_excerpt_more( $link ) {
    217 	if ( is_admin() ) {
    218 		return $link;
    219 	}
    220 
    221 	$link = sprintf(
    222 		'<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>',
    223 		esc_url( get_permalink( get_the_ID() ) ),
    224 		/* translators: %s: Post title. */
    225 		sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentynineteen' ), get_the_title( get_the_ID() ) )
    226 	);
    227 	return ' &hellip; ' . $link;
    228 }
    229 add_filter( 'excerpt_more', 'twentynineteen_excerpt_more' );
    230 
    231 /**
    232  * Set the content width in pixels, based on the theme's design and stylesheet.
    233  *
    234  * Priority 0 to make it available to lower priority callbacks.
    235  *
    236  * @global int $content_width Content width.
    237  */
    238 function twentynineteen_content_width() {
    239 	// This variable is intended to be overruled from themes.
    240 	// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
    241 	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
    242 	$GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 );
    243 }
    244 add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 );
    245 
    246 /**
    247  * Enqueue scripts and styles.
    248  */
    249 function twentynineteen_scripts() {
    250 	wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
    251 
    252 	wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );
    253 
    254 	if ( has_nav_menu( 'menu-1' ) ) {
    255 		wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '20181214', true );
    256 		wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '20181231', true );
    257 	}
    258 
    259 	wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
    260 
    261 	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    262 		wp_enqueue_script( 'comment-reply' );
    263 	}
    264 }
    265 add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );
    266 
    267 /**
    268  * Fix skip link focus in IE11.
    269  *
    270  * This does not enqueue the script because it is tiny and because it is only for IE11,
    271  * thus it does not warrant having an entire dedicated blocking script being loaded.
    272  *
    273  * @link https://git.io/vWdr2
    274  */
    275 function twentynineteen_skip_link_focus_fix() {
    276 	// The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
    277 	?>
    278 	<script>
    279 	/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
    280 	</script>
    281 	<?php
    282 }
    283 add_action( 'wp_print_footer_scripts', 'twentynineteen_skip_link_focus_fix' );
    284 
    285 /**
    286  * Enqueue supplemental block editor styles.
    287  */
    288 function twentynineteen_editor_customizer_styles() {
    289 
    290 	wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.1', 'all' );
    291 
    292 	if ( 'custom' === get_theme_mod( 'primary_color' ) ) {
    293 		// Include color patterns.
    294 		require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
    295 		wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() );
    296 	}
    297 }
    298 add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' );
    299 
    300 /**
    301  * Display custom color CSS in customizer and on frontend.
    302  */
    303 function twentynineteen_colors_css_wrap() {
    304 
    305 	// Only include custom colors in customizer or frontend.
    306 	if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'primary_color', 'default' ) ) || is_admin() ) {
    307 		return;
    308 	}
    309 
    310 	require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
    311 
    312 	$primary_color = 199;
    313 	if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
    314 		$primary_color = get_theme_mod( 'primary_color_hue', 199 );
    315 	}
    316 	?>
    317 
    318 	<style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
    319 		<?php echo twentynineteen_custom_colors_css(); ?>
    320 	</style>
    321 	<?php
    322 }
    323 add_action( 'wp_head', 'twentynineteen_colors_css_wrap' );
    324 
    325 /**
    326  * SVG Icons class.
    327  */
    328 require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php';
    329 
    330 /**
    331  * Custom Comment Walker template.
    332  */
    333 require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php';
    334 
    335 /**
    336  * Common theme functions.
    337  */
    338 require get_template_directory() . '/inc/helper-functions.php';
    339 
    340 /**
    341  * SVG Icons related functions.
    342  */
    343 require get_template_directory() . '/inc/icon-functions.php';
    344 
    345 /**
    346  * Enhance the theme by hooking into WordPress.
    347  */
    348 require get_template_directory() . '/inc/template-functions.php';
    349 
    350 /**
    351  * Custom template tags for the theme.
    352  */
    353 require get_template_directory() . '/inc/template-tags.php';
    354 
    355 /**
    356  * Customizer additions.
    357  */
    358 require get_template_directory() . '/inc/customizer.php';
    359 
    360 /**
    361  * Block Patterns.
    362  */
    363 require get_template_directory() . '/inc/block-patterns.php';