文件操作 - conditionals.php
返回文件管理
返回主菜单
删除本文件
文件: /storage/v12552/jimbrandstatter/public_html/wp-content/themes/Total/inc/functions/conditionals.php
编辑文件内容
<?php defined( 'ABSPATH' ) || exit; /*-------------------------------------------------------------------------------*/ /* [ Table of contents ] /*-------------------------------------------------------------------------------*/ # General # Portfolio # Staff # Testimonials # Header # Footer # WooCommerce # WPBakery # Elementor /*-------------------------------------------------------------------------------*/ /* [ General ] /*-------------------------------------------------------------------------------*/ /** * Check if current site is dev environment. */ function wpex_is_dev_environment(): bool { $site = site_url(); $chunks = explode( '.', $site ); if ( 1 === count( $chunks ) ) { return true; } if ( in_array( end( $chunks ), [ 'local', 'dev', 'wp', 'test', 'example', 'localhost', 'invalid', 'staging', ] ) ) { return true; } return preg_match( '/^[0-9\.]+$/', $site ); } /** * Check if a specific customizer section is enabled. */ function wpex_has_customizer_panel( $section ): bool { $disabled_panels = (array) get_option( 'wpex_disabled_customizer_panels' ); return ! ( $disabled_panels && in_array( $section, $disabled_panels ) ); } /** * Check if responsiveness is enabled. */ function wpex_is_layout_responsive(): bool { return (bool) apply_filters( 'wpex_is_layout_responsive', true ); } /** * Check if the post edit links should display on the page. * * @todo rename to wpex_has_retina_support */ function wpex_is_retina_enabled(): bool { return ( get_theme_mod( 'image_resizing', true ) && get_theme_mod( 'retina', false ) ); } /** * Check if metadata exists. */ function wpex_has_post_meta( $key = '' ): bool { return (bool) get_post_meta( wpex_get_current_post_id(), $key, true ); } /** * Check if google services are disabled. */ function wpex_disable_google_services(): bool { $check = wp_validate_boolean( get_theme_mod( 'disable_gs', false ) ); return (bool) apply_filters( 'wpex_disable_google_services', $check ); } /** * Check if comments should display or not. */ function wpex_show_comments(): bool { if ( post_password_required() || ( ! comments_open() && get_comments_number() < 1 ) ) { $check = false; } else { $check = true; } /** * Filters whether comments should display or not. * * @param bool $check */ $check = apply_filters( 'wpex_show_comments', $check ); return $check; } /** * Check if a post has media (used for entry classes) * * @todo rename to wpex_has_post_media */ function wpex_post_has_media( $post = '', $deprecated = false ): bool { $post = get_post( $post ); $type = get_post_type( $post ); $check = false; if ( $type ) { switch ( $type ) { case 'post': $check = (bool) wpex_blog_entry_media_type(); break; case 'portfolio': $check = (bool) wpex_portfolio_entry_media_type(); break; case 'staff': $check = (bool) wpex_staff_entry_media_type(); break; default: $check = (bool) wpex_cpt_entry_media_type(); break; } } /** * Filter check if a post has media or not. * * @param bool $check True if post has media, false if it doesnt. * @param int $post_id Current post we are checking. */ $check = (bool) apply_filters( 'wpex_post_has_media', $check, $post->ID ); return $check; } /** * Check if a post has a redirection. */ function wpex_has_post_redirection( $post_id = '' ): bool { return (bool) wpex_get_custom_permalink(); } /** * Check if the post edit links should display on the page. */ function wpex_has_post_edit(): bool { if ( ! get_theme_mod( 'edit_post_link_enable', true ) ) { return false; // return if disabled completely via theme settings. } // If not singular or in front-end editor we can bail completely. if ( ! is_singular() || wpex_vc_is_inline() ) { return false; } // Not needed for these woo commerce pages. if ( totaltheme_is_integration_active( 'woocommerce' ) && ( is_cart() || is_checkout() ) ) { return false; } return (bool) apply_filters( 'wpex_has_post_edit', true ); } /** * Check if the next/previous links should display. */ function wpex_has_next_prev(): bool { if ( ! is_singular() ) { return false; } // Get current post type. $post_type = get_post_type(); // Not needed for pages or attachments. if ( in_array( $post_type, [ 'page', 'attachment', 'templatera', 'elementor_library', 'wpex_templates' ] ) ) { return false; } // Enabled by default. $check = true; // WooCommerce check. if ( totaltheme_is_integration_active( 'woocommerce' ) && is_singular( 'product' ) && is_woocommerce() ) { $check = get_theme_mod( 'woo_next_prev', true ); } // We use "blog" for the post post type mod. if ( 'post' === $post_type ) { $post_type = 'blog'; } // Check if enabled for specific post type. $check = get_theme_mod( "{$post_type}_next_prev", $check ); if ( totaltheme_is_integration_active( 'post_types_unlimited' ) ) { $ptu_check = wpex_get_ptu_type_mod( $post_type, 'next_prev' ); if ( isset( $ptu_check ) ) { $check = $ptu_check; } } // Sanitize. $check = wp_validate_boolean( $check ); // Apply filters. $check = apply_filters( 'wpex_has_next_prev', $check, $post_type ); return (bool) $check; } /** * Check if the readmore button should display. * * @todo fix "blog_exceprt" typo. */ function wpex_has_readmore(): bool { $check = true; if ( post_password_required() ) { $check = false; } elseif ( 'post' === get_post_type() && ! str_contains( get_the_content(), 'more-link' ) && ! get_theme_mod( 'blog_exceprt', true ) ) { $check = false; } return (bool )apply_filters( 'wpex_has_readmore', $check ); } /** * Check if the breadcrumbs is enabled. */ function wpex_has_breadcrumbs(): bool { $check = wp_validate_boolean( get_theme_mod( 'breadcrumbs', true ) ); $post_id = wpex_get_current_post_id(); if ( $post_id && $meta = get_post_meta( $post_id, 'wpex_disable_breadcrumbs', true ) ) { if ( 'on' === $meta ) { $check = false; } elseif ( 'enable' === $meta ) { $check = true; } } if ( is_front_page() ) { $check = false; } /** * Filters whether breadcrumbs are enabled or not. * * @param bool $check */ $check = (bool) apply_filters( 'wpex_has_breadcrumbs', $check ); return $check; } /** * Check if current page has a sidebar. */ function wpex_has_sidebar( $post_id = '' ): bool { if ( in_array( wpex_content_area_layout( $post_id ), [ 'left-sidebar', 'right-sidebar' ], true ) ) { $check = true; } else { $check = false; } /** * Filters if the current post has a sidebar or not. * * @param boolean $check * @param int $post_id */ $check = (bool) apply_filters( 'wpex_has_sidebar', $check, $post_id ); return $check; } /** * Returns site frame border width. */ function wpex_has_site_frame_border(): bool { return (bool) get_theme_mod( 'site_frame_border', false ); } /** * Check if Google Services are enabled. */ function wpex_has_google_services_support(): bool { return ! wpex_disable_google_services(); } /** * Check if gallery lightbox is enabled. */ function wpex_gallery_is_lightbox_enabled( $post_id = '' ) { if ( ! $post_id ) { $post_id = wpex_get_current_post_id(); } if ( 'on' === get_post_meta( $post_id, '_easy_image_gallery_link_images', true ) ) { return true; } return false; } /** * Check if the custom wp gallery output is supported. * * @todo rename to wpex_has_custom_wp_gallery. */ function wpex_custom_wp_gallery_supported(): bool { if ( totaltheme_is_integration_active( 'elementor' ) ) { $check = false; } else { $check = wp_validate_boolean( get_theme_mod( 'custom_wp_gallery_enable', true ) ); } /** * Filters whether the theme should override the default post_gallery shortcode output. * * @param bool $check. */ $check = (bool) apply_filters( 'wpex_custom_wp_gallery_supported', $check ); return $check; } /** * Checks if the current post is part of a post series. */ function wpex_is_post_in_series(): bool { return ( taxonomy_exists( 'post_series' ) && get_the_terms( get_the_id(), 'post_series' ) ); } /** * Check if a post has terms/categories. * * This function is used for the next and previous posts so if a post is in a category it * will display next and previous posts from the same category. * * @todo rename to wpex_has_post_terms() */ if ( ! function_exists( 'wpex_post_has_terms' ) ) { function wpex_post_has_terms( $post_id = '', $post_type = '' ): bool { $check = has_term( '', wpex_get_post_primary_taxonomy() ); /** * Check if the current post has terms. * * @param bool $check */ $check = (bool) apply_filters( 'wpex_post_has_terms', $check ); return $check; } } /** * Check if current user has social profiles defined. */ function wpex_author_has_social( $user = '' ) { if ( ! $user ) { global $post; $user = ! empty( $post->post_author ) ? $post->post_author : ''; } if ( ! $user ) { return; } $profiles = wpex_get_user_social_profile_settings_array(); foreach ( $profiles as $k => $v ) { if ( get_the_author_meta( 'wpex_' . $k, $user ) ) { return true; // we only need 1 to validate } } } /** * Check if an attachment exists. */ function wpex_attachment_exists( $attachment = '' ): bool { return ( 'attachment' === get_post_type( $attachment ) ); } /*-------------------------------------------------------------------------------*/ /* [ Portfolio ] /*-------------------------------------------------------------------------------*/ /** * Checks if the portfolio post type is enabled. */ function wpex_is_total_portfolio_enabled(): bool { return totaltheme_call_static( 'Portfolio\Post_Type', 'is_enabled' ); } /** * Checks if on a theme portfolio taxonomy archive. */ function wpex_is_portfolio_tax(): bool { if ( ! is_tax() || ! totaltheme_call_static( 'Portfolio\Post_Type', 'is_enabled' ) ) { return false; } $check = ( is_tax( [ 'portfolio_category', 'portfolio_tag' ] ) && ! is_search() ); /** * Filters if the current page is a portfolio taxonomy archive or not. * * @param bool $check */ $check = (bool) apply_filters( 'wpex_is_portfolio_tax', $check ); return $check; } /*-------------------------------------------------------------------------------*/ /* [ Staff ] /*-------------------------------------------------------------------------------*/ /** * Checks if the Staff post type is enabled. */ function wpex_is_total_staff_enabled(): bool { return totaltheme_call_static( 'Staff\Post_Type', 'is_enabled' ); } /** * Checks if on a theme staff taxonomy archive. */ function wpex_is_staff_tax(): bool { if ( ! is_tax() || ! totaltheme_call_static( 'Staff\Post_Type', 'is_enabled' ) ) { return false; } $check = ( is_tax( [ 'staff_category', 'staff_tag' ] ) && ! is_search() ); /** * Filters if the current page is a staff taxonomy archive or not. * * @param bool $check */ $check = (bool) apply_filters( 'wpex_is_staff_tax', $check ); return $check; } /*-------------------------------------------------------------------------------*/ /* [ Testimonials ] /*-------------------------------------------------------------------------------*/ /** * Checks if the portfolio post type is enabled. */ function wpex_is_total_testimonials_enabled(): bool { return totaltheme_call_static( 'Testimonials\Post_Type', 'is_enabled' ); } /** * Checks if on a theme testimonials taxonomy archive. */ function wpex_is_testimonials_tax(): bool { if ( ! is_tax() || ! totaltheme_call_static( 'Testimonials\Post_Type', 'is_enabled' ) ) { return false; } $check = ( is_tax( [ 'testimonials_category', 'testimonials_tag' ] ) && ! is_search() ); /** * Filters if the current page is a staff taxonomy archive or not. * * @param bool $check */ $check = (bool) apply_filters( 'wpex_is_testimonials_tax', $check ); return $check; } /*-------------------------------------------------------------------------------*/ /* [ Header ] /*-------------------------------------------------------------------------------*/ /** * Check if the header style is in dev mode..4 */ function wpex_has_dev_style_header() { return ( 'dev' === totaltheme_call_static( 'Header\Core', 'style' ) ); } /** * Check if the header style is not in dev mode..4 */ function wpex_hasnt_dev_style_header() { return ! wpex_has_dev_style_header(); } /*-------------------------------------------------------------------------------*/ /* [ Footer ] /*-------------------------------------------------------------------------------*/ /** * Check if footer builder is enabled. */ function wpex_has_custom_footer() { return ! empty( wpex_footer_builder_id() ); } /*-------------------------------------------------------------------------------*/ /* [ WooCommerce ] /*-------------------------------------------------------------------------------*/ /** * Checks if on the WooCommerce shop page. */ function wpex_is_woo_shop(): bool { return function_exists( 'is_shop' ) && is_shop() && totaltheme_is_integration_active( 'woocommerce' ); } /** * Check if WooCommerce default output should be disabled. * * @todo rename to wpex_has_woo_archive_loop. */ function wpex_woo_archive_has_loop() { $check = true; if ( get_theme_mod( 'woo_shop_disable_default_output', false ) && wpex_is_woo_shop() && ! is_search() ) { $check = false; } /** * Checks if the WooCommerce shop has the default loop enabled. * * @param bool $check */ $check = (bool) apply_filters( 'wpex_woo_archive_has_loop', $check ); return $check; } /** * Checks if on a WooCommerce tax. */ if ( ! function_exists( 'wpex_is_woo_tax' ) ) { function wpex_is_woo_tax(): bool { if ( ! totaltheme_is_integration_active( 'woocommerce' ) ) { return false; // important check since we use Woo only functions. } $check = false; if ( is_product_category() || is_product_tag() ) { $check = true; } if ( is_tax() && function_exists( 'taxonomy_is_product_attribute' ) ) { $tax_obj = get_queried_object(); if ( is_object( $tax_obj ) && ! empty( $tax_obj->taxonomy ) ) { $is_product_attribute = taxonomy_is_product_attribute( $tax_obj->taxonomy ); if ( $is_product_attribute ) { $check = true; } } } /** * Checks if the current page is a WooCommerce taxonomy archive. * * @param bool $check */ $check = apply_filters( 'wpex_is_woo_tax', $check ); return (bool) $check; } } /** * Checks if on singular WooCommerce product post. */ function wpex_is_woo_single(): bool { return function_exists( 'is_woocommerce' ) && is_singular( 'product' ) && is_woocommerce(); } /** * Check if product is in stock. */ function wpex_woo_product_instock() { if ( 'yes' !== get_option( 'woocommerce_manage_stock', 'yes' ) ) { return true; } global $product; if ( ! $product || ( $product && $product->is_in_stock() ) ) { return true; } } /*-------------------------------------------------------------------------------*/ /* [ WPBakery ] @todo move to Integration\WPBakery\Helpers /*-------------------------------------------------------------------------------*/ /** * Check if user is currently editing in front-end editor mode. */ function wpex_vc_is_inline(): bool { return (bool) totaltheme_call_static( 'Integration\WPBakery\Helpers', 'is_frontend_edit_mode' ); } /*-------------------------------------------------------------------------------*/ /* [ Elementor ] @todo move to Integration\Elementor\Helpers /*-------------------------------------------------------------------------------*/ /** * Check if an elementor theme builder location exists for a specific location. */ function wpex_elementor_location_exists( string $location ): bool { return function_exists( 'elementor_location_exits' ) && elementor_location_exits( $location, true ); } /** * Check if user is currently editing in front-end editor mode. * * Note: This function works only at init >= 0 */ function wpex_elementor_is_preview_mode(): bool { return ( class_exists( 'Elementor\Plugin' ) && is_object( \Elementor\Plugin::$instance->preview ) && is_callable( [ \Elementor\Plugin::$instance->preview, 'is_preview_mode' ] ) && \Elementor\Plugin::$instance->preview->is_preview_mode() ); }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件