'default',
'themeoo_secondary_header' => 'default',
'themeoo_section_height' => 0,
'themeoo_site_layout' => 'default',
'themeoo_titlebar' => 'default',
'themeoo_page_title' => 'default',
'themeoo_content_layout' => 'default',
'themeoo_sidebar' => 'default',
]
)
);
$option = strtolower( $option );
if ( ! $option || 'all' === $option ) {
return $settings;
}
if ( false === strpos( $option, 'themeoo_' ) ) {
$option = 'themeoo_' . $option;
}
if ( isset( $settings[ $option ] ) ) {
return $settings[ $option ];
}
_doing_it_wrong( __FUNCTION__, sprintf(
/* translators: %s: Option name. */
esc_html__( 'Option is not registered with theme companion', 'ayyash' ),
'' . esc_html( $option ) . ''
), '1.0.0' );
return false;
}
}
if ( ! function_exists( 'themeoo_body_classes' ) ) {
/**
* Body class for multi author system.
*
* @param string[] $classes body class list.
*
* @return array
*/
function themeoo_body_classes( $classes ) {
// Adds a class of group-blog to blog with more than 1 published author.
$classes[] = 'ayyash';
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
return $classes;
}
}
if ( ! function_exists('themeoo_search_menu_icon') ) {
/**
* Mobile search icon
*
* @param string $items nav items.
* @param object $args nav args.
*
* @return string
*/
function themeoo_search_menu_icon( $items, $args ) {
if ( themeoo_get_mod( 'layout_header_search' ) && isset( $args->theme_location ) && 'primary' === $args->theme_location ) {
// @phpstan-ignore-next-line
$items .= '
';
}
return $items;
}
}
if ( ! function_exists('themeoo_mobile_icon') ) {
/**
* Mobile Menu Icon.
*
* @return void
*/
function themeoo_mobile_icon() {
$mobile_icon_grid = themeoo_get_mod( 'layout_header_menu_mobileshow' );
switch ( $mobile_icon_grid ) {
case 'sm':
$mobile_icon_grid = ' d-block d-md-none';
break;
case 'md':
$mobile_icon_grid = ' d-block d-lg-none';
break;
case 'lg':
$mobile_icon_grid = ' d-block d-xl-none';
break;
case 'xl':
$mobile_icon_grid = ' d-block';
break;
default:
$mobile_icon_grid = ' d-block d-xl-none';
}
?>
'mobile' ) );
} else {
wp_nav_menu( array(
'theme_location' => 'primary',
'mobile' => true,
) );
}
}
}
if ( ! function_exists('themeoo_header_user_account_info') ) {
/**
* Right Nav Panel.
*
* @return void
*/
function themeoo_header_user_account_info() {
$stat = is_user_logged_in();
$label = $stat ? __( 'My Account', 'ayyash' ) : __( 'Sign Up / Log In', 'ayyash' );
$title = $stat ? __( 'My Account', 'ayyash' ) : __( 'Login', 'ayyash' );
/** @noinspection HtmlUnknownTarget */
printf(
' %s',
esc_url( get_permalink( get_option('woocommerce_myaccount_page_id') ) ), // @phpstan-ignore-line
esc_attr( $title ),
esc_html( $label )
);
}
}
if ( ! function_exists('themeoo_wp_page_menu') ) {
/**
* Display or retrieve list of pages with optional home link.
*
* This function is copied from WP wp_page_menu function to add an extra class as
* the default WP function has no inbuilt way to achieve this without using hacks
*
* @param array $args args.
*
* @return string html menu
*/
function themeoo_wp_page_menu( $args = array() ) {
$defaults = array(
'sort_column' => 'menu_order, post_title',
'menu_class' => 'menu',
'echo' => true,
'link_before' => '',
'link_after' => '',
);
$args = wp_parse_args($args, $defaults);
/**
* Filter the arguments used to generate a page-based menu.
*
* @see wp_page_menu()
*
* @param array $args An array of page menu arguments.
*/
$args = apply_filters( 'wp_page_menu_args', $args ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
$menu = '';
$list_args = $args;
// Show Home in the menu.
if ( ! empty( $args['show_home'] ) ) {
if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) {
$text = __( 'Home', 'ayyash' );
} else {
$text = $args['show_home'];
}
$class = '';
if ( is_front_page() && ! is_paged() ) {
$class = 'class="current_page_item"';
}
$menu .= '' . $args['link_before'] . $text . $args['link_after'] . '';
// If the front page is a page, add it to the exclude list.
if ( 'page' == get_option('show_on_front') ) {
if ( ! empty( $list_args['exclude'] ) ) {
$list_args['exclude'] .= ',';
} else {
$list_args['exclude'] = '';
}
$list_args['exclude'] .= get_option( 'page_on_front' );
}
}
$list_args['echo'] = false;
$list_args['depth'] = 1;
$list_args['title_li'] = '';
$menu .= str_replace( [ "\r", "\n", "\t" ], '', wp_list_pages( $list_args ) ); // @phpstan-ignore-line
if ( $menu ) {
$menu = '';
}
$menu = '\n";
/**
* Filter the HTML output of a page-based menu.
*
* @see wp_page_menu()
*
* @param string $menu The HTML output.
* @param array $args An array of arguments.
*/
$menu = apply_filters( 'wp_page_menu', $menu, $args ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
if ( $args['echo'] ) {
echo $menu; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
return $menu;
}
}
if ( class_exists('WooCommerce') ) {
/**
* CPT notice.
*
* @return void
*/
function themeoo_show_cpt_archive_notice() {
global $post;
$shop_page_id = wc_get_page_id( 'shop' );
if ( $post && absint( $shop_page_id ) === absint( $post->ID ) ) { ?>
get_sale_price();
$regular_price = $product->get_regular_price();
if ( ! empty( $sale_price ) && $regular_price > $sale_price ) {
$discount = ( ( (float) $regular_price - (float) $sale_price ) / (float) $regular_price ) * 100;
$discount = round( $discount, $precision );
}
}
if ( $discount > 0 ) {
printf( '%1$s%%', (float) $discount );
}
}
}
if ( ! function_exists( 'themeoo_get_product_badge' ) ) {
/**
* Get product badge.
*
* @param int $product_id Product ID.
* @param array $check check.
*
* @return void
*/
function themeoo_get_product_badge( $product_id = null, $check = array() ) {
$product_id = ! $product_id ? get_the_ID() : $product_id;
$product = wc_get_product( $product_id );
if ( ! $product ) {
return;
}
$product_tags = array_map( function ( $tag_id ) use ( $check ) {
$term = get_term_by( 'id', $tag_id, 'product_tag' );
// @phpstan-ignore-next-line
if ( ! $term || is_wp_error( $term ) ) {
return null;
}
/**
* @var WP_Term $term
*/
if ( ! empty( $check ) && ! in_array( $term->slug, $check ) ) {
return null;
}
return sprintf( '%s', esc_attr( $term->slug ), esc_html( $term->name ) );
},
$product->get_tag_ids()
);
$product_tags = array_filter( $product_tags );
if ( ! empty( $product_tags ) ) {
echo implode( '', $product_tags ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
}
/**
* Get Layout for a view.
*
* @param string $view View.
*
* @return string
*/
function themeoo_get_content_layout( $view = '' ) {
if ( '' === $view ) {
$view = themeoo_get_view();
}
return apply_filters( 'themeoo_content_layout', themeoo_get_mod('layout_' . $view . '_style'), $view );
}
/**
* Render oEmbed content.
*
* @param string $src Link to render.
* @param bool $echo display or return content.
* Default is true (display)
*
* @return void|string|false|true return embed html or false, true if displayed.
*
* @see WP_Embed::shortcode()
* WP Embed uses current (global) post's id (meta) to cache the oEmbed api responses.
*/
function themeoo_render_embedded( $src, $echo = true ) {
global $wp_embed;
if ( ! strpos( $src, '://' ) ) {
$src = 'http://' . $src;
}
$src = esc_url_raw( $src );
if ( ! $src ) {
return;
}
$embedded = $wp_embed->run_shortcode( '[embed]' . $src . '[/embed]' );
$embedded = apply_filters( 'themeoo_render_embedded', $embedded, $src );
if ( ! $echo ) {
return $embedded;
}
if ( $embedded ) {
echo $embedded; // phpcs:ignore WordPress.Security.EscapeOutput
return true;
}
return false;
}
/**
* Print the first instance of a block in the content, and then break away.
*
* Scrapped from Twenty Twenty-One 1.0
*
* @param string $block_name The full block type name, or a partial match.
* Example: `core/image`, `core-embed/*`.
* @param string|null $content The content to search in. Use null for get_the_content().
* @param int $instances How many instances of the block will be printed (max). Defaults to 1.
*
* @return bool Returns true if a block was located & printed, otherwise false.
*/
function themeoo_print_first_instance_of_block( $block_name, $content = null, $instances = 1 ) {
$instances_count = 0;
$blocks_content = '';
if ( ! $content ) {
$content = get_the_content();
}
// Parse blocks in the content.
$blocks = parse_blocks( $content );
// Loop blocks.
foreach ( $blocks as $block ) {
// Sanity check.
if ( ! isset( $block['blockName'] ) ) {
continue;
}
// Check if this the block matches the $block_name.
$is_matching_block = false;
// If the block ends with *, try to match the first portion.
if ( '*' === $block_name[-1] ) {
$is_matching_block = 0 === strpos( $block['blockName'], rtrim( $block_name, '*' ) );
} else {
$is_matching_block = $block_name === $block['blockName'];
}
if ( $is_matching_block ) {
// Increment count.
$instances_count++;
// Add the block HTML.
$blocks_content .= render_block( $block );
// Break the loop if the $instances count was reached.
if ( $instances_count >= $instances ) {
break;
}
}
}
if ( $blocks_content ) {
echo apply_filters( 'the_content', $blocks_content ); // phpcs:ignore WordPress.Security.EscapeOutput
return true;
}
return false;
}