'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_taxonomy_archive_cat_layout' );
} elseif ( class_exists( 'WooCommerce' ) && is_product_tag() ) {
$position = ayyash_get_mod( 'woocommerce_taxonomy_archive_tag_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 ) ) {
?>
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');
?>