HOME


Mini Shell 1.0
DIR: /home/depancom/www/depancomblogus/wp-content/themes/beautyspot/inc/lsvr-faq/
Upload File :
Current File : /home/depancom/www/depancomblogus/wp-content/themes/beautyspot/inc/lsvr-faq/actions.php
<?php

/**
 * GENERAL
 */

	// Set current post type
	add_filter( 'lsvr_beautyspot_current_post_type', 'lsvr_beautyspot_faq_set_current_post_type' );
	if ( ! function_exists( 'lsvr_beautyspot_faq_set_current_post_type' ) ) {
		function lsvr_beautyspot_faq_set_current_post_type( $post_type ) {

			if ( lsvr_beautyspot_is_faq() ) {
				return 'lsvr_faq';
			}
			return $post_type;

		}
	}

	// Document title
	add_filter( 'document_title_parts', 'lsvr_beautyspot_faq_document_title' );
	if ( ! function_exists( 'lsvr_beautyspot_faq_document_title' ) ) {
		function lsvr_beautyspot_faq_document_title( $title ) {

			if ( is_post_type_archive( 'lsvr_faq' ) ) {
				$title['title'] = sanitize_text_field( lsvr_beautyspot_get_faq_archive_title() );
			}
			return $title;

		}
	}


/**
 * CORE
 */

	// Set narrow layout
	add_filter( 'lsvr_beautyspot_narrow_layout_enable', 'lsvr_beautyspot_faq_narrow_layout_enable' );
	if ( ! function_exists( 'lsvr_beautyspot_faq_narrow_layout_enable' ) ) {
		function lsvr_beautyspot_faq_narrow_layout_enable( $enable ) {

			if ( ( is_singular( 'lsvr_faq' ) && 'narrow' === get_theme_mod( 'lsvr_faq_single_layout', 'default' ) ) ||
				( lsvr_beautyspot_is_faq() && ! is_singular( 'lsvr_faq' ) && 'narrow' === get_theme_mod( 'lsvr_faq_archive_layout', 'default' ) ) ) {
				return true;
			}

			return $enable;

		}
	}

	// Page title
	add_filter( 'lsvr_beautyspot_page_header_title', 'lsvr_beautyspot_faq_page_title' );
	if ( ! function_exists( 'lsvr_beautyspot_faq_page_title' ) ) {
		function lsvr_beautyspot_faq_page_title( $title ) {

			if ( is_post_type_archive( 'lsvr_faq' ) ) {
				return lsvr_beautyspot_get_faq_archive_title();
			} elseif ( is_tax( 'lsvr_faq_tag' ) ) {
				return sprintf( esc_html__( 'Tag: %s', 'beautyspot' ), single_term_title( '', false ) );
			}

			return $title;

		}
	}

	// Breadcrumbs
	add_filter( 'lsvr_beautyspot_add_to_breadcrumbs', 'lsvr_beautyspot_faq_breadcrumbs' );
	if ( ! function_exists( 'lsvr_beautyspot_faq_breadcrumbs' ) ) {
		function lsvr_beautyspot_faq_breadcrumbs( $breadcrumbs ) {

			if ( lsvr_beautyspot_is_faq() && ! is_post_type_archive( 'lsvr_faq' ) ) {
				return array(
					array(
						'url' => get_post_type_archive_link( 'lsvr_faq' ),
						'label' => lsvr_beautyspot_get_faq_archive_title(),
					),
				);
			}
			return $breadcrumbs;

		}
	}

	// Archive pre_get_posts actions
	add_action( 'pre_get_posts', 'lsvr_beautyspot_faq_archive_pre_get_posts' );
	if ( ! function_exists( 'lsvr_beautyspot_faq_archive_pre_get_posts' ) ) {
		function lsvr_beautyspot_faq_archive_pre_get_posts( $query ) {

			if ( ! is_admin() && $query->is_main_query() && ( $query->is_post_type_archive( 'lsvr_faq' ) ||
				$query->is_tax( 'lsvr_faq_cat' ) || $query->is_tax( 'lsvr_faq_tag' ) ) ) {

				// Posts per page
				if ( 0 === (int) get_theme_mod( 'lsvr_faq_archive_posts_per_page', 12 ) ) {
					$query->set( 'posts_per_page', 1000 );
				} else {
					$query->set( 'posts_per_page', esc_attr( get_theme_mod( 'lsvr_faq_archive_posts_per_page', 12 ) ) );
				}

				// Order
				if ( 'date_desc' == get_theme_mod( 'lsvr_faq_archive_order', 'default' ) ) {
					$query->set( 'order', 'DESC' );
					$query->set( 'orderby', 'date' );
				}
				elseif ( 'date_asc' == get_theme_mod( 'lsvr_faq_archive_order', 'default' )  ) {
					$query->set( 'order', 'ASC' );
					$query->set( 'orderby', 'date' );
				}
				elseif ( 'title_asc' == get_theme_mod( 'lsvr_faq_archive_order', 'default' )  ) {
					$query->set( 'order', 'ASC' );
					$query->set( 'orderby', 'title' );
				}
				elseif ( 'title_desc' == get_theme_mod( 'lsvr_faq_archive_order', 'default' )  ) {
					$query->set( 'order', 'DESC' );
					$query->set( 'orderby', 'title' );
				}
				elseif ( 'random' == get_theme_mod( 'lsvr_faq_archive_order', 'default' )  ) {
					$query->set( 'orderby', 'rand' );
				}

			}

		}
	}

	// Enable archive categories
	add_filter( 'lsvr_beautyspot_post_archive_categories_enable', 'lsvr_beautyspot_faq_archive_categories_enable' );
	if ( ! function_exists( 'lsvr_beautyspot_faq_archive_categories_enable' ) ) {
		function lsvr_beautyspot_faq_archive_categories_enable( $enabled ) {

			if ( lsvr_beautyspot_is_faq() && true === get_theme_mod( 'lsvr_faq_archive_categories_enable', true ) ) {
				return true;
			}

			return $enabled;

		}
	}

	// Get categories taxonomy
	add_filter( 'lsvr_beautyspot_post_archive_categories_taxonomy', 'lsvr_beautyspot_faq_archive_categories_taxonomy' );
	if ( ! function_exists( 'lsvr_beautyspot_faq_archive_categories_taxonomy' ) ) {
		function lsvr_beautyspot_faq_archive_categories_taxonomy( $taxonomy ) {

			if ( lsvr_beautyspot_is_faq() ) {
				return 'lsvr_faq_cat';
			}

			return $taxonomy;

		}
	}

	// Make posts on archive expandable
	add_filter( 'lsvr_beautyspot_faq_post_archive_class', 'lsvr_beautyspot_faq_archive_expandable_enable' );
	if ( ! function_exists( 'lsvr_beautyspot_faq_archive_expandable_enable' ) ) {
		function lsvr_beautyspot_faq_archive_expandable_enable( $class ) {

			if ( lsvr_beautyspot_is_faq() && true === get_theme_mod( 'lsvr_faq_archive_expandable_enable', true ) ) {
				return 'lsvr_faq-post-archive--is-expandable';
			}

			return $class;

		}
	}

	// Enable single post single navigation
	add_filter( 'lsvr_beautyspot_post_single_navigation_enable', 'lsvr_beautyspot_faq_single_post_navigation_enable' );
	if ( ! function_exists( 'lsvr_beautyspot_faq_single_post_navigation_enable' ) ) {
		function lsvr_beautyspot_faq_single_post_navigation_enable( $enabled ) {

			if ( lsvr_beautyspot_is_faq() && true === get_theme_mod( 'lsvr_faq_single_navigation_enable', true ) ) {
				return true;
			}

			return $enabled;

		}
	}

	// Sidebar position
	add_filter( 'lsvr_beautyspot_sidebar_position', 'lsvr_beautyspot_faq_sidebar_position' );
	if ( ! function_exists( 'lsvr_beautyspot_faq_sidebar_position' ) ) {
		function lsvr_beautyspot_faq_sidebar_position( $sidebar_position ) {

			// Is single
			if ( is_singular( 'lsvr_faq' ) ) {
				return get_theme_mod( 'lsvr_faq_single_sidebar_position', 'disable' );
			}

			// Is archive
			elseif ( lsvr_beautyspot_is_faq() ) {
				return get_theme_mod( 'lsvr_faq_archive_sidebar_position', 'disable' );
			}

			return $sidebar_position;

		}
	}

	// Sidebar ID
	add_filter( 'lsvr_beautyspot_sidebar_id', 'lsvr_beautyspot_faq_sidebar_id' );
	if ( ! function_exists( 'lsvr_beautyspot_faq_sidebar_id' ) ) {
		function lsvr_beautyspot_faq_sidebar_id( $sidebar_id ) {

			// Is single
			if ( is_singular( 'lsvr_faq' ) ) {
				return get_theme_mod( 'lsvr_faq_single_sidebar_id', 'lsvr-beautyspot-default-sidebar' );
			}

			// Is archive
			elseif ( lsvr_beautyspot_is_faq() ) {
				return get_theme_mod( 'lsvr_faq_archive_sidebar_id', 'lsvr-beautyspot-default-sidebar' );
			}

			return $sidebar_id;

		}
	}

?>