| Current Path : /home/x/b/o/xbodynamge/namtation/wp-content/ |
| Current File : /home/x/b/o/xbodynamge/namtation/wp-content/template-functions.php.tar |
home/xbodynamge/crosstraining/wp-content/themes/twentyseventeen/inc/template-functions.php 0000604 00000004774 15112661634 0026470 0 ustar 00 <?php
/**
* Additional features to allow styling of the templates
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function twentyseventeen_body_classes( $classes ) {
// Add class of group-blog to blogs with more than 1 published author.
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
// Add class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
// Add class if we're viewing the Customizer for easier styling of theme options.
if ( is_customize_preview() ) {
$classes[] = 'twentyseventeen-customizer';
}
// Add class on front page.
if ( is_front_page() && 'posts' !== get_option( 'show_on_front' ) ) {
$classes[] = 'twentyseventeen-front-page';
}
// Add a class if there is a custom header.
if ( has_header_image() ) {
$classes[] = 'has-header-image';
}
// Add class if sidebar is used.
if ( is_active_sidebar( 'sidebar-1' ) && ! is_page() ) {
$classes[] = 'has-sidebar';
}
// Add class for one or two column page layouts.
if ( is_page() || is_archive() ) {
if ( 'one-column' === get_theme_mod( 'page_layout' ) ) {
$classes[] = 'page-one-column';
} else {
$classes[] = 'page-two-column';
}
}
// Add class if the site title and tagline is hidden.
if ( 'blank' === get_header_textcolor() ) {
$classes[] = 'title-tagline-hidden';
}
// Get the colorscheme or the default if there isn't one.
$colors = twentyseventeen_sanitize_colorscheme( get_theme_mod( 'colorscheme', 'light' ) );
$classes[] = 'colors-' . $colors;
return $classes;
}
add_filter( 'body_class', 'twentyseventeen_body_classes' );
/**
* Count our number of active panels.
*
* Primarily used to see if we have any panels active, duh.
*/
function twentyseventeen_panel_count() {
$panel_count = 0;
/**
* Filter number of front page sections in Twenty Seventeen.
*
* @since Twenty Seventeen 1.0
*
* @param int $num_sections Number of front page sections.
*/
$num_sections = apply_filters( 'twentyseventeen_front_page_sections', 4 );
// Create a setting and control for each of the sections available in the theme.
for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) {
if ( get_theme_mod( 'panel_' . $i ) ) {
$panel_count++;
}
}
return $panel_count;
}
/**
* Checks to see if we're on the homepage or not.
*/
function twentyseventeen_is_frontpage() {
return ( is_front_page() && ! is_home() );
}
home/xbodynamge/crosstraining/wp-content/themes/custom-file-5-1751661813/inc/template-functions.php 0000644 00000001637 15113753075 0026677 0 ustar 00 <?php
/**
* Functions which enhance the theme by hooking into WordPress
*
* @package PopularFX
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function popularfx_body_classes( $classes ) {
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
// Adds a class of no-sidebar when there is no sidebar present.
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'no-sidebar';
}
return $classes;
}
add_filter( 'body_class', 'popularfx_body_classes' );
/**
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
*/
function popularfx_pingback_header() {
if ( is_singular() && pings_open() ) {
printf( '<link rel="pingback" href="%s">', esc_url( get_bloginfo( 'pingback_url' ) ) );
}
}
add_action( 'wp_head', 'popularfx_pingback_header' );
home/xbodynamge/lebauwcentre/wp-content/themes/customify/inc/template-functions.php 0000644 00000024535 15114373661 0025041 0 ustar 00 <?php
/**
* Functions which enhance the theme by hooking into WordPress
*
* @package customify
*/
if ( ! function_exists( 'customify_get_config_sidebar_layouts' ) ) {
function customify_get_config_sidebar_layouts() {
return array(
'content-sidebar' => __( 'Content / Sidebar', 'customify' ),
'sidebar-content' => __( 'Sidebar / Content', 'customify' ),
'content' => __( 'Content (no sidebars)', 'customify' ),
'sidebar-content-sidebar' => __( 'Sidebar / Content / Sidebar', 'customify' ),
'sidebar-sidebar-content' => __( 'Sidebar / Sidebar / Content', 'customify' ),
'content-sidebar-sidebar' => __( 'Content / Sidebar / Sidebar', 'customify' ),
);
}
}
if ( ! function_exists( 'customify_get_all_image_sizes' ) ) {
/**
* Get all the registered image sizes along with their dimensions
*
* @global array $_wp_additional_image_sizes
*
* @link http://core.trac.wordpress.org/ticket/18947 Reference ticket
* @return array $image_sizes The image sizes
*/
function customify_get_all_image_sizes() {
global $_wp_additional_image_sizes;
$default_image_sizes = array( 'thumbnail', 'medium', 'large' );
foreach ( $default_image_sizes as $size ) {
$image_sizes[ $size ]['width'] = intval( get_option( "{$size}_size_w" ) );
$image_sizes[ $size ]['height'] = intval( get_option( "{$size}_size_h" ) );
$image_sizes[ $size ]['crop'] = get_option( "{$size}_crop" ) ? get_option( "{$size}_crop" ) : false;
}
if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) ) {
$image_sizes = array_merge( $image_sizes, $_wp_additional_image_sizes );
}
$options = array();
foreach ( $image_sizes as $k => $option ) {
$options[ $k ] = sprintf( '%1$s - (%2$s x %3$s)', $k, $option['width'], $option['height'] );
}
$options['full'] = 'Full';
return $options;
}
}
if ( ! function_exists( 'customify_get_layout' ) ) {
/**
* Get the layout for the current page from Customizer setting or individual page/post.
*
* @since 0.0.1
* @since 0.2.6
*/
function customify_get_layout() {
$default = Customify()->get_setting( 'sidebar_layout' );
$layout = apply_filters( 'customify_get_layout', null );
if ( ! $layout ) {
$page = Customify()->get_setting( 'page_sidebar_layout' );
if ( is_home() && is_front_page() || ( is_home() && ! is_front_page() ) ) { // Blog page.
$blog_posts = Customify()->get_setting( 'posts_sidebar_layout' );
$layout = $blog_posts;
} elseif ( is_page() ) { // Page.
$layout = Customify()->get_setting( 'page_sidebar_layout' );
} elseif ( is_search() ) { // Search.
$search = Customify()->get_setting( 'search_sidebar_layout' );
$layout = $search;
} elseif ( is_archive() ) { // Archive.
$archive = Customify()->get_setting( 'posts_archives_sidebar_layout' );
$layout = $archive;
} elseif ( is_category() || is_tag() || is_singular( 'post' ) ) { // blog page and single page.
$blog_posts = Customify()->get_setting( 'posts_sidebar_layout' );
$layout = $blog_posts;
} elseif ( is_404() ) { // 404 Page.
$layout = Customify()->get_setting( '404_sidebar_layout' );
} elseif ( is_singular() ) {
$layout = Customify()->get_setting( get_post_type() . '_sidebar_layout' );
}
// Support for all posts that using meta settings.
if ( Customify()->is_using_post() && customify_is_support_meta() ) {
$post_type = get_post_type();
$page_custom = get_post_meta( customify_get_support_meta_id(), '_customify_sidebar', true );
if ( ! $page_custom ) {
if ( Customify()->is_woocommerce_active() ) {
if ( is_cart() || is_checkout() || is_account_page() || is_product() ) {
$page_custom = 'content';
}
}
}
if ( $page_custom ) {
if ( $page_custom && 'default' != $page_custom ) {
$layout = $page_custom;
}
} elseif ( 'page' == $post_type ) {
$layout = $page;
}
}
}
if ( ! $layout ) {
$layout = $default;
}
return $layout;
}
}
if ( ! function_exists( 'customify_get_sidebars' ) ) {
/**
* Display primary or/and secondary sidebar base on layout setting.
*
* @since 0.0.1
*/
function customify_get_sidebars() {
// Get the current layout.
$layout = customify_get_layout();
if ( ! $layout || 'default' == $layout ) {
$layout = 'content-sidebar';
}
// Layout with 2 column.
$layout_2_columns = array( 'sidebar-content', 'content-sidebar' );
// Layout with 3 column.
$layout_3_columns = array( 'sidebar-sidebar-content', 'sidebar-content-sidebar', 'content-sidebar-sidebar' );
// Only show primary sidebar for 2 column layout.
if ( in_array( $layout, $layout_2_columns ) ) { // phpcs:ignore
get_sidebar();
}
// Show both sidebar for 3 column layout.
if ( in_array( $layout, $layout_3_columns ) ) { // phpcs:ignore
get_sidebar();
get_sidebar( 'secondary' );
}
}
}
add_action( 'customify/sidebars', 'customify_get_sidebars' );
if ( ! function_exists( 'customify_pingback_header' ) ) {
/**
* Add a pingback url auto-discovery header for singularly identifiable articles.
*/
function customify_pingback_header() {
if ( is_singular() && pings_open() ) {
echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
}
}
}
add_action( 'wp_head', 'customify_pingback_header' );
if ( ! function_exists( 'customify_is_support_meta' ) ) {
function customify_is_support_meta() {
$support = is_singular();
if ( is_home() && get_option( 'page_for_posts' ) ) {
$support = true;
}
return $support;
}
}
if ( ! function_exists( 'customify_get_support_meta_id' ) ) {
function customify_get_support_meta_id() {
$id = is_singular() ? get_the_ID() : false;
if ( is_home() && get_option( 'page_for_posts' ) ) {
$id = get_option( 'page_for_posts' );
}
return $id;
}
}
if ( ! function_exists( 'customify_is_header_display' ) ) {
/**
* Check if show header
*
* @return bool
*/
function customify_is_header_display() {
$show = true;
// page_for_posts.
if ( customify_is_support_meta() ) {
$disable = get_post_meta( customify_get_support_meta_id(), '_customify_disable_header', true );
if ( $disable ) {
$show = false;
}
}
return apply_filters( 'customify_is_header_display', $show );
}
}
if ( ! function_exists( 'customify_is_footer_display' ) ) {
/**
* Check if show header
*
* @return bool
*/
function customify_is_footer_display() {
$show = true;
if ( customify_is_support_meta() ) {
$rows = array( 'main', 'bottom' );
if ( class_exists( 'Customify_Pro' ) ) {
$rows[] = 'top';
}
$count = 0;
foreach ( $rows as $row_id ) {
if ( ! customify_is_builder_row_display( 'footer', $row_id ) ) {
$count ++;
}
}
if ( $count >= count( $rows ) ) {
$show = false;
}
}
return apply_filters( 'customify_is_footer_display', $show );
}
}
if ( ! function_exists( 'customify_is_builder_row_display' ) ) {
/**
* Check if show header
*
* @param string $builder_id
* @param bool $row_id
* @param bool $post_id
*
* @return mixed
*/
function customify_is_builder_row_display( $builder_id, $row_id = false, $post_id = false ) {
$show = true;
if ( $row_id && $builder_id ) {
if ( ! $post_id ) {
$post_id = apply_filters( 'customify_builder_row_display_get_post_id', customify_get_support_meta_id() );
}
$key = $builder_id . '_' . $row_id;
$disable = get_post_meta( $post_id, '_customify_disable_' . $key, true );
if ( $disable ) {
$show = false;
}
}
return apply_filters( 'customify_is_builder_row_display', $show, $builder_id, $row_id, $post_id );
}
}
if ( ! function_exists( 'customify_show_post_title' ) ) {
/**
* Check if display title of any post type
*/
function customify_is_post_title_display() {
$show = true;
if ( Customify()->is_using_post() ) {
$disable = get_post_meta( Customify()->get_current_post_id(), '_customify_disable_page_title', true );
if ( $disable ) {
$show = false;
}
}
$r = apply_filters( 'customify_is_post_title_display', $show );
return $r;
}
}
/**
* Retrieve the archive title based on the queried object.
*
* @param string $title
*
* @return string Archive title.
*/
function customify_get_the_archive_title( $title ) {
$disable = Customify()->get_setting( 'page_header_show_archive_prefix' );
if ( ! $disable ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>';
} elseif ( is_year() ) {
$title = get_the_date( _x( 'Y', 'yearly archives date format', 'customify' ) );
} elseif ( is_month() ) {
$title = get_the_date( _x( 'F Y', 'monthly archives date format', 'customify' ) );
} elseif ( is_day() ) {
$title = get_the_date( _x( 'F j, Y', 'daily archives date format', 'customify' ) );
} elseif ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
}
}
return $title;
}
add_filter( 'get_the_archive_title', 'customify_get_the_archive_title', 15 );
function customify_search_form( $form ) {
$form = '
<form role="search" class="sidebar-search-form" action="' . esc_url( home_url( '/' ) ) . '">
<label>
<span class="screen-reader-text">' . _x( 'Search for:', 'label', 'customify' ) . '</span>
<input type="search" class="search-field" placeholder="' . esc_attr__( 'Search …', 'customify' ) . '" value="' . get_search_query() . '" name="s" title="' . esc_attr_x( 'Search for:', 'label', 'customify' ) . '" />
</label>
<button type="submit" class="search-submit" >
<svg aria-hidden="true" focusable="false" role="presentation" xmlns="http://www.w3.org/2000/svg" width="20" height="21" viewBox="0 0 20 21">
<path id="svg-search" fill="currentColor" fill-rule="evenodd" d="M12.514 14.906a8.264 8.264 0 0 1-4.322 1.21C3.668 16.116 0 12.513 0 8.07 0 3.626 3.668.023 8.192.023c4.525 0 8.193 3.603 8.193 8.047 0 2.033-.769 3.89-2.035 5.307l4.999 5.552-1.775 1.597-5.06-5.62zm-4.322-.843c3.37 0 6.102-2.684 6.102-5.993 0-3.31-2.732-5.994-6.102-5.994S2.09 4.76 2.09 8.07c0 3.31 2.732 5.993 6.102 5.993z"></path>
</svg>
</button>
</form>';
return $form;
}
add_filter( 'get_search_form', 'customify_search_form' );
home/xbodynamge/lebauwcentre/wp-content/themes/twentyseventeen/inc/template-functions.php 0000604 00000005001 15114417342 0026240 0 ustar 00 <?php
/**
* Additional features to allow styling of the templates
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function twentyseventeen_body_classes( $classes ) {
// Add class of group-blog to blogs with more than 1 published author.
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
// Add class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
// Add class if we're viewing the Customizer for easier styling of theme options.
if ( is_customize_preview() ) {
$classes[] = 'twentyseventeen-customizer';
}
// Add class on front page.
if ( is_front_page() && 'posts' !== get_option( 'show_on_front' ) ) {
$classes[] = 'twentyseventeen-front-page';
}
// Add a class if there is a custom header.
if ( has_header_image() ) {
$classes[] = 'has-header-image';
}
// Add class if sidebar is used.
if ( is_active_sidebar( 'sidebar-1' ) && ! is_page() ) {
$classes[] = 'has-sidebar';
}
// Add class for one or two column page layouts.
if ( is_page() || is_archive() ) {
if ( 'one-column' === get_theme_mod( 'page_layout' ) ) {
$classes[] = 'page-one-column';
} else {
$classes[] = 'page-two-column';
}
}
// Add class if the site title and tagline is hidden.
if ( 'blank' === get_header_textcolor() ) {
$classes[] = 'title-tagline-hidden';
}
// Get the colorscheme or the default if there isn't one.
$colors = twentyseventeen_sanitize_colorscheme( get_theme_mod( 'colorscheme', 'light' ) );
$classes[] = 'colors-' . $colors;
return $classes;
}
add_filter( 'body_class', 'twentyseventeen_body_classes' );
/**
* Count our number of active panels.
*
* Primarily used to see if we have any panels active, duh.
*/
function twentyseventeen_panel_count() {
$panel_count = 0;
/**
* Filter number of front page sections in Twenty Seventeen.
*
* @since Twenty Seventeen 1.0
*
* @param int $num_sections Number of front page sections.
*/
$num_sections = apply_filters( 'twentyseventeen_front_page_sections', 4 );
// Create a setting and control for each of the sections available in the theme.
for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) {
if ( get_theme_mod( 'panel_' . $i ) ) {
$panel_count++;
}
}
return $panel_count;
}
/**
* Checks to see if we're on the front page or not.
*/
function twentyseventeen_is_frontpage() {
return ( is_front_page() && ! is_home() );
}
home/xbodynamge/lebauwcentre/wp-content/themes/twentynineteen/inc/template-functions.php 0000604 00000030710 15114516424 0026057 0 ustar 00 <?php
/**
* Functions which enhance the theme by hooking into WordPress
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function twentynineteen_body_classes( $classes ) {
if ( is_singular() ) {
// Adds `singular` to singular pages.
$classes[] = 'singular';
} else {
// Adds `hfeed` to non singular pages.
$classes[] = 'hfeed';
}
// Adds a class if image filters are enabled.
if ( twentynineteen_image_filters_enabled() ) {
$classes[] = 'image-filters-enabled';
}
return $classes;
}
add_filter( 'body_class', 'twentynineteen_body_classes' );
/**
* Adds custom class to the array of posts classes.
*/
function twentynineteen_post_classes( $classes, $class, $post_id ) {
$classes[] = 'entry';
return $classes;
}
add_filter( 'post_class', 'twentynineteen_post_classes', 10, 3 );
/**
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
*/
function twentynineteen_pingback_header() {
if ( is_singular() && pings_open() ) {
echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
}
}
add_action( 'wp_head', 'twentynineteen_pingback_header' );
/**
* Changes comment form default fields.
*/
function twentynineteen_comment_form_defaults( $defaults ) {
$comment_field = $defaults['comment_field'];
// Adjust height of comment form.
$defaults['comment_field'] = preg_replace( '/rows="\d+"/', 'rows="5"', $comment_field );
return $defaults;
}
add_filter( 'comment_form_defaults', 'twentynineteen_comment_form_defaults' );
/**
* Filters the default archive titles.
*/
function twentynineteen_get_the_archive_title() {
if ( is_category() ) {
$title = __( 'Category Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
} elseif ( is_tag() ) {
$title = __( 'Tag Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
} elseif ( is_author() ) {
$title = __( 'Author Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_author_meta( 'display_name' ) . '</span>';
} elseif ( is_year() ) {
$title = __( 'Yearly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentynineteen' ) ) . '</span>';
} elseif ( is_month() ) {
$title = __( 'Monthly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentynineteen' ) ) . '</span>';
} elseif ( is_day() ) {
$title = __( 'Daily Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date() . '</span>';
} elseif ( is_post_type_archive() ) {
$title = __( 'Post Type Archives: ', 'twentynineteen' ) . '<span class="page-description">' . post_type_archive_title( '', false ) . '</span>';
} elseif ( is_tax() ) {
$tax = get_taxonomy( get_queried_object()->taxonomy );
/* translators: %s: Taxonomy singular name */
$title = sprintf( esc_html__( '%s Archives:', 'twentynineteen' ), $tax->labels->singular_name );
} else {
$title = __( 'Archives:', 'twentynineteen' );
}
return $title;
}
add_filter( 'get_the_archive_title', 'twentynineteen_get_the_archive_title' );
/**
* Determines if post thumbnail can be displayed.
*/
function twentynineteen_can_show_post_thumbnail() {
return apply_filters( 'twentynineteen_can_show_post_thumbnail', ! post_password_required() && ! is_attachment() && has_post_thumbnail() );
}
/**
* Returns true if image filters are enabled on the theme options.
*/
function twentynineteen_image_filters_enabled() {
return 0 !== get_theme_mod( 'image_filter', 1 );
}
/**
* Add custom sizes attribute to responsive image functionality for post thumbnails.
*
* @origin Twenty Nineteen 1.0
*
* @param array $attr Attributes for the image markup.
* @return string Value for use in post thumbnail 'sizes' attribute.
*/
function twentynineteen_post_thumbnail_sizes_attr( $attr ) {
if ( is_admin() ) {
return $attr;
}
if ( ! is_singular() ) {
$attr['sizes'] = '(max-width: 34.9rem) calc(100vw - 2rem), (max-width: 53rem) calc(8 * (100vw / 12)), (min-width: 53rem) calc(6 * (100vw / 12)), 100vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 );
/**
* Returns the size for avatars used in the theme.
*/
function twentynineteen_get_avatar_size() {
return 60;
}
/**
* Returns true if comment is by author of the post.
*
* @see get_comment_class()
*/
function twentynineteen_is_comment_by_post_author( $comment = null ) {
if ( is_object( $comment ) && $comment->user_id > 0 ) {
$user = get_userdata( $comment->user_id );
$post = get_post( $comment->comment_post_ID );
if ( ! empty( $user ) && ! empty( $post ) ) {
return $comment->user_id === $post->post_author;
}
}
return false;
}
/**
* Returns information about the current post's discussion, with cache support.
*/
function twentynineteen_get_discussion_data() {
static $discussion, $post_id;
$current_post_id = get_the_ID();
if ( $current_post_id === $post_id ) {
return $discussion; /* If we have discussion information for post ID, return cached object */
} else {
$post_id = $current_post_id;
}
$comments = get_comments(
array(
'post_id' => $current_post_id,
'orderby' => 'comment_date_gmt',
'order' => get_option( 'comment_order', 'asc' ), /* Respect comment order from Settings » Discussion. */
'status' => 'approve',
'number' => 20, /* Only retrieve the last 20 comments, as the end goal is just 6 unique authors */
)
);
$authors = array();
foreach ( $comments as $comment ) {
$authors[] = ( (int) $comment->user_id > 0 ) ? (int) $comment->user_id : $comment->comment_author_email;
}
$authors = array_unique( $authors );
$discussion = (object) array(
'authors' => array_slice( $authors, 0, 6 ), /* Six unique authors commenting on the post. */
'responses' => get_comments_number( $current_post_id ), /* Number of responses. */
);
return $discussion;
}
/**
* Add an extra menu to our nav for our priority+ navigation to use
*
* @param object $nav_menu Nav menu.
* @param object $args Nav menu args.
* @return string More link for hidden menu items.
*/
function twentynineteen_add_ellipses_to_nav( $nav_menu, $args ) {
if ( 'menu-1' === $args->theme_location ) :
$nav_menu .= '<div class="main-menu-more">';
$nav_menu .= '<ul class="main-menu">';
$nav_menu .= '<li class="menu-item menu-item-has-children">';
$nav_menu .= '<button class="submenu-expand main-menu-more-toggle is-empty" tabindex="-1" aria-label="More" aria-haspopup="true" aria-expanded="false">';
$nav_menu .= '<span class="screen-reader-text">' . esc_html__( 'More', 'twentynineteen' ) . '</span>';
$nav_menu .= twentynineteen_get_icon_svg( 'arrow_drop_down_ellipsis' );
$nav_menu .= '</button>';
$nav_menu .= '<ul class="sub-menu hidden-links">';
$nav_menu .= '<li id="menu-item--1" class="mobile-parent-nav-menu-item menu-item--1">';
$nav_menu .= '<button class="menu-item-link-return">';
$nav_menu .= twentynineteen_get_icon_svg( 'chevron_left' );
$nav_menu .= esc_html__( 'Back', 'twentynineteen' );
$nav_menu .= '</button>';
$nav_menu .= '</li>';
$nav_menu .= '</ul>';
$nav_menu .= '</li>';
$nav_menu .= '</ul>';
$nav_menu .= '</div>';
endif;
return $nav_menu;
}
add_filter( 'wp_nav_menu', 'twentynineteen_add_ellipses_to_nav', 10, 2 );
/**
* WCAG 2.0 Attributes for Dropdown Menus
*
* Adjustments to menu attributes tot support WCAG 2.0 recommendations
* for flyout and dropdown menus.
*
* @ref https://www.w3.org/WAI/tutorials/menus/flyout/
*/
function twentynineteen_nav_menu_link_attributes( $atts, $item, $args, $depth ) {
// Add [aria-haspopup] and [aria-expanded] to menu items that have children
$item_has_children = in_array( 'menu-item-has-children', $item->classes );
if ( $item_has_children ) {
$atts['aria-haspopup'] = 'true';
$atts['aria-expanded'] = 'false';
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'twentynineteen_nav_menu_link_attributes', 10, 4 );
/**
* Add a dropdown icon to top-level menu items.
*
* @param string $output Nav menu item start element.
* @param object $item Nav menu item.
* @param int $depth Depth.
* @param object $args Nav menu args.
* @return string Nav menu item start element.
* Add a dropdown icon to top-level menu items
*/
function twentynineteen_add_dropdown_icons( $output, $item, $depth, $args ) {
// Only add class to 'top level' items on the 'primary' menu.
if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) {
return $output;
}
if ( in_array( 'mobile-parent-nav-menu-item', $item->classes, true ) && isset( $item->original_id ) ) {
// Inject the keyboard_arrow_left SVG inside the parent nav menu item, and let the item link to the parent item.
// @todo Only do this for nested submenus? If on a first-level submenu, then really the link could be "#" since the desire is to remove the target entirely.
$link = sprintf(
'<button class="menu-item-link-return" tabindex="-1">%s',
twentynineteen_get_icon_svg( 'chevron_left', 24 )
);
// replace opening <a> with <button>
$output = preg_replace(
'/<a\s.*?>/',
$link,
$output,
1 // Limit.
);
// replace closing </a> with </button>
$output = preg_replace(
'#</a>#i',
'</button>',
$output,
1 // Limit.
);
} elseif ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
// Add SVG icon to parent items.
$icon = twentynineteen_get_icon_svg( 'keyboard_arrow_down', 24 );
$output .= sprintf(
'<button class="submenu-expand" tabindex="-1">%s</button>',
$icon
);
}
return $output;
}
add_filter( 'walker_nav_menu_start_el', 'twentynineteen_add_dropdown_icons', 10, 4 );
/**
* Create a nav menu item to be displayed on mobile to navigate from submenu back to the parent.
*
* This duplicates each parent nav menu item and makes it the first child of itself.
*
* @param array $sorted_menu_items Sorted nav menu items.
* @param object $args Nav menu args.
* @return array Amended nav menu items.
*/
function twentynineteen_add_mobile_parent_nav_menu_items( $sorted_menu_items, $args ) {
static $pseudo_id = 0;
if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) {
return $sorted_menu_items;
}
$amended_menu_items = array();
foreach ( $sorted_menu_items as $nav_menu_item ) {
$amended_menu_items[] = $nav_menu_item;
if ( in_array( 'menu-item-has-children', $nav_menu_item->classes, true ) ) {
$parent_menu_item = clone $nav_menu_item;
$parent_menu_item->original_id = $nav_menu_item->ID;
$parent_menu_item->ID = --$pseudo_id;
$parent_menu_item->db_id = $parent_menu_item->ID;
$parent_menu_item->object_id = $parent_menu_item->ID;
$parent_menu_item->classes = array( 'mobile-parent-nav-menu-item' );
$parent_menu_item->menu_item_parent = $nav_menu_item->ID;
$amended_menu_items[] = $parent_menu_item;
}
}
return $amended_menu_items;
}
add_filter( 'wp_nav_menu_objects', 'twentynineteen_add_mobile_parent_nav_menu_items', 10, 2 );
/**
* Convert HSL to HEX colors
*/
function twentynineteen_hsl_hex( $h, $s, $l, $to_hex = true ) {
$h /= 360;
$s /= 100;
$l /= 100;
$r = $l;
$g = $l;
$b = $l;
$v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s );
if ( $v > 0 ) {
$m;
$sv;
$sextant;
$fract;
$vsf;
$mid1;
$mid2;
$m = $l + $l - $v;
$sv = ( $v - $m ) / $v;
$h *= 6.0;
$sextant = floor( $h );
$fract = $h - $sextant;
$vsf = $v * $sv * $fract;
$mid1 = $m + $vsf;
$mid2 = $v - $vsf;
switch ( $sextant ) {
case 0:
$r = $v;
$g = $mid1;
$b = $m;
break;
case 1:
$r = $mid2;
$g = $v;
$b = $m;
break;
case 2:
$r = $m;
$g = $v;
$b = $mid1;
break;
case 3:
$r = $m;
$g = $mid2;
$b = $v;
break;
case 4:
$r = $mid1;
$g = $m;
$b = $v;
break;
case 5:
$r = $v;
$g = $m;
$b = $mid2;
break;
}
}
$r = round( $r * 255, 0 );
$g = round( $g * 255, 0 );
$b = round( $b * 255, 0 );
if ( $to_hex ) {
$r = ( $r < 15 ) ? '0' . dechex( $r ) : dechex( $r );
$g = ( $g < 15 ) ? '0' . dechex( $g ) : dechex( $g );
$b = ( $b < 15 ) ? '0' . dechex( $b ) : dechex( $b );
return "#$r$g$b";
}
return "rgb($r, $g, $b)";
}
home/xbodynamge/namtation/wp-content/themes/twentynineteen/inc/template-functions.php 0000604 00000030710 15114536253 0025373 0 ustar 00 <?php
/**
* Functions which enhance the theme by hooking into WordPress
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function twentynineteen_body_classes( $classes ) {
if ( is_singular() ) {
// Adds `singular` to singular pages.
$classes[] = 'singular';
} else {
// Adds `hfeed` to non singular pages.
$classes[] = 'hfeed';
}
// Adds a class if image filters are enabled.
if ( twentynineteen_image_filters_enabled() ) {
$classes[] = 'image-filters-enabled';
}
return $classes;
}
add_filter( 'body_class', 'twentynineteen_body_classes' );
/**
* Adds custom class to the array of posts classes.
*/
function twentynineteen_post_classes( $classes, $class, $post_id ) {
$classes[] = 'entry';
return $classes;
}
add_filter( 'post_class', 'twentynineteen_post_classes', 10, 3 );
/**
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
*/
function twentynineteen_pingback_header() {
if ( is_singular() && pings_open() ) {
echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
}
}
add_action( 'wp_head', 'twentynineteen_pingback_header' );
/**
* Changes comment form default fields.
*/
function twentynineteen_comment_form_defaults( $defaults ) {
$comment_field = $defaults['comment_field'];
// Adjust height of comment form.
$defaults['comment_field'] = preg_replace( '/rows="\d+"/', 'rows="5"', $comment_field );
return $defaults;
}
add_filter( 'comment_form_defaults', 'twentynineteen_comment_form_defaults' );
/**
* Filters the default archive titles.
*/
function twentynineteen_get_the_archive_title() {
if ( is_category() ) {
$title = __( 'Category Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
} elseif ( is_tag() ) {
$title = __( 'Tag Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
} elseif ( is_author() ) {
$title = __( 'Author Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_author_meta( 'display_name' ) . '</span>';
} elseif ( is_year() ) {
$title = __( 'Yearly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentynineteen' ) ) . '</span>';
} elseif ( is_month() ) {
$title = __( 'Monthly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentynineteen' ) ) . '</span>';
} elseif ( is_day() ) {
$title = __( 'Daily Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date() . '</span>';
} elseif ( is_post_type_archive() ) {
$title = __( 'Post Type Archives: ', 'twentynineteen' ) . '<span class="page-description">' . post_type_archive_title( '', false ) . '</span>';
} elseif ( is_tax() ) {
$tax = get_taxonomy( get_queried_object()->taxonomy );
/* translators: %s: Taxonomy singular name */
$title = sprintf( esc_html__( '%s Archives:', 'twentynineteen' ), $tax->labels->singular_name );
} else {
$title = __( 'Archives:', 'twentynineteen' );
}
return $title;
}
add_filter( 'get_the_archive_title', 'twentynineteen_get_the_archive_title' );
/**
* Determines if post thumbnail can be displayed.
*/
function twentynineteen_can_show_post_thumbnail() {
return apply_filters( 'twentynineteen_can_show_post_thumbnail', ! post_password_required() && ! is_attachment() && has_post_thumbnail() );
}
/**
* Returns true if image filters are enabled on the theme options.
*/
function twentynineteen_image_filters_enabled() {
return 0 !== get_theme_mod( 'image_filter', 1 );
}
/**
* Add custom sizes attribute to responsive image functionality for post thumbnails.
*
* @origin Twenty Nineteen 1.0
*
* @param array $attr Attributes for the image markup.
* @return string Value for use in post thumbnail 'sizes' attribute.
*/
function twentynineteen_post_thumbnail_sizes_attr( $attr ) {
if ( is_admin() ) {
return $attr;
}
if ( ! is_singular() ) {
$attr['sizes'] = '(max-width: 34.9rem) calc(100vw - 2rem), (max-width: 53rem) calc(8 * (100vw / 12)), (min-width: 53rem) calc(6 * (100vw / 12)), 100vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 );
/**
* Returns the size for avatars used in the theme.
*/
function twentynineteen_get_avatar_size() {
return 60;
}
/**
* Returns true if comment is by author of the post.
*
* @see get_comment_class()
*/
function twentynineteen_is_comment_by_post_author( $comment = null ) {
if ( is_object( $comment ) && $comment->user_id > 0 ) {
$user = get_userdata( $comment->user_id );
$post = get_post( $comment->comment_post_ID );
if ( ! empty( $user ) && ! empty( $post ) ) {
return $comment->user_id === $post->post_author;
}
}
return false;
}
/**
* Returns information about the current post's discussion, with cache support.
*/
function twentynineteen_get_discussion_data() {
static $discussion, $post_id;
$current_post_id = get_the_ID();
if ( $current_post_id === $post_id ) {
return $discussion; /* If we have discussion information for post ID, return cached object */
} else {
$post_id = $current_post_id;
}
$comments = get_comments(
array(
'post_id' => $current_post_id,
'orderby' => 'comment_date_gmt',
'order' => get_option( 'comment_order', 'asc' ), /* Respect comment order from Settings » Discussion. */
'status' => 'approve',
'number' => 20, /* Only retrieve the last 20 comments, as the end goal is just 6 unique authors */
)
);
$authors = array();
foreach ( $comments as $comment ) {
$authors[] = ( (int) $comment->user_id > 0 ) ? (int) $comment->user_id : $comment->comment_author_email;
}
$authors = array_unique( $authors );
$discussion = (object) array(
'authors' => array_slice( $authors, 0, 6 ), /* Six unique authors commenting on the post. */
'responses' => get_comments_number( $current_post_id ), /* Number of responses. */
);
return $discussion;
}
/**
* Add an extra menu to our nav for our priority+ navigation to use
*
* @param object $nav_menu Nav menu.
* @param object $args Nav menu args.
* @return string More link for hidden menu items.
*/
function twentynineteen_add_ellipses_to_nav( $nav_menu, $args ) {
if ( 'menu-1' === $args->theme_location ) :
$nav_menu .= '<div class="main-menu-more">';
$nav_menu .= '<ul class="main-menu">';
$nav_menu .= '<li class="menu-item menu-item-has-children">';
$nav_menu .= '<button class="submenu-expand main-menu-more-toggle is-empty" tabindex="-1" aria-label="More" aria-haspopup="true" aria-expanded="false">';
$nav_menu .= '<span class="screen-reader-text">' . esc_html__( 'More', 'twentynineteen' ) . '</span>';
$nav_menu .= twentynineteen_get_icon_svg( 'arrow_drop_down_ellipsis' );
$nav_menu .= '</button>';
$nav_menu .= '<ul class="sub-menu hidden-links">';
$nav_menu .= '<li id="menu-item--1" class="mobile-parent-nav-menu-item menu-item--1">';
$nav_menu .= '<button class="menu-item-link-return">';
$nav_menu .= twentynineteen_get_icon_svg( 'chevron_left' );
$nav_menu .= esc_html__( 'Back', 'twentynineteen' );
$nav_menu .= '</button>';
$nav_menu .= '</li>';
$nav_menu .= '</ul>';
$nav_menu .= '</li>';
$nav_menu .= '</ul>';
$nav_menu .= '</div>';
endif;
return $nav_menu;
}
add_filter( 'wp_nav_menu', 'twentynineteen_add_ellipses_to_nav', 10, 2 );
/**
* WCAG 2.0 Attributes for Dropdown Menus
*
* Adjustments to menu attributes tot support WCAG 2.0 recommendations
* for flyout and dropdown menus.
*
* @ref https://www.w3.org/WAI/tutorials/menus/flyout/
*/
function twentynineteen_nav_menu_link_attributes( $atts, $item, $args, $depth ) {
// Add [aria-haspopup] and [aria-expanded] to menu items that have children
$item_has_children = in_array( 'menu-item-has-children', $item->classes );
if ( $item_has_children ) {
$atts['aria-haspopup'] = 'true';
$atts['aria-expanded'] = 'false';
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'twentynineteen_nav_menu_link_attributes', 10, 4 );
/**
* Add a dropdown icon to top-level menu items.
*
* @param string $output Nav menu item start element.
* @param object $item Nav menu item.
* @param int $depth Depth.
* @param object $args Nav menu args.
* @return string Nav menu item start element.
* Add a dropdown icon to top-level menu items
*/
function twentynineteen_add_dropdown_icons( $output, $item, $depth, $args ) {
// Only add class to 'top level' items on the 'primary' menu.
if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) {
return $output;
}
if ( in_array( 'mobile-parent-nav-menu-item', $item->classes, true ) && isset( $item->original_id ) ) {
// Inject the keyboard_arrow_left SVG inside the parent nav menu item, and let the item link to the parent item.
// @todo Only do this for nested submenus? If on a first-level submenu, then really the link could be "#" since the desire is to remove the target entirely.
$link = sprintf(
'<button class="menu-item-link-return" tabindex="-1">%s',
twentynineteen_get_icon_svg( 'chevron_left', 24 )
);
// replace opening <a> with <button>
$output = preg_replace(
'/<a\s.*?>/',
$link,
$output,
1 // Limit.
);
// replace closing </a> with </button>
$output = preg_replace(
'#</a>#i',
'</button>',
$output,
1 // Limit.
);
} elseif ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
// Add SVG icon to parent items.
$icon = twentynineteen_get_icon_svg( 'keyboard_arrow_down', 24 );
$output .= sprintf(
'<button class="submenu-expand" tabindex="-1">%s</button>',
$icon
);
}
return $output;
}
add_filter( 'walker_nav_menu_start_el', 'twentynineteen_add_dropdown_icons', 10, 4 );
/**
* Create a nav menu item to be displayed on mobile to navigate from submenu back to the parent.
*
* This duplicates each parent nav menu item and makes it the first child of itself.
*
* @param array $sorted_menu_items Sorted nav menu items.
* @param object $args Nav menu args.
* @return array Amended nav menu items.
*/
function twentynineteen_add_mobile_parent_nav_menu_items( $sorted_menu_items, $args ) {
static $pseudo_id = 0;
if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) {
return $sorted_menu_items;
}
$amended_menu_items = array();
foreach ( $sorted_menu_items as $nav_menu_item ) {
$amended_menu_items[] = $nav_menu_item;
if ( in_array( 'menu-item-has-children', $nav_menu_item->classes, true ) ) {
$parent_menu_item = clone $nav_menu_item;
$parent_menu_item->original_id = $nav_menu_item->ID;
$parent_menu_item->ID = --$pseudo_id;
$parent_menu_item->db_id = $parent_menu_item->ID;
$parent_menu_item->object_id = $parent_menu_item->ID;
$parent_menu_item->classes = array( 'mobile-parent-nav-menu-item' );
$parent_menu_item->menu_item_parent = $nav_menu_item->ID;
$amended_menu_items[] = $parent_menu_item;
}
}
return $amended_menu_items;
}
add_filter( 'wp_nav_menu_objects', 'twentynineteen_add_mobile_parent_nav_menu_items', 10, 2 );
/**
* Convert HSL to HEX colors
*/
function twentynineteen_hsl_hex( $h, $s, $l, $to_hex = true ) {
$h /= 360;
$s /= 100;
$l /= 100;
$r = $l;
$g = $l;
$b = $l;
$v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s );
if ( $v > 0 ) {
$m;
$sv;
$sextant;
$fract;
$vsf;
$mid1;
$mid2;
$m = $l + $l - $v;
$sv = ( $v - $m ) / $v;
$h *= 6.0;
$sextant = floor( $h );
$fract = $h - $sextant;
$vsf = $v * $sv * $fract;
$mid1 = $m + $vsf;
$mid2 = $v - $vsf;
switch ( $sextant ) {
case 0:
$r = $v;
$g = $mid1;
$b = $m;
break;
case 1:
$r = $mid2;
$g = $v;
$b = $m;
break;
case 2:
$r = $m;
$g = $v;
$b = $mid1;
break;
case 3:
$r = $m;
$g = $mid2;
$b = $v;
break;
case 4:
$r = $mid1;
$g = $m;
$b = $v;
break;
case 5:
$r = $v;
$g = $m;
$b = $mid2;
break;
}
}
$r = round( $r * 255, 0 );
$g = round( $g * 255, 0 );
$b = round( $b * 255, 0 );
if ( $to_hex ) {
$r = ( $r < 15 ) ? '0' . dechex( $r ) : dechex( $r );
$g = ( $g < 15 ) ? '0' . dechex( $g ) : dechex( $g );
$b = ( $b < 15 ) ? '0' . dechex( $b ) : dechex( $b );
return "#$r$g$b";
}
return "rgb($r, $g, $b)";
}
home/xbodynamge/dev/wp-content/themes/twentyseventeen/inc/template-functions.php 0000604 00000004774 15114544225 0024357 0 ustar 00 <?php
/**
* Additional features to allow styling of the templates
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function twentyseventeen_body_classes( $classes ) {
// Add class of group-blog to blogs with more than 1 published author.
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
// Add class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
// Add class if we're viewing the Customizer for easier styling of theme options.
if ( is_customize_preview() ) {
$classes[] = 'twentyseventeen-customizer';
}
// Add class on front page.
if ( is_front_page() && 'posts' !== get_option( 'show_on_front' ) ) {
$classes[] = 'twentyseventeen-front-page';
}
// Add a class if there is a custom header.
if ( has_header_image() ) {
$classes[] = 'has-header-image';
}
// Add class if sidebar is used.
if ( is_active_sidebar( 'sidebar-1' ) && ! is_page() ) {
$classes[] = 'has-sidebar';
}
// Add class for one or two column page layouts.
if ( is_page() || is_archive() ) {
if ( 'one-column' === get_theme_mod( 'page_layout' ) ) {
$classes[] = 'page-one-column';
} else {
$classes[] = 'page-two-column';
}
}
// Add class if the site title and tagline is hidden.
if ( 'blank' === get_header_textcolor() ) {
$classes[] = 'title-tagline-hidden';
}
// Get the colorscheme or the default if there isn't one.
$colors = twentyseventeen_sanitize_colorscheme( get_theme_mod( 'colorscheme', 'light' ) );
$classes[] = 'colors-' . $colors;
return $classes;
}
add_filter( 'body_class', 'twentyseventeen_body_classes' );
/**
* Count our number of active panels.
*
* Primarily used to see if we have any panels active, duh.
*/
function twentyseventeen_panel_count() {
$panel_count = 0;
/**
* Filter number of front page sections in Twenty Seventeen.
*
* @since Twenty Seventeen 1.0
*
* @param int $num_sections Number of front page sections.
*/
$num_sections = apply_filters( 'twentyseventeen_front_page_sections', 4 );
// Create a setting and control for each of the sections available in the theme.
for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) {
if ( get_theme_mod( 'panel_' . $i ) ) {
$panel_count++;
}
}
return $panel_count;
}
/**
* Checks to see if we're on the homepage or not.
*/
function twentyseventeen_is_frontpage() {
return ( is_front_page() && ! is_home() );
}
home/xbodynamge/crosstraining/wp-content/themes/twentynineteen/inc/template-functions.php 0000604 00000030650 15114644700 0026266 0 ustar 00 <?php
/**
* Functions which enhance the theme by hooking into WordPress
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function twentynineteen_body_classes( $classes ) {
if ( is_singular() ) {
// Adds `singular` to singular pages.
$classes[] = 'singular';
} else {
// Adds `hfeed` to non singular pages.
$classes[] = 'hfeed';
}
// Adds a class if image filters are enabled.
if ( twentynineteen_image_filters_enabled() ) {
$classes[] = 'image-filters-enabled';
}
return $classes;
}
add_filter( 'body_class', 'twentynineteen_body_classes' );
/**
* Adds custom class to the array of posts classes.
*/
function twentynineteen_post_classes( $classes, $class, $post_id ) {
$classes[] = 'entry';
return $classes;
}
add_filter( 'post_class', 'twentynineteen_post_classes', 10, 3 );
/**
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
*/
function twentynineteen_pingback_header() {
if ( is_singular() && pings_open() ) {
echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
}
}
add_action( 'wp_head', 'twentynineteen_pingback_header' );
/**
* Changes comment form default fields.
*/
function twentynineteen_comment_form_defaults( $defaults ) {
$comment_field = $defaults['comment_field'];
// Adjust height of comment form.
$defaults['comment_field'] = preg_replace( '/rows="\d+"/', 'rows="5"', $comment_field );
return $defaults;
}
add_filter( 'comment_form_defaults', 'twentynineteen_comment_form_defaults' );
/**
* Filters the default archive titles.
*/
function twentynineteen_get_the_archive_title() {
if ( is_category() ) {
$title = __( 'Category Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
} elseif ( is_tag() ) {
$title = __( 'Tag Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
} elseif ( is_author() ) {
$title = __( 'Author Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_author_meta( 'display_name' ) . '</span>';
} elseif ( is_year() ) {
$title = __( 'Yearly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentynineteen' ) ) . '</span>';
} elseif ( is_month() ) {
$title = __( 'Monthly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentynineteen' ) ) . '</span>';
} elseif ( is_day() ) {
$title = __( 'Daily Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date() . '</span>';
} elseif ( is_post_type_archive() ) {
$title = __( 'Post Type Archives: ', 'twentynineteen' ) . '<span class="page-description">' . post_type_archive_title( '', false ) . '</span>';
} elseif ( is_tax() ) {
$tax = get_taxonomy( get_queried_object()->taxonomy );
/* translators: %s: Taxonomy singular name */
$title = sprintf( esc_html__( '%s Archives:', 'twentynineteen' ), $tax->labels->singular_name );
} else {
$title = __( 'Archives:', 'twentynineteen' );
}
return $title;
}
add_filter( 'get_the_archive_title', 'twentynineteen_get_the_archive_title' );
/**
* Determines if post thumbnail can be displayed.
*/
function twentynineteen_can_show_post_thumbnail() {
return apply_filters( 'twentynineteen_can_show_post_thumbnail', ! post_password_required() && ! is_attachment() && has_post_thumbnail() );
}
/**
* Returns true if image filters are enabled on the theme options.
*/
function twentynineteen_image_filters_enabled() {
return 0 !== get_theme_mod( 'image_filter', 1 );
}
/**
* Add custom sizes attribute to responsive image functionality for post thumbnails.
*
* @origin Twenty Nineteen 1.0
*
* @param array $attr Attributes for the image markup.
* @return string Value for use in post thumbnail 'sizes' attribute.
*/
function twentynineteen_post_thumbnail_sizes_attr( $attr ) {
if ( is_admin() ) {
return $attr;
}
if ( ! is_singular() ) {
$attr['sizes'] = '(max-width: 34.9rem) calc(100vw - 2rem), (max-width: 53rem) calc(8 * (100vw / 12)), (min-width: 53rem) calc(6 * (100vw / 12)), 100vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 );
/**
* Returns the size for avatars used in the theme.
*/
function twentynineteen_get_avatar_size() {
return 60;
}
/**
* Returns true if comment is by author of the post.
*
* @see get_comment_class()
*/
function twentynineteen_is_comment_by_post_author( $comment = null ) {
if ( is_object( $comment ) && $comment->user_id > 0 ) {
$user = get_userdata( $comment->user_id );
$post = get_post( $comment->comment_post_ID );
if ( ! empty( $user ) && ! empty( $post ) ) {
return $comment->user_id === $post->post_author;
}
}
return false;
}
/**
* Returns information about the current post's discussion, with cache support.
*/
function twentynineteen_get_discussion_data() {
static $discussion, $post_id;
$current_post_id = get_the_ID();
if ( $current_post_id === $post_id ) {
return $discussion; /* If we have discussion information for post ID, return cached object */
} else {
$post_id = $current_post_id;
}
$comments = get_comments(
array(
'post_id' => $current_post_id,
'orderby' => 'comment_date_gmt',
'order' => get_option( 'comment_order', 'asc' ), /* Respect comment order from Settings » Discussion. */
'status' => 'approve',
'number' => 20, /* Only retrieve the last 20 comments, as the end goal is just 6 unique authors */
)
);
$authors = array();
foreach ( $comments as $comment ) {
$authors[] = ( (int) $comment->user_id > 0 ) ? (int) $comment->user_id : $comment->comment_author_email;
}
$authors = array_unique( $authors );
$discussion = (object) array(
'authors' => array_slice( $authors, 0, 6 ), /* Six unique authors commenting on the post. */
'responses' => get_comments_number( $current_post_id ), /* Number of responses. */
);
return $discussion;
}
/**
* Add an extra menu to our nav for our priority+ navigation to use
*
* @param object $nav_menu Nav menu.
* @param object $args Nav menu args.
* @return string More link for hidden menu items.
*/
function twentynineteen_add_ellipses_to_nav( $nav_menu, $args ) {
if ( 'menu-1' === $args->theme_location ) :
$nav_menu .= '<div class="main-menu-more">';
$nav_menu .= '<ul class="main-menu" tabindex="0">';
$nav_menu .= '<li class="menu-item menu-item-has-children">';
$nav_menu .= '<a href="#" class="screen-reader-text" aria-label="More" aria-haspopup="true" aria-expanded="false">' . esc_html__( 'More', 'twentynineteen' ) . '</a>';
$nav_menu .= '<span class="submenu-expand main-menu-more-toggle is-empty" tabindex="-1">';
$nav_menu .= twentynineteen_get_icon_svg( 'arrow_drop_down_ellipsis' );
$nav_menu .= '</span>';
$nav_menu .= '<ul class="sub-menu hidden-links">';
$nav_menu .= '<li id="menu-item--1" class="mobile-parent-nav-menu-item menu-item--1">';
$nav_menu .= '<span class="menu-item-link-return">';
$nav_menu .= twentynineteen_get_icon_svg( 'chevron_left' );
$nav_menu .= esc_html__( 'Back', 'twentynineteen' );
$nav_menu .= '</span>';
$nav_menu .= '</li>';
$nav_menu .= '</ul>';
$nav_menu .= '</li>';
$nav_menu .= '</ul>';
$nav_menu .= '</div>';
endif;
return $nav_menu;
}
add_filter( 'wp_nav_menu', 'twentynineteen_add_ellipses_to_nav', 10, 2 );
/**
* WCAG 2.0 Attributes for Dropdown Menus
*
* Adjustments to menu attributes tot support WCAG 2.0 recommendations
* for flyout and dropdown menus.
*
* @ref https://www.w3.org/WAI/tutorials/menus/flyout/
*/
function twentynineteen_nav_menu_link_attributes( $atts, $item, $args, $depth ) {
// Add [aria-haspopup] and [aria-expanded] to menu items that have children
$item_has_children = in_array( 'menu-item-has-children', $item->classes );
if ( $item_has_children ) {
$atts['aria-haspopup'] = 'true';
$atts['aria-expanded'] = 'false';
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'twentynineteen_nav_menu_link_attributes', 10, 4 );
/**
* Add a dropdown icon to top-level menu items.
*
* @param string $output Nav menu item start element.
* @param object $item Nav menu item.
* @param int $depth Depth.
* @param object $args Nav menu args.
* @return string Nav menu item start element.
* Add a dropdown icon to top-level menu items
*/
function twentynineteen_add_dropdown_icons( $output, $item, $depth, $args ) {
// Only add class to 'top level' items on the 'primary' menu.
if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) {
return $output;
}
if ( in_array( 'mobile-parent-nav-menu-item', $item->classes, true ) && isset( $item->original_id ) ) {
// Inject the keyboard_arrow_left SVG inside the parent nav menu item, and let the item link to the parent item.
// @todo Only do this for nested submenus? If on a first-level submenu, then really the link could be "#" since the desire is to remove the target entirely.
$link = sprintf(
'<span class="menu-item-link-return" tabindex="-1">%s',
twentynineteen_get_icon_svg( 'chevron_left', 24 )
);
// replace opening <a> with <span>
$output = preg_replace(
'/<a\s.*?>/',
$link,
$output,
1 // Limit.
);
// replace closing </a> with </span>
$output = preg_replace(
'#</a>#i',
'</span>',
$output,
1 // Limit.
);
} elseif ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
// Add SVG icon to parent items.
$icon = twentynineteen_get_icon_svg( 'keyboard_arrow_down', 24 );
$output .= sprintf(
'<span class="submenu-expand" tabindex="-1">%s</span>',
$icon
);
}
return $output;
}
add_filter( 'walker_nav_menu_start_el', 'twentynineteen_add_dropdown_icons', 10, 4 );
/**
* Create a nav menu item to be displayed on mobile to navigate from submenu back to the parent.
*
* This duplicates each parent nav menu item and makes it the first child of itself.
*
* @param array $sorted_menu_items Sorted nav menu items.
* @param object $args Nav menu args.
* @return array Amended nav menu items.
*/
function twentynineteen_add_mobile_parent_nav_menu_items( $sorted_menu_items, $args ) {
static $pseudo_id = 0;
if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) {
return $sorted_menu_items;
}
$amended_menu_items = array();
foreach ( $sorted_menu_items as $nav_menu_item ) {
$amended_menu_items[] = $nav_menu_item;
if ( in_array( 'menu-item-has-children', $nav_menu_item->classes, true ) ) {
$parent_menu_item = clone $nav_menu_item;
$parent_menu_item->original_id = $nav_menu_item->ID;
$parent_menu_item->ID = --$pseudo_id;
$parent_menu_item->db_id = $parent_menu_item->ID;
$parent_menu_item->object_id = $parent_menu_item->ID;
$parent_menu_item->classes = array( 'mobile-parent-nav-menu-item' );
$parent_menu_item->menu_item_parent = $nav_menu_item->ID;
$amended_menu_items[] = $parent_menu_item;
}
}
return $amended_menu_items;
}
add_filter( 'wp_nav_menu_objects', 'twentynineteen_add_mobile_parent_nav_menu_items', 10, 2 );
/**
* Convert HSL to HEX colors
*/
function twentynineteen_hsl_hex( $h, $s, $l, $to_hex = true ) {
$h /= 360;
$s /= 100;
$l /= 100;
$r = $l;
$g = $l;
$b = $l;
$v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s );
if ( $v > 0 ) {
$m;
$sv;
$sextant;
$fract;
$vsf;
$mid1;
$mid2;
$m = $l + $l - $v;
$sv = ( $v - $m ) / $v;
$h *= 6.0;
$sextant = floor( $h );
$fract = $h - $sextant;
$vsf = $v * $sv * $fract;
$mid1 = $m + $vsf;
$mid2 = $v - $vsf;
switch ( $sextant ) {
case 0:
$r = $v;
$g = $mid1;
$b = $m;
break;
case 1:
$r = $mid2;
$g = $v;
$b = $m;
break;
case 2:
$r = $m;
$g = $v;
$b = $mid1;
break;
case 3:
$r = $m;
$g = $mid2;
$b = $v;
break;
case 4:
$r = $mid1;
$g = $m;
$b = $v;
break;
case 5:
$r = $v;
$g = $m;
$b = $mid2;
break;
}
}
$r = round( $r * 255, 0 );
$g = round( $g * 255, 0 );
$b = round( $b * 255, 0 );
if ( $to_hex ) {
$r = ( $r < 15 ) ? '0' . dechex( $r ) : dechex( $r );
$g = ( $g < 15 ) ? '0' . dechex( $g ) : dechex( $g );
$b = ( $b < 15 ) ? '0' . dechex( $b ) : dechex( $b );
return "#$r$g$b";
}
return "rgb($r, $g, $b)";
}
home/xbodynamge/www/wp-content/themes/twentynineteen/inc/template-functions.php 0000644 00000030650 15114673375 0024243 0 ustar 00 <?php
/**
* Functions which enhance the theme by hooking into WordPress
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function twentynineteen_body_classes( $classes ) {
if ( is_singular() ) {
// Adds `singular` to singular pages.
$classes[] = 'singular';
} else {
// Adds `hfeed` to non singular pages.
$classes[] = 'hfeed';
}
// Adds a class if image filters are enabled.
if ( twentynineteen_image_filters_enabled() ) {
$classes[] = 'image-filters-enabled';
}
return $classes;
}
add_filter( 'body_class', 'twentynineteen_body_classes' );
/**
* Adds custom class to the array of posts classes.
*/
function twentynineteen_post_classes( $classes, $class, $post_id ) {
$classes[] = 'entry';
return $classes;
}
add_filter( 'post_class', 'twentynineteen_post_classes', 10, 3 );
/**
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
*/
function twentynineteen_pingback_header() {
if ( is_singular() && pings_open() ) {
echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
}
}
add_action( 'wp_head', 'twentynineteen_pingback_header' );
/**
* Changes comment form default fields.
*/
function twentynineteen_comment_form_defaults( $defaults ) {
$comment_field = $defaults['comment_field'];
// Adjust height of comment form.
$defaults['comment_field'] = preg_replace( '/rows="\d+"/', 'rows="5"', $comment_field );
return $defaults;
}
add_filter( 'comment_form_defaults', 'twentynineteen_comment_form_defaults' );
/**
* Filters the default archive titles.
*/
function twentynineteen_get_the_archive_title() {
if ( is_category() ) {
$title = __( 'Category Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
} elseif ( is_tag() ) {
$title = __( 'Tag Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
} elseif ( is_author() ) {
$title = __( 'Author Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_author_meta( 'display_name' ) . '</span>';
} elseif ( is_year() ) {
$title = __( 'Yearly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentynineteen' ) ) . '</span>';
} elseif ( is_month() ) {
$title = __( 'Monthly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentynineteen' ) ) . '</span>';
} elseif ( is_day() ) {
$title = __( 'Daily Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date() . '</span>';
} elseif ( is_post_type_archive() ) {
$title = __( 'Post Type Archives: ', 'twentynineteen' ) . '<span class="page-description">' . post_type_archive_title( '', false ) . '</span>';
} elseif ( is_tax() ) {
$tax = get_taxonomy( get_queried_object()->taxonomy );
/* translators: %s: Taxonomy singular name */
$title = sprintf( esc_html__( '%s Archives:', 'twentynineteen' ), $tax->labels->singular_name );
} else {
$title = __( 'Archives:', 'twentynineteen' );
}
return $title;
}
add_filter( 'get_the_archive_title', 'twentynineteen_get_the_archive_title' );
/**
* Determines if post thumbnail can be displayed.
*/
function twentynineteen_can_show_post_thumbnail() {
return apply_filters( 'twentynineteen_can_show_post_thumbnail', ! post_password_required() && ! is_attachment() && has_post_thumbnail() );
}
/**
* Returns true if image filters are enabled on the theme options.
*/
function twentynineteen_image_filters_enabled() {
return 0 !== get_theme_mod( 'image_filter', 1 );
}
/**
* Add custom sizes attribute to responsive image functionality for post thumbnails.
*
* @origin Twenty Nineteen 1.0
*
* @param array $attr Attributes for the image markup.
* @return string Value for use in post thumbnail 'sizes' attribute.
*/
function twentynineteen_post_thumbnail_sizes_attr( $attr ) {
if ( is_admin() ) {
return $attr;
}
if ( ! is_singular() ) {
$attr['sizes'] = '(max-width: 34.9rem) calc(100vw - 2rem), (max-width: 53rem) calc(8 * (100vw / 12)), (min-width: 53rem) calc(6 * (100vw / 12)), 100vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 );
/**
* Returns the size for avatars used in the theme.
*/
function twentynineteen_get_avatar_size() {
return 60;
}
/**
* Returns true if comment is by author of the post.
*
* @see get_comment_class()
*/
function twentynineteen_is_comment_by_post_author( $comment = null ) {
if ( is_object( $comment ) && $comment->user_id > 0 ) {
$user = get_userdata( $comment->user_id );
$post = get_post( $comment->comment_post_ID );
if ( ! empty( $user ) && ! empty( $post ) ) {
return $comment->user_id === $post->post_author;
}
}
return false;
}
/**
* Returns information about the current post's discussion, with cache support.
*/
function twentynineteen_get_discussion_data() {
static $discussion, $post_id;
$current_post_id = get_the_ID();
if ( $current_post_id === $post_id ) {
return $discussion; /* If we have discussion information for post ID, return cached object */
} else {
$post_id = $current_post_id;
}
$comments = get_comments(
array(
'post_id' => $current_post_id,
'orderby' => 'comment_date_gmt',
'order' => get_option( 'comment_order', 'asc' ), /* Respect comment order from Settings » Discussion. */
'status' => 'approve',
'number' => 20, /* Only retrieve the last 20 comments, as the end goal is just 6 unique authors */
)
);
$authors = array();
foreach ( $comments as $comment ) {
$authors[] = ( (int) $comment->user_id > 0 ) ? (int) $comment->user_id : $comment->comment_author_email;
}
$authors = array_unique( $authors );
$discussion = (object) array(
'authors' => array_slice( $authors, 0, 6 ), /* Six unique authors commenting on the post. */
'responses' => get_comments_number( $current_post_id ), /* Number of responses. */
);
return $discussion;
}
/**
* Add an extra menu to our nav for our priority+ navigation to use
*
* @param object $nav_menu Nav menu.
* @param object $args Nav menu args.
* @return string More link for hidden menu items.
*/
function twentynineteen_add_ellipses_to_nav( $nav_menu, $args ) {
if ( 'menu-1' === $args->theme_location ) :
$nav_menu .= '<div class="main-menu-more">';
$nav_menu .= '<ul class="main-menu" tabindex="0">';
$nav_menu .= '<li class="menu-item menu-item-has-children">';
$nav_menu .= '<a href="#" class="screen-reader-text" aria-label="More" aria-haspopup="true" aria-expanded="false">' . esc_html__( 'More', 'twentynineteen' ) . '</a>';
$nav_menu .= '<span class="submenu-expand main-menu-more-toggle is-empty" tabindex="-1">';
$nav_menu .= twentynineteen_get_icon_svg( 'arrow_drop_down_ellipsis' );
$nav_menu .= '</span>';
$nav_menu .= '<ul class="sub-menu hidden-links">';
$nav_menu .= '<li id="menu-item--1" class="mobile-parent-nav-menu-item menu-item--1">';
$nav_menu .= '<span class="menu-item-link-return">';
$nav_menu .= twentynineteen_get_icon_svg( 'chevron_left' );
$nav_menu .= esc_html__( 'Back', 'twentynineteen' );
$nav_menu .= '</span>';
$nav_menu .= '</li>';
$nav_menu .= '</ul>';
$nav_menu .= '</li>';
$nav_menu .= '</ul>';
$nav_menu .= '</div>';
endif;
return $nav_menu;
}
add_filter( 'wp_nav_menu', 'twentynineteen_add_ellipses_to_nav', 10, 2 );
/**
* WCAG 2.0 Attributes for Dropdown Menus
*
* Adjustments to menu attributes tot support WCAG 2.0 recommendations
* for flyout and dropdown menus.
*
* @ref https://www.w3.org/WAI/tutorials/menus/flyout/
*/
function twentynineteen_nav_menu_link_attributes( $atts, $item, $args, $depth ) {
// Add [aria-haspopup] and [aria-expanded] to menu items that have children
$item_has_children = in_array( 'menu-item-has-children', $item->classes );
if ( $item_has_children ) {
$atts['aria-haspopup'] = 'true';
$atts['aria-expanded'] = 'false';
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'twentynineteen_nav_menu_link_attributes', 10, 4 );
/**
* Add a dropdown icon to top-level menu items.
*
* @param string $output Nav menu item start element.
* @param object $item Nav menu item.
* @param int $depth Depth.
* @param object $args Nav menu args.
* @return string Nav menu item start element.
* Add a dropdown icon to top-level menu items
*/
function twentynineteen_add_dropdown_icons( $output, $item, $depth, $args ) {
// Only add class to 'top level' items on the 'primary' menu.
if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) {
return $output;
}
if ( in_array( 'mobile-parent-nav-menu-item', $item->classes, true ) && isset( $item->original_id ) ) {
// Inject the keyboard_arrow_left SVG inside the parent nav menu item, and let the item link to the parent item.
// @todo Only do this for nested submenus? If on a first-level submenu, then really the link could be "#" since the desire is to remove the target entirely.
$link = sprintf(
'<span class="menu-item-link-return" tabindex="-1">%s',
twentynineteen_get_icon_svg( 'chevron_left', 24 )
);
// replace opening <a> with <span>
$output = preg_replace(
'/<a\s.*?>/',
$link,
$output,
1 // Limit.
);
// replace closing </a> with </span>
$output = preg_replace(
'#</a>#i',
'</span>',
$output,
1 // Limit.
);
} elseif ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
// Add SVG icon to parent items.
$icon = twentynineteen_get_icon_svg( 'keyboard_arrow_down', 24 );
$output .= sprintf(
'<span class="submenu-expand" tabindex="-1">%s</span>',
$icon
);
}
return $output;
}
add_filter( 'walker_nav_menu_start_el', 'twentynineteen_add_dropdown_icons', 10, 4 );
/**
* Create a nav menu item to be displayed on mobile to navigate from submenu back to the parent.
*
* This duplicates each parent nav menu item and makes it the first child of itself.
*
* @param array $sorted_menu_items Sorted nav menu items.
* @param object $args Nav menu args.
* @return array Amended nav menu items.
*/
function twentynineteen_add_mobile_parent_nav_menu_items( $sorted_menu_items, $args ) {
static $pseudo_id = 0;
if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) {
return $sorted_menu_items;
}
$amended_menu_items = array();
foreach ( $sorted_menu_items as $nav_menu_item ) {
$amended_menu_items[] = $nav_menu_item;
if ( in_array( 'menu-item-has-children', $nav_menu_item->classes, true ) ) {
$parent_menu_item = clone $nav_menu_item;
$parent_menu_item->original_id = $nav_menu_item->ID;
$parent_menu_item->ID = --$pseudo_id;
$parent_menu_item->db_id = $parent_menu_item->ID;
$parent_menu_item->object_id = $parent_menu_item->ID;
$parent_menu_item->classes = array( 'mobile-parent-nav-menu-item' );
$parent_menu_item->menu_item_parent = $nav_menu_item->ID;
$amended_menu_items[] = $parent_menu_item;
}
}
return $amended_menu_items;
}
add_filter( 'wp_nav_menu_objects', 'twentynineteen_add_mobile_parent_nav_menu_items', 10, 2 );
/**
* Convert HSL to HEX colors
*/
function twentynineteen_hsl_hex( $h, $s, $l, $to_hex = true ) {
$h /= 360;
$s /= 100;
$l /= 100;
$r = $l;
$g = $l;
$b = $l;
$v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s );
if ( $v > 0 ) {
$m;
$sv;
$sextant;
$fract;
$vsf;
$mid1;
$mid2;
$m = $l + $l - $v;
$sv = ( $v - $m ) / $v;
$h *= 6.0;
$sextant = floor( $h );
$fract = $h - $sextant;
$vsf = $v * $sv * $fract;
$mid1 = $m + $vsf;
$mid2 = $v - $vsf;
switch ( $sextant ) {
case 0:
$r = $v;
$g = $mid1;
$b = $m;
break;
case 1:
$r = $mid2;
$g = $v;
$b = $m;
break;
case 2:
$r = $m;
$g = $v;
$b = $mid1;
break;
case 3:
$r = $m;
$g = $mid2;
$b = $v;
break;
case 4:
$r = $mid1;
$g = $m;
$b = $v;
break;
case 5:
$r = $v;
$g = $m;
$b = $mid2;
break;
}
}
$r = round( $r * 255, 0 );
$g = round( $g * 255, 0 );
$b = round( $b * 255, 0 );
if ( $to_hex ) {
$r = ( $r < 15 ) ? '0' . dechex( $r ) : dechex( $r );
$g = ( $g < 15 ) ? '0' . dechex( $g ) : dechex( $g );
$b = ( $b < 15 ) ? '0' . dechex( $b ) : dechex( $b );
return "#$r$g$b";
}
return "rgb($r, $g, $b)";
}
home/xbodynamge/dev/wp-content/themes/twentynineteen/inc/template-functions.php 0000604 00000030650 15114677401 0024163 0 ustar 00 <?php
/**
* Functions which enhance the theme by hooking into WordPress
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function twentynineteen_body_classes( $classes ) {
if ( is_singular() ) {
// Adds `singular` to singular pages.
$classes[] = 'singular';
} else {
// Adds `hfeed` to non singular pages.
$classes[] = 'hfeed';
}
// Adds a class if image filters are enabled.
if ( twentynineteen_image_filters_enabled() ) {
$classes[] = 'image-filters-enabled';
}
return $classes;
}
add_filter( 'body_class', 'twentynineteen_body_classes' );
/**
* Adds custom class to the array of posts classes.
*/
function twentynineteen_post_classes( $classes, $class, $post_id ) {
$classes[] = 'entry';
return $classes;
}
add_filter( 'post_class', 'twentynineteen_post_classes', 10, 3 );
/**
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
*/
function twentynineteen_pingback_header() {
if ( is_singular() && pings_open() ) {
echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
}
}
add_action( 'wp_head', 'twentynineteen_pingback_header' );
/**
* Changes comment form default fields.
*/
function twentynineteen_comment_form_defaults( $defaults ) {
$comment_field = $defaults['comment_field'];
// Adjust height of comment form.
$defaults['comment_field'] = preg_replace( '/rows="\d+"/', 'rows="5"', $comment_field );
return $defaults;
}
add_filter( 'comment_form_defaults', 'twentynineteen_comment_form_defaults' );
/**
* Filters the default archive titles.
*/
function twentynineteen_get_the_archive_title() {
if ( is_category() ) {
$title = __( 'Category Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
} elseif ( is_tag() ) {
$title = __( 'Tag Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
} elseif ( is_author() ) {
$title = __( 'Author Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_author_meta( 'display_name' ) . '</span>';
} elseif ( is_year() ) {
$title = __( 'Yearly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentynineteen' ) ) . '</span>';
} elseif ( is_month() ) {
$title = __( 'Monthly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentynineteen' ) ) . '</span>';
} elseif ( is_day() ) {
$title = __( 'Daily Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date() . '</span>';
} elseif ( is_post_type_archive() ) {
$title = __( 'Post Type Archives: ', 'twentynineteen' ) . '<span class="page-description">' . post_type_archive_title( '', false ) . '</span>';
} elseif ( is_tax() ) {
$tax = get_taxonomy( get_queried_object()->taxonomy );
/* translators: %s: Taxonomy singular name */
$title = sprintf( esc_html__( '%s Archives:', 'twentynineteen' ), $tax->labels->singular_name );
} else {
$title = __( 'Archives:', 'twentynineteen' );
}
return $title;
}
add_filter( 'get_the_archive_title', 'twentynineteen_get_the_archive_title' );
/**
* Determines if post thumbnail can be displayed.
*/
function twentynineteen_can_show_post_thumbnail() {
return apply_filters( 'twentynineteen_can_show_post_thumbnail', ! post_password_required() && ! is_attachment() && has_post_thumbnail() );
}
/**
* Returns true if image filters are enabled on the theme options.
*/
function twentynineteen_image_filters_enabled() {
return 0 !== get_theme_mod( 'image_filter', 1 );
}
/**
* Add custom sizes attribute to responsive image functionality for post thumbnails.
*
* @origin Twenty Nineteen 1.0
*
* @param array $attr Attributes for the image markup.
* @return string Value for use in post thumbnail 'sizes' attribute.
*/
function twentynineteen_post_thumbnail_sizes_attr( $attr ) {
if ( is_admin() ) {
return $attr;
}
if ( ! is_singular() ) {
$attr['sizes'] = '(max-width: 34.9rem) calc(100vw - 2rem), (max-width: 53rem) calc(8 * (100vw / 12)), (min-width: 53rem) calc(6 * (100vw / 12)), 100vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 );
/**
* Returns the size for avatars used in the theme.
*/
function twentynineteen_get_avatar_size() {
return 60;
}
/**
* Returns true if comment is by author of the post.
*
* @see get_comment_class()
*/
function twentynineteen_is_comment_by_post_author( $comment = null ) {
if ( is_object( $comment ) && $comment->user_id > 0 ) {
$user = get_userdata( $comment->user_id );
$post = get_post( $comment->comment_post_ID );
if ( ! empty( $user ) && ! empty( $post ) ) {
return $comment->user_id === $post->post_author;
}
}
return false;
}
/**
* Returns information about the current post's discussion, with cache support.
*/
function twentynineteen_get_discussion_data() {
static $discussion, $post_id;
$current_post_id = get_the_ID();
if ( $current_post_id === $post_id ) {
return $discussion; /* If we have discussion information for post ID, return cached object */
} else {
$post_id = $current_post_id;
}
$comments = get_comments(
array(
'post_id' => $current_post_id,
'orderby' => 'comment_date_gmt',
'order' => get_option( 'comment_order', 'asc' ), /* Respect comment order from Settings » Discussion. */
'status' => 'approve',
'number' => 20, /* Only retrieve the last 20 comments, as the end goal is just 6 unique authors */
)
);
$authors = array();
foreach ( $comments as $comment ) {
$authors[] = ( (int) $comment->user_id > 0 ) ? (int) $comment->user_id : $comment->comment_author_email;
}
$authors = array_unique( $authors );
$discussion = (object) array(
'authors' => array_slice( $authors, 0, 6 ), /* Six unique authors commenting on the post. */
'responses' => get_comments_number( $current_post_id ), /* Number of responses. */
);
return $discussion;
}
/**
* Add an extra menu to our nav for our priority+ navigation to use
*
* @param object $nav_menu Nav menu.
* @param object $args Nav menu args.
* @return string More link for hidden menu items.
*/
function twentynineteen_add_ellipses_to_nav( $nav_menu, $args ) {
if ( 'menu-1' === $args->theme_location ) :
$nav_menu .= '<div class="main-menu-more">';
$nav_menu .= '<ul class="main-menu" tabindex="0">';
$nav_menu .= '<li class="menu-item menu-item-has-children">';
$nav_menu .= '<a href="#" class="screen-reader-text" aria-label="More" aria-haspopup="true" aria-expanded="false">' . esc_html__( 'More', 'twentynineteen' ) . '</a>';
$nav_menu .= '<span class="submenu-expand main-menu-more-toggle is-empty" tabindex="-1">';
$nav_menu .= twentynineteen_get_icon_svg( 'arrow_drop_down_ellipsis' );
$nav_menu .= '</span>';
$nav_menu .= '<ul class="sub-menu hidden-links">';
$nav_menu .= '<li id="menu-item--1" class="mobile-parent-nav-menu-item menu-item--1">';
$nav_menu .= '<span class="menu-item-link-return">';
$nav_menu .= twentynineteen_get_icon_svg( 'chevron_left' );
$nav_menu .= esc_html__( 'Back', 'twentynineteen' );
$nav_menu .= '</span>';
$nav_menu .= '</li>';
$nav_menu .= '</ul>';
$nav_menu .= '</li>';
$nav_menu .= '</ul>';
$nav_menu .= '</div>';
endif;
return $nav_menu;
}
add_filter( 'wp_nav_menu', 'twentynineteen_add_ellipses_to_nav', 10, 2 );
/**
* WCAG 2.0 Attributes for Dropdown Menus
*
* Adjustments to menu attributes tot support WCAG 2.0 recommendations
* for flyout and dropdown menus.
*
* @ref https://www.w3.org/WAI/tutorials/menus/flyout/
*/
function twentynineteen_nav_menu_link_attributes( $atts, $item, $args, $depth ) {
// Add [aria-haspopup] and [aria-expanded] to menu items that have children
$item_has_children = in_array( 'menu-item-has-children', $item->classes );
if ( $item_has_children ) {
$atts['aria-haspopup'] = 'true';
$atts['aria-expanded'] = 'false';
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'twentynineteen_nav_menu_link_attributes', 10, 4 );
/**
* Add a dropdown icon to top-level menu items.
*
* @param string $output Nav menu item start element.
* @param object $item Nav menu item.
* @param int $depth Depth.
* @param object $args Nav menu args.
* @return string Nav menu item start element.
* Add a dropdown icon to top-level menu items
*/
function twentynineteen_add_dropdown_icons( $output, $item, $depth, $args ) {
// Only add class to 'top level' items on the 'primary' menu.
if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) {
return $output;
}
if ( in_array( 'mobile-parent-nav-menu-item', $item->classes, true ) && isset( $item->original_id ) ) {
// Inject the keyboard_arrow_left SVG inside the parent nav menu item, and let the item link to the parent item.
// @todo Only do this for nested submenus? If on a first-level submenu, then really the link could be "#" since the desire is to remove the target entirely.
$link = sprintf(
'<span class="menu-item-link-return" tabindex="-1">%s',
twentynineteen_get_icon_svg( 'chevron_left', 24 )
);
// replace opening <a> with <span>
$output = preg_replace(
'/<a\s.*?>/',
$link,
$output,
1 // Limit.
);
// replace closing </a> with </span>
$output = preg_replace(
'#</a>#i',
'</span>',
$output,
1 // Limit.
);
} elseif ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
// Add SVG icon to parent items.
$icon = twentynineteen_get_icon_svg( 'keyboard_arrow_down', 24 );
$output .= sprintf(
'<span class="submenu-expand" tabindex="-1">%s</span>',
$icon
);
}
return $output;
}
add_filter( 'walker_nav_menu_start_el', 'twentynineteen_add_dropdown_icons', 10, 4 );
/**
* Create a nav menu item to be displayed on mobile to navigate from submenu back to the parent.
*
* This duplicates each parent nav menu item and makes it the first child of itself.
*
* @param array $sorted_menu_items Sorted nav menu items.
* @param object $args Nav menu args.
* @return array Amended nav menu items.
*/
function twentynineteen_add_mobile_parent_nav_menu_items( $sorted_menu_items, $args ) {
static $pseudo_id = 0;
if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) {
return $sorted_menu_items;
}
$amended_menu_items = array();
foreach ( $sorted_menu_items as $nav_menu_item ) {
$amended_menu_items[] = $nav_menu_item;
if ( in_array( 'menu-item-has-children', $nav_menu_item->classes, true ) ) {
$parent_menu_item = clone $nav_menu_item;
$parent_menu_item->original_id = $nav_menu_item->ID;
$parent_menu_item->ID = --$pseudo_id;
$parent_menu_item->db_id = $parent_menu_item->ID;
$parent_menu_item->object_id = $parent_menu_item->ID;
$parent_menu_item->classes = array( 'mobile-parent-nav-menu-item' );
$parent_menu_item->menu_item_parent = $nav_menu_item->ID;
$amended_menu_items[] = $parent_menu_item;
}
}
return $amended_menu_items;
}
add_filter( 'wp_nav_menu_objects', 'twentynineteen_add_mobile_parent_nav_menu_items', 10, 2 );
/**
* Convert HSL to HEX colors
*/
function twentynineteen_hsl_hex( $h, $s, $l, $to_hex = true ) {
$h /= 360;
$s /= 100;
$l /= 100;
$r = $l;
$g = $l;
$b = $l;
$v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s );
if ( $v > 0 ) {
$m;
$sv;
$sextant;
$fract;
$vsf;
$mid1;
$mid2;
$m = $l + $l - $v;
$sv = ( $v - $m ) / $v;
$h *= 6.0;
$sextant = floor( $h );
$fract = $h - $sextant;
$vsf = $v * $sv * $fract;
$mid1 = $m + $vsf;
$mid2 = $v - $vsf;
switch ( $sextant ) {
case 0:
$r = $v;
$g = $mid1;
$b = $m;
break;
case 1:
$r = $mid2;
$g = $v;
$b = $m;
break;
case 2:
$r = $m;
$g = $v;
$b = $mid1;
break;
case 3:
$r = $m;
$g = $mid2;
$b = $v;
break;
case 4:
$r = $mid1;
$g = $m;
$b = $v;
break;
case 5:
$r = $v;
$g = $m;
$b = $mid2;
break;
}
}
$r = round( $r * 255, 0 );
$g = round( $g * 255, 0 );
$b = round( $b * 255, 0 );
if ( $to_hex ) {
$r = ( $r < 15 ) ? '0' . dechex( $r ) : dechex( $r );
$g = ( $g < 15 ) ? '0' . dechex( $g ) : dechex( $g );
$b = ( $b < 15 ) ? '0' . dechex( $b ) : dechex( $b );
return "#$r$g$b";
}
return "rgb($r, $g, $b)";
}