', $close = '', $callback = '', $callback_args = '' ) { if ( ! $context ) { return; } // Short circuit filter. $check = apply_filters( "aamla_markup_{$context}", false, $context ); if ( false !== $check ) { return; } printf( $open, aamla_get_attr( $context ) ); // WPCS xss ok. $hook = str_replace( '-', '_', $context ); do_action( "aamla_inside_{$hook}", "inside_{$hook}" ); if ( ! empty( $callback ) && is_callable( $callback ) ) { if ( ! empty( $callback_args ) ) { call_user_func( $callback, $callback_args ); } else { call_user_func( $callback ); } } echo $close; // WPCS xss ok. } /** * Outputs an HTML element's attributes. * * The purposes of this is to provide a way to hook into the attributes for specific * HTML elements and create new or modify existing attributes, without modifying actual * markup templates. * * @since 1.0.0 * * @param str $slug The slug/ID of the element (e.g., 'sidebar'). * @param array $attr Array of attributes to pass in (overwrites filters). */ function aamla_attr( $slug, $attr = array() ) { echo aamla_get_attr( $slug, $attr ); // WPCS xss ok. } /** * Gets an HTML element's attributes. * * @since 1.0.0 * * @param str $slug The slug/ID of the element (e.g., 'sidebar'). * @param array $attr Array of attributes to pass in (overwrites filters). * @return string */ function aamla_get_attr( $slug, $attr = array() ) { $out = ''; if ( false !== $attr ) { if ( isset( $attr['class'] ) ) { $attr['class'] .= ' ' . $slug; } else { $attr['class'] = $slug; } } $hook = str_replace( '-', '_', $slug ); /** * Filter element's attributes. * * @since 1.0.0 */ $attr = apply_filters( "aamla_get_attr_{$hook}", $attr, $slug ); if ( $attr ) { foreach ( $attr as $name => $value ) { $out .= sprintf( ' %s="%s"', esc_html( $name ), esc_attr( $value ) ); } } return $out; } /** * Output a font icon. * * @since 1.0.0 * * @param array $args Parameters needed to display a font icon. */ function aamla_icon( $args = array() ) { $icon_markup = aamla_get_icon( $args ); if ( $icon_markup ) { echo $icon_markup; // WPCS xss ok. } } /** * Return font icon SVG markup. * * @param array $args { * Parameters needed to display an SVG. * * @type string $icon Required SVG icon filename. * @type string $title Optional SVG title. * @type string $desc Optional SVG description. * } * @return string Font icon SVG markup. */ function aamla_get_icon( $args = array() ) { // Make sure $args are an array. if ( empty( $args ) ) { return esc_html__( 'Please define default parameters in the form of an array.', 'aamla' ); } // Define an icon. if ( false === array_key_exists( 'icon', $args ) ) { return esc_html__( 'Please define an SVG icon filename.', 'aamla' ); } // Set defaults. $defaults = array( 'icon' => '', 'title' => '', 'desc' => '', 'fallback' => false, ); // Parse args. $args = wp_parse_args( $args, $defaults ); // Set aria hidden. $aria_hidden = ' aria-hidden="true"'; // Set ARIA. $aria_labelledby = ''; /* * Aamla doesn't use the SVG title or description attributes; non-decorative icons are * described with .screen-reader-text. However, child themes can use the title and description * to add information to non-decorative SVG icons to improve accessibility. * * Example 1 with title: 'arrow-right', 'title' => __( 'This is the title', 'textdomain' ) ) ); ?> * * Example 2 with title and description: 'arrow-right', 'title' => __( 'This is the title', 'textdomain' ), 'desc' => __( 'This is the description', 'textdomain' ) ) ); ?> * * See https://www.paciellogroup.com/blog/2013/12/using-aria-enhance-svg-accessibility/. */ if ( $args['title'] ) { $aria_hidden = ''; $unique_id = uniqid(); $aria_labelledby = ' aria-labelledby="title-' . $unique_id . '"'; if ( $args['desc'] ) { $aria_labelledby = ' aria-labelledby="title-' . $unique_id . ' desc-' . $unique_id . '"'; } } // Begin SVG markup. $svg = ''; // Display the title. if ( $args['title'] ) { $svg .= '' . esc_html( $args['title'] ) . ''; // Display the desc only if the title is already set. if ( $args['desc'] ) { $svg .= '' . esc_html( $args['desc'] ) . ''; } } /* * Display the icon. * * The whitespace around `` is intentional - it is a work around to a keyboard navigation bug in Safari 10. * * See https://core.trac.wordpress.org/ticket/38387. */ $svg .= ' '; // Add some markup to use as a fallback for browsers that do not support SVGs. if ( $args['fallback'] ) { $svg .= ''; } $svg .= ''; return $svg; } /** * Get navigation menu markup. * * Create navigation menu markup based on arguments provided. * * @since 1.0.0 * * @param string $nav_id Menu container ID. * @param string $menu_id Menu ID. * @param string $label Menu label. * @param string $location Menu theme location. * @param bool $is_toggle Is toggle button required. * @param int $args Additional wp_nav_menu args. */ function aamla_nav_menu( $nav_id, $menu_id, $label, $location, $is_toggle = false, $args = array() ) { if ( $is_toggle ) { $toggle = sprintf( '', esc_attr( $menu_id ), aamla_get_icon( array( 'icon' => 'bars' ) ), aamla_get_icon( array( 'icon' => 'close' ) ), esc_html__( 'Menu', 'aamla' ) ); } else { $toggle = ''; } $menu = sprintf( '

%s

', esc_html( $label ) ); $menu .= wp_nav_menu( array_merge( $args, array( 'theme_location' => $location, 'menu_id' => $menu_id, 'menu_class' => 'nav-menu nav-menu--' . $location, 'echo' => false, ) ) ); printf( '%1$s', $toggle, esc_attr( $nav_id ), esc_attr( $nav_id ), esc_attr( $label ), $menu ); // WPCS xss ok. } /** * Get widget markup. * * Create widget markup based on arguments provided. * * @since 1.0.0 * * @param string $id Widget ID. * @param string $class Widget HTML class. * @param string $label Widget label. * @param array $widgets Registered sidebar(s) to be displayed. * @param string $before_widgets Markup to be displayed before widgets. * @param string $after_widgets Markup to be displayed after widgets. */ function aamla_widgets( $id, $class, $label, $widgets = array(), $before_widgets = '', $after_widgets = '' ) { // Short circuit filter. $check = apply_filters( "aamla_widgets_{$id}", false, $id ); if ( false !== $check ) { return; } printf( '' ); } /** * Get a theme template part. * * This is a wrapper function on WordPress built-in function "get_template_part()" * to provide additional provision to change required template using filters. * * @since 1.0.0 * * @param string $path Template file path. * @param string $file_name Template file name. * @param string $arg Additional arguments for identification. * @return void */ function aamla_get_template_partial( $path, $file_name, $arg = '' ) { $file = $path . '/' . $file_name; $file_name = str_replace( '-', '_', $file_name ); $file = apply_filters( "aamla_template_{$file_name}", $file, $arg ); // Load the template file. if ( $file ) { get_template_part( $file ); } } /** * Get link to blog posts page. * * @since 1.0.0 * * @return url Link to blog posts page. */ function aamla_get_blog_posts_link() { if ( 'page' === get_option( 'show_on_front' ) ) { return get_permalink( get_option( 'page_for_posts' ) ); } else { return home_url(); } } /** * Wrapper for 'add_action()' for theme specific hooks. * * This is a wrapper function on WordPress built-in function "add_action()" * to make it slightly clean and redable. * * @since 1.0.0 * * @param string $func_name Name of the functions to be hooked. * @param string $hook Template Name of the hook. * @param int $priority Priority of execution. * @param int $args Number of arguments passed to the function. * @return void */ function aamla_add_markup_for( $func_name, $hook, $priority = 10, $args = 1 ) { add_action( "aamla_{$hook}", "aamla_{$func_name}", $priority, $args ); } /** * Wrapper for 'remove_action()' for theme specific hooks. * * This is a wrapper function on WordPress built-in function "remove_action()" * to make it slightly clean and redable. * * @since 1.0.0 * * @param string $func_name Name of the functions to be unhooked. * @param string $hook Template Name of the hook. * @param int $priority Priority of execution. * @param int $args Number of arguments passed to the function. * @return void */ function aamla_remove_markup_for( $func_name, $hook, $priority = 10, $args = 1 ) { remove_action( "aamla_{$hook}", "aamla_{$func_name}", $priority, $args ); }