'default',
'ayyash_secondary_header' => 'default',
'ayyash_section_height' => 0,
'ayyash_site_layout' => 'default',
'ayyash_titlebar' => 'default',
'ayyash_page_title' => 'default',
'ayyash_content_layout' => 'default',
'ayyash_sidebar' => 'default',
'ayyash_display_main_footer' => 'default',
'ayyash_display_secondary_footer' => 'default',
'ayyash_display_credit' => 'default',
)
);
// fx option name.
if ( ! $option ) {
$option = 'all';
} else {
$option = str_replace( 'ayyash_', '', $option );
}
if ( $post ) {
if ( 'all' !== $option && has_filter( "ayyash_pre_get_post_{$option}_option" ) ) {
// Eg. ayyash_pre_get_post_content_layout_option
// Eg. ayyash_pre_get_post_display_header_option
return apply_filters( "ayyash_pre_get_post_{$option}_option", $post );
}
if ( ! isset( $ayyash_loaded_layout_options[ $post->ID ] ) ) {
$settings = (array) get_post_meta( $post->ID, 'ayyash', true );
$settings = array_filter( $settings );
$settings = wp_parse_args( $settings, $defaults );
$settings = apply_filters( 'ayyash_post_layout_options', $settings, $post );
// Store into cache.
$ayyash_loaded_layout_options[ $post->ID ] = $settings;
} else {
// Read from cache.
$settings = $ayyash_loaded_layout_options[ $post->ID ];
}
} else {
// This function can be called from any archive pages...
$settings = apply_filters( 'ayyash_post_layout_options', $defaults, null );
}
if ( 'all' === $option ) {
return $settings;
}
if ( isset( $settings[ $option ] ) ) {
return $settings[ $option ];
}
if ( isset( $settings[ 'ayyash_' . $option ] ) ) {
return $settings[ 'ayyash_' . $option ];
}
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: %s: Option name. */
esc_html__( 'Option %s is not registered within current theme', 'ayyash' ),
'' . esc_html( $option ) . ''
),
'1.0.0'
);
return false;
}
}
if ( ! function_exists( 'ayyash_get_current_screen' ) ) {
/**
* Determine the current view.
*
* @return string The string representing the current view.
*/
function ayyash_get_current_screen() {
global $ayyash_screen;
if ( isset($ayyash_screen) ) {
return $ayyash_screen;
}
// Post types.
$post_types = get_post_types(
array(
'public' => true,
'_builtin' => false,
)
);
$post_types[] = 'post';
// Post parent.
$parent_post_type = '';
if ( is_attachment() ) {
$attachment = get_post();
$parent_post_type = $attachment ? get_post_type($attachment->post_parent) : '';
}
$ayyash_screen = 'post';
if ( is_home() ) {
$ayyash_screen = 'blog'; // Blog.
} elseif ( is_archive() && ! is_post_type_archive('product') ) {
$ayyash_screen = 'archive'; // Archives.
} elseif ( is_search() ) {
$ayyash_screen = 'search'; // Search results.
// @phpstan-ignore-next-line
} elseif ( is_singular($post_types) || ( is_attachment() && in_array($parent_post_type, $post_types, true) ) ) {
$ayyash_screen = 'post'; // Posts and public custom post types.
} elseif ( is_page() || ( is_attachment() && 'page' === $parent_post_type ) ) {
$ayyash_screen = 'page'; // Pages.
}
return apply_filters('ayyash_current_screen', $ayyash_screen);
}
}
if ( ! function_exists( 'ayyash_get_sidebar_position' ) ) {
/**
* Get Sidebar Position.
*
* @param string $screen current view.
*
* @return string
*/
function ayyash_get_sidebar_position( $screen = '' ) {
global $ayyash_loaded_sidebar_position;
if ( ! $screen ) {
$screen = ayyash_get_current_screen();
}
if ( null === $ayyash_loaded_sidebar_position ) {
$ayyash_loaded_sidebar_position = array();
}
if ( isset( $ayyash_loaded_sidebar_position[ $screen ] ) ) {
return $ayyash_loaded_sidebar_position[ $screen ];
}
if ( class_exists( 'WooCommerce' ) && ( is_post_type_archive( 'product' ) ) ) {
$position = ayyash_get_mod( 'woocommerce_shop_archive_layout' );
} elseif ( class_exists( 'WooCommerce' ) && is_product() ) {
$position = ayyash_get_mod( 'woocommerce_single_layout' );
} elseif ( class_exists( 'WooCommerce' ) && is_cart() ) {
$position = ayyash_get_mod( 'woocommerce_cart_sidebar_layout' );
} elseif ( class_exists( 'WooCommerce' ) && is_checkout() ) {
$position = ayyash_get_mod( 'woocommerce_checkout_sidebar_layout' );
} elseif ( class_exists( 'WooCommerce' ) && is_account_page() ) {
$position = ayyash_get_mod( 'woocommerce_myaccount_sidebar_layout' );
} elseif ( class_exists( 'WooCommerce' ) && is_product_category() ) {
$position = ayyash_get_mod( 'woocommerce_product_catalog_sidebar_layout' );
} else {
/**
* @var string $single_sidebar_position
*/
$single_sidebar_position = ayyash_get_post_layout_options( 'content_layout' );
if ( 'default' !== $single_sidebar_position && $single_sidebar_position ) {
$position = $single_sidebar_position;
} else {
$position = ayyash_get_mod( 'layout_' . $screen . '_sidebar' );
// In case current screen is modified and not found in default values.
if ( ! $position ) {
$position = 'none';
}
}
}
$ayyash_loaded_sidebar_position[ $screen ] = apply_filters( 'ayyash_sidebar_position', $position, $screen );
return $ayyash_loaded_sidebar_position[ $screen ];
}
}
if ( ! function_exists( 'ayyash_layzload_enabled' ) ) {
/**
* Checks if lazy-loading images is enabled.
*
* @return bool
*/
function ayyash_layzload_enabled() {
return (bool) ayyash_get_mod( 's_config_lazyload_enable' );
}
}
if ( ! function_exists( 'ayyash_doing_rest' ) ) {
/**
* Ayyash rest api request
*
* @return false|mixed|void
*/
function ayyash_doing_rest() {
if ( empty( $_SERVER['REQUEST_URI'] ) ) {
return false;
}
$rest_prefix = trailingslashit( rest_get_url_prefix() );
$is_rest_api_request = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix ) ); // phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
return apply_filters( 'ayyash_is_rest_api_request', $is_rest_api_request );
}
}
if ( ! function_exists( 'ayyash_maybe_lazyload_post_thumbnail' ) ) {
/**
* Ayyash lazyload post thumbnail
*
* @return mixed|void
*/
function ayyash_maybe_lazyload_post_thumbnail() {
return apply_filters(
'ayyash_lazyload_post_thumbnail',
(
ayyash_layzload_enabled() &&
! is_admin() &&
! wp_doing_ajax() &&
! ayyash_doing_rest()
)
);
}
}
if ( ! function_exists( 'ayyash_search_menu_icon' ) ) {
/**
* Mobile search icon
*
* @param string $items nav items.
* @param object $args nav args.
*
* @return string
*/
function ayyash_search_menu_icon() {
if ( ayyash_get_mod( 'layout_header_search' ) ) {
?>
'mobile' ) );
} else {
wp_nav_menu(
array(
'theme_location' => 'primary',
'mobile' => true,
)
);
}
}
}
if ( ! function_exists( 'ayyash_header_user_account_info' ) ) {
/**
* Right Nav Panel.
*
* @return void
*/
function ayyash_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( 'ayyash_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 ayyash_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,WPThemeReview.CoreFunctionality.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'] = ''; // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude
}
$list_args['exclude'] .= get_option( 'page_on_front' );
}
}
$list_args['echo'] = false;
$list_args['depth'] = 1;
$list_args['title_li'] = '';
$menu .= str_replace( array( "\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,WPThemeReview.CoreFunctionality.PrefixAllGlobals.NonPrefixedHooknameFound
if ( $args['echo'] ) {
echo $menu; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
return $menu;
}
}
if ( class_exists( 'WooCommerce' ) ) {
/**
* CPT notice.
*
* @return void
*/
function ayyash_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 ( class_exists( 'Ayyash_Pro' ) ) {
$product_label_type = ayyash_get_mod('woocommerce_shop_archive_label_type');
} else {
$product_label_type = '';
}
if ( $discount > 0 ) {
printf(
'%2$s%% OFF',
esc_attr( $product_label_type ? $product_label_type : 'fill' ),
(float) $discount
);
}
}
}
if ( ! function_exists( 'ayyash_get_featured_badge' ) ) {
/**
* Display Product Discount Tag.
*
* @param int $product_id Product ID.
*
* @return void
*/
function ayyash_get_featured_badge( $product_id = null ) {
$product_id = ! $product_id ? get_the_ID() : $product_id;
$product = wc_get_product( $product_id );
$is_featured = false;
if ( $product instanceof WC_Product ) {
$is_featured = $product->is_featured();
}
if ( class_exists( 'Ayyash_Pro' ) ) {
$product_label_type = ayyash_get_mod('woocommerce_shop_archive_label_type');
} else {
$product_label_type = '';
}
if ( $is_featured ) {
printf(
'Featured',
esc_attr( $product_label_type ? $product_label_type : 'fill' )
);
}
}
}
if ( ! function_exists( 'ayyash_get_product_badge' ) ) {
/**
* Get product badge.
*
* @param int $product_id Product ID.
* @param array $check check.
*
* @return void
*/
function ayyash_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 ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
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
}
}
}
if ( ! function_exists( 'ayyash_wpcf7_form_class_attr') ) {
/**
* Contact Form 7 wpcf7_form_class_attr callback
*
* @param $class
*
* @return string
*/
function ayyash_wpcf7_form_class_attr( $class ) {
$class .= ' ayyash-' . ayyash_get_mod( 'layout_wpcf7_columns' );
$inline_acceptance_btn = ayyash_get_mod('layout_wpcf7_inline_acceptance_btn');
if ( $inline_acceptance_btn ) {
$class .= ' ayyash-inline-acceptance-btn';
}
return $class;
}
add_filter( 'wpcf7_form_class_attr', 'ayyash_wpcf7_form_class_attr', 10, 1 );
}
/**
* Get Layout for a view.
*
* @param string $view View.
*
* @return string
*/
function ayyash_get_content_layout( $view = '' ) {
if ( '' === $view ) {
$view = ayyash_get_current_screen();
}
$layout = wp_cache_get( 'layout_' . $view . '_style' );
if ( false === $layout ) {
$layout = ayyash_get_mod( 'layout_' . $view . '_style' );
wp_cache_set( 'layout_' . $view . '_style', $layout );
}
return apply_filters( 'ayyash_content_layout', $layout, $view );
}
/**
* Get post format content class for layout.
*
* @param string $layout
* @param string $class
*
* @return void
*/
function ayyash_get_post_format_classes( $layout = 'normal', $class = '' ) {
$map = [ 'grid', 'normal', 'medium' ];
if ( ! in_array( $layout, $map, true ) ) {
$layout = 'normal';
}
$format = get_post_format();
$classes = [
'blog-' . $layout,
'post-' . $format,
'entry-' . $format . '-post-format',
$format,
];
if ( 'medium' === $layout ) {
$classes[] = 'medium-left';
}
if ( 'gallery' === $format ) {
$classes[] = 'carousel';
$classes[] = 'slide';
$classes[] = 'blog-gallery-slider';
}
// Animations
$classes[] = 'effect';
$classes[] = 'slide-top';
if ( ! empty( $class ) ) {
if ( is_string( $class ) ) {
$class = preg_split( '#\s+#', $class );
}
if ( is_array( $class ) ) {
$classes = array_merge( $classes, $class );
}
}
if ( ! is_array( $class ) ) {
// Ensure that we always coerce class to being an array.
$class = array();
}
/**
* Filters the list of CSS post-format class names for the current post in the loop.
*
* @param string[] $classes An array of body class names.
* @param string[] $class An array of additional class names added to the body.
*/
$classes = apply_filters( 'ayyash_post_format_class', $classes, $class );
$classes = array_map( 'esc_attr', $classes );
echo 'class="' . esc_attr( implode( ' ', array_unique( $classes ) ) ) . '"';
}
/**
* 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 ayyash_render_embedded( $src, $echo = true ) {
global $wp_embed;
if ( ! strpos( $src, '://' ) ) {
$src = ( is_ssl() ? 'http' : 'https' ) . '://' . $src;
}
$src = esc_url_raw( $src );
if ( ! $src ) {
return;
}
$embedded = $wp_embed->run_shortcode( '[embed]' . $src . '[/embed]' );
$embedded = apply_filters( 'ayyash_render_embedded', $embedded, $src );
if ( ! $echo ) {
return $embedded;
}
if ( $embedded ) {
echo $embedded; // phpcs:ignore WordPress.Security.EscapeOutput
return true;
}
return false;
}
/**
* Gets 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 ayyash_get_first_instance_of_block( $block_name, $content = null, $instances = 1 ) {
if ( ! $content ) {
$content = get_the_content();
}
// Parse blocks in the content.
$blocks = parse_blocks( $content );
$instances_count = 0;
$blocks_content = '';
// Loop blocks.
foreach ( $blocks as $block ) {
// Sanity check.
if ( ! isset( $block['blockName'] ) ) {
continue;
}
// Check if this the block matches the $block_name.
// If the block ends with *, try to match the first portion.
/** @noinspection PhpLanguageLevelInspection */
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 ) {
// Add the block HTML.
$blocks_content .= render_block( $block );
// Increment count.
$instances_count++;
// Break the loop if the $instances count was reached.
if ( $instances_count >= $instances ) {
break;
}
}
}
if ( $blocks_content ) {
return apply_filters( 'the_content', $blocks_content ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound,WPThemeReview.CoreFunctionality.PrefixAllGlobals.NonPrefixedHooknameFound
}
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 void
*/
function ayyash_print_first_instance_of_block( $block_name, $content = null, $instances = 1 ) {
echo ayyash_get_first_instance_of_block( $block_name, $content, $instances ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Ayyash Post view Count
*/
if ( ! function_exists( 'ayyash_post_view_count' ) ) {
/**
* Ayyash post view count
*
* @return void
*/
function ayyash_post_view_count() {
if ( ! isset($_POST['nonce']) || wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), basename(__FILE__)) ) {
return;
}
$count_key = 'ayyash_post_views_count';
$post_id = intval( isset( $_POST['post_id'] ) ? sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : '' );
$view_count = get_post_meta( $post_id, $count_key, true );
$view_count = ( '' == $view_count ) ? 0 : $view_count;
$new_view_count = $view_count + 1;
if ( metadata_exists('post', $post_id, $count_key ) ) {
update_post_meta( $post_id, $count_key, $new_view_count );
} else {
add_post_meta( $post_id, $count_key, $new_view_count );
}
}
add_action('wp_ajax_ayyash_post_view_count', 'ayyash_post_view_count');
}
/**
* Ayyash Post Excerpt
*/
if ( ! function_exists( 'get_ayyash_excerpt' ) ) {
/**
* Ayyash Excerpt for Homepage.
*
* @return string
*/
function get_ayyash_excerpt( $post_id = '', $excerpt_length = '' ) {
//set excerpt length
if ( ! empty($excerpt_length ) ) {
$excerpt_length;
} else {
$excerpt_length = 30;
}
//set excerpt
$excerpt = '';
if ( ! empty($post_id) ) {
$excerpt = explode(' ', get_the_excerpt($post_id), $excerpt_length);
} else {
$excerpt = explode(' ', get_the_excerpt(), $excerpt_length);
}
if ( count($excerpt) >= $excerpt_length ) {
array_pop($excerpt);
$excerpt = implode(' ', $excerpt) . '...';
} else {
$excerpt = implode(' ', $excerpt);
}
return preg_replace('`\[[^\]]*\]`', '', $excerpt);
}
}
/**
* Ayyash blog home page date
*/
if ( ! function_exists( 'ayyash_date' ) ) {
/**
* Function Name : ayyash_date
* Function return Type : html
* Function Since : 1.0.0
*
* @return void
*/
function ayyash_date() {
if ( ayyash_get_mod('layout_blog_home_date') ) {
$date_format = ayyash_get_mod('layout_blog_home_date_format');
?>