=' ) ) ) { /** * Get global $fusion_settings object. * * @return object */ function fusion_get_fusion_settings() { return awb_get_fusion_settings(); } } /** * Returns an instance of the Fusion_Data_Framework class. * * @since 2.2.0 * @return Fusion_Data_Framework */ function fusion_data() { return Fusion_Data_Framework::init(); } if ( ! function_exists( 'fusion_get_option' ) ) { /** * Get Global Option or page option. * * @param string $option_name Global Option ID. * @param string $page_option Page option ID. * @param integer $post_id Post/Page ID. * @return string Global Option or page option value. */ function fusion_get_option( $option_name, $page_option = false, $post_id = false ) { $value = ''; $value_found = false; $id = Fusion::get_instance()->get_page_id(); $is_archive = false === $post_id ? ( false !== strpos( $id, 'archive' ) || false === $id ) : false !== strpos( $post_id, 'archive' ); $map = Fusion_Options_Map::get_option_map(); $edit_post = false; // Admin check for edit post screen. if ( is_admin() && false === $id && isset( $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $id = (int) sanitize_text_field( wp_unslash( $_GET['post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification $edit_post = true; } /** * Tweak for the "mobile_header_bg_color" option. */ if ( 'mobile_archive_header_bg_color' === $option_name && ( ! is_archive() || fusion_is_shop( $id ) ) ) { $option_name = 'mobile_header_bg_color'; } /** * Tweak for blog "page_title_bar". */ if ( 'page_title_bar' === $option_name && 'post' === get_post_type( $id ) ) { $option_name = 'blog_page_title_bar'; } if ( false === strpos( $option_name, '[' ) ) { $option_name_located = Fusion_Options_Map::get_option_name_from_theme_option( $option_name ); if ( is_array( $option_name_located ) ) { $value = []; foreach ( $option_name_located as $key => $option_id ) { $value[ $key ] = fusion_get_option( $option_id ); } } } /** * Get term options. * Overrides page-option & theme-option. */ if ( $is_archive ) { $tax_value = fusion_data()->term_meta( intval( $id ) )->get( $option_name ); if ( null !== $tax_value && '' !== $tax_value ) { $value_found = true; $value = $tax_value; } } $post_id = apply_filters( 'fusion_get_option_post_id', ( $post_id ) ? $post_id : $id ); // If $post_id is not set that means there is a call for a TO and it is still too early for post ID to be set. if ( false === $post_id ) { $skip = true; } else { $post_meta = fusion_data()->post_meta( $post_id ); // Make sure this is not an override that should not be happening. // See https://github.com/Theme-Fusion/Avada/issues/8122 for details. $skip = ( ( '' === $post_meta->get( 'header_bg_image[url]' ) && in_array( $option_name, [ 'header_bg_repeat', 'header_bg_full' ], true ) ) || ( '' === $post_meta->get( 'bg_image[url]' ) && ( 'bg_repeat' === $option_name || 'bg_full' === $option_name ) ) || ( '' === $post_meta->get( 'content_bg_image[url]', $post_id ) && in_array( $option_name, [ 'content_bg_repeat', 'content_bg_full' ], true ) ) ); } /** * Get page options. * Overrides theme-option. */ $get_page_option = apply_filters( 'fusion_should_get_page_option', ( is_singular() || fusion_is_shop( $post_id ) || ( is_home() && ! is_front_page() ) || $edit_post || ( false !== $post_id && ! $is_archive ) ) ); if ( ! $value_found && ! $skip && $get_page_option ) { // Get the page-option. $page_option = $post_meta->get( $option_name ); if ( 'default' !== $page_option && false !== $page_option && '' !== $page_option && null !== $page_option ) { $value_found = true; $value = $page_option; } // Tweak for sidebars options. $sidebars_options = [ 'pages_sidebar', 'pages_sidebar_2', 'posts_sidebar', 'posts_sidebar_2', 'portfolio_sidebar', 'portfolio_sidebar_2', 'woo_sidebar', 'woo_sidebar_2', 'ec_sidebar', 'ec_sidebar_2', 'ppbress_sidebar', 'ppbress_sidebar_2', ]; if ( '' === $page_option && in_array( $option_name, $sidebars_options, true ) ) { $value_found = true; $value = $page_option; } // Tweak for show_first_featured_image. if ( 'show_first_featured_image' === $option_name && '' === $page_option && 'avada_portfolio' !== get_post_type( $post_id ) ) { $value_found = true; $value = true; } } // Get the theme-option value if we couldn't find a value in page-options or taxonomy-options. if ( ! $value_found ) { /** * Get the Global Options. */ $option_name = Fusion_Options_Map::get_option_name( $option_name, 'theme' ); $value = fusion_get_theme_option( $option_name ); } // Tweak values for the "page_title_bar" option - TOs and POs have different formats. if ( 'page_title_bar' === $option_name || 'blog_page_title_bar' === $option_name ) { $value = strtolower( $value ); $value = 'yes' === $value ? 'bar_and_content' : $value; $value = 'yes_without_bar' === $value ? 'content_only' : $value; $value = 'no' === $value ? 'hide' : $value; } // Tweak values for the "page_title_bar_bs" option - TOs and POs have different formats. if ( 'page_title_bar_bs' === $option_name ) { $value = strtolower( $value ); $value = 'searchbar' === $value ? 'search_box' : $value; } /** * Apply mods for options. */ if ( is_string( $option_name ) && isset( $map[ $option_name ] ) && isset( $map[ $option_name ]['is_bool'] ) && true === $map[ $option_name ]['is_bool'] ) { return ( '1' === $value || 1 === $value || true === $value || 'yes' === $value ); } return apply_filters( 'fusion_get_option', $value, $option_name, $page_option, $post_id ); } } if ( ! function_exists( 'fusion_get_theme_option' ) ) { /** * Gets a theme-option value. * * @since 2.0 * @param string|array $option The option we want to get. If we use an array, then the 2nd arg is the subset. * @param string $subset A subset of the option. * @return mixed */ function fusion_get_theme_option( $option = '', $subset = '' ) { if ( is_string( $option ) && false !== strpos( $option, '[' ) ) { $option = explode( '[', str_replace( ']', '', $option ) ); } if ( is_array( $option ) ) { $subset = ( isset( $option[1] ) && '' === $subset ) ? $option[1] : $subset; $option = $option[0]; } if ( '' !== $subset ) { return ( class_exists( 'Avada' ) ) ? Avada()->settings->get( $option, $subset ) : fusion_library()->get_option( $option, $subset ); } return ( class_exists( 'Avada' ) ) ? Avada()->settings->get( $option ) : fusion_library()->get_option( $option ); } } if ( ! function_exists( 'fusion_get_page_option' ) ) { /** * Get page option value. * * @param string $page_option ID of page option. * @param integer $post_id Post/Page ID. * @return mixed Value of page option. */ function fusion_get_page_option( $page_option, $post_id = null ) { if ( ! $post_id ) { $post_id = Fusion::get_instance()->get_page_id(); } // Allow post ID to be filtered depending on page_option. $post_id = apply_filters( 'fusion_get_page_option_id', $post_id, $page_option ); // Allow override which returns early. $override = apply_filters( 'fusion_get_page_option_override', null, $post_id, $page_option ); if ( ! is_null( $override ) ) { return $override; } if ( $page_option && $post_id ) { return fusion_data()->post_meta( $post_id )->get( $page_option ); } return false; } } if ( ! function_exists( 'fusion_render_rich_snippets_for_pages' ) ) { /** * Render the full meta data for blog archive and single layouts. * * @param boolean $title_tag Set to true to render title rich snippet. * @param bool $author_tag Set to true to render author rich snippet. * @param bool $updated_tag Set to true to render updated rich snippet. * @return string HTML markup to display rich snippets. */ function fusion_render_rich_snippets_for_pages( $title_tag = true, $author_tag = true, $updated_tag = true ) { ob_start(); include locate_template( 'templates/pages-rich-snippets.php' ); $rich_snippets = ob_get_clean(); return str_replace( [ "\t", "\n", "\r", "\0", "\x0B" ], '', $rich_snippets ); } } if ( ! function_exists( 'fusion_render_post_metadata' ) ) { /** * Render the full meta data for blog archive and single layouts. * * @param string $layout The blog layout (either single, standard, alternate or grid_timeline). * @param string $settings HTML markup to display the date and post format box. * @return string */ function fusion_render_post_metadata( $layout, $settings = [] ) { $html = ''; $author = ''; $date = ''; $metadata = ''; $settings = ( is_array( $settings ) ) ? $settings : []; if ( is_search() ) { $search_meta = array_flip( fusion_library()->get_option( 'search_meta' ) ); $default_settings = [ 'post_meta' => empty( $search_meta ) ? false : true, 'post_meta_author' => isset( $search_meta['author'] ), 'post_meta_date' => isset( $search_meta['date'] ), 'post_meta_cats' => isset( $search_meta['categories'] ), 'post_meta_tags' => isset( $search_meta['tags'] ), 'post_meta_comments' => isset( $search_meta['comments'] ), 'post_meta_type' => isset( $search_meta['post_type'] ), ]; } else { $default_settings = [ 'post_meta' => fusion_library()->get_option( 'post_meta' ), 'post_meta_author' => fusion_library()->get_option( 'post_meta_author' ), 'post_meta_date' => fusion_library()->get_option( 'post_meta_date' ), 'post_meta_cats' => fusion_library()->get_option( 'post_meta_cats' ), 'post_meta_tags' => fusion_library()->get_option( 'post_meta_tags' ), 'post_meta_comments' => fusion_library()->get_option( 'post_meta_comments' ), 'post_meta_type' => false, ]; } $settings = wp_parse_args( $settings, $default_settings ); $post_meta = fusion_data()->post_meta( get_queried_object_id() )->get( 'post_meta' ); // Check if meta data is enabled. if ( ( $settings['post_meta'] && 'no' !== $post_meta ) || ( ! $settings['post_meta'] && 'yes' === $post_meta ) ) { // For alternate, grid and timeline layouts return empty single-line-meta if all meta data for that position is disabled. if ( in_array( $layout, [ 'alternate', 'grid_timeline' ], true ) && ! $settings['post_meta_author'] && ! $settings['post_meta_date'] && ! $settings['post_meta_cats'] && ! $settings['post_meta_tags'] && ! $settings['post_meta_comments'] && ! $settings['post_meta_type'] ) { return ''; } // Render post type meta data. if ( $settings['post_meta_type'] ) { $post_type = get_post_type_object( get_post_type() ); if ( $post_type ) { $post_type = $post_type->labels->singular_name; } else { $post_type = ''; } $metadata .= ''; $metadata .= '|'; } // Render author meta data. if ( $settings['post_meta_author'] ) { ob_start(); the_author_posts_link(); $author_post_link = ob_get_clean(); // Check if rich snippets are enabled. if ( fusion_library()->get_option( 'disable_date_rich_snippet_pages' ) && fusion_library()->get_option( 'disable_rich_snippet_author' ) ) { /* translators: The author. */ $metadata .= sprintf( esc_html__( 'By %s', 'Avada' ), '' . $author_post_link . '' ); } else { /* translators: The author. */ $metadata .= sprintf( esc_html__( 'By %s', 'Avada' ), '' . $author_post_link . '' ); } $metadata .= '|'; } else { // If author meta data won't be visible, render just the invisible author rich snippet. $author .= fusion_render_rich_snippets_for_pages( false, true, false ); } // Render the updated meta data or at least the rich snippet if enabled. if ( $settings['post_meta_date'] ) { $metadata .= fusion_render_rich_snippets_for_pages( false, false, true ); $date_format = fusion_library()->get_option( 'date_format' ); $date_format = $date_format ? $date_format : get_option( 'date_format' ); $formatted_date = get_the_time( $date_format ); $date_markup = '' . $formatted_date . '|'; $metadata .= apply_filters( 'fusion_post_metadata_date', $date_markup, $formatted_date ); } else { $date .= fusion_render_rich_snippets_for_pages( false, false, true ); } // Render rest of meta data. // Render categories. if ( $settings['post_meta_cats'] ) { $post_type = get_post_type(); $taxonomies = [ 'avada_portfolio' => 'portfolio_category', 'avada_faq' => 'faq_category', 'product' => 'product_cat', 'tribe_events' => 'tribe_events_cat', ]; ob_start(); if ( 'post' === $post_type ) { the_category( ', ' ); } elseif ( 'page' !== $post_type && isset( $taxonomies[ $post_type ] ) ) { the_terms( get_the_ID(), $taxonomies[ $post_type ], '', ', ' ); } $categories = ob_get_clean(); if ( $categories ) { /* translators: The categories list. */ $metadata .= ( $settings['post_meta_tags'] ) ? sprintf( esc_html__( 'Categories: %s', 'Avada' ), $categories ) : $categories; $metadata .= '|'; } } // Render tags. if ( $settings['post_meta_tags'] ) { ob_start(); the_tags( '' ); $tags = ob_get_clean(); if ( $tags ) { /* translators: The tags list. */ $metadata .= '|'; } } // Render comments. if ( $settings['post_meta_comments'] && 'grid_timeline' !== $layout ) { ob_start(); comments_popup_link( esc_html__( '0 Comments', 'Avada' ), esc_html__( '1 Comment', 'Avada' ), esc_html__( '% Comments', 'Avada' ) ); $comments = ob_get_clean(); $metadata .= '' . $comments . ''; } // Render the HTML wrappers for the different layouts. if ( $metadata ) { $metadata = $author . $date . $metadata; if ( 'single' === $layout ) { $html .= '
'; } elseif ( in_array( $layout, [ 'alternate', 'grid_timeline' ], true ) ) { $html .= ''; } else { $html .= '' ); } } else { // All other posts with custom excerpt. $content = '
' . do_shortcode( get_the_excerpt( $post->ID ) ) . '
'; } } else { // All other posts (with and without tag in the contents). // HTML tags should be stripped. if ( $strip_html ) { $content = wp_strip_all_tags( get_the_content( '{{read_more_placeholder}}' ), '' ); // Strip out all attributes. $content = preg_replace( '/<(\w+)[^>]*>/', '<$1>', $content ); $content = str_replace( '{{read_more_placeholder}}', $read_more, $content ); } else { // HTML tags remain in excerpt. $content = get_the_content( $read_more ); } $pattern = get_shortcode_regex(); $content = preg_replace_callback( "/$pattern/s", 'fusion_extract_shortcode_contents', $content ); // tag is used in the post. if ( false !== strpos( $post->post_content, '' ) ) { $content = apply_filters( 'the_content', $content ); $content = str_replace( ']]>', ']]>', $content ); if ( $strip_html ) { $content = do_shortcode( $content ); } } } // Limit the contents to the $limit length. if ( ! has_excerpt( $post->ID ) || 'product' === $post->post_type ) { // Check if the excerpting should be char or word based. if ( 'characters' === fusion_get_option( 'excerpt_base' ) ) { $content = mb_substr( $content, 0, $limit ); $content .= $read_more; } else { // Excerpting is word based. $content = explode( ' ', $content, $limit + 1 ); if ( count( $content ) > $limit ) { array_pop( $content ); $content = implode( ' ', $content ); $content .= $read_more; } else { $content = implode( ' ', $content ); } } if ( $strip_html ) { $content = '
' . $content . '
'; } else { $content = apply_filters( 'the_content', $content ); $content = str_replace( ']]>', ']]>', $content ); } $content = do_shortcode( $content ); } return fusion_force_balance_tags( $content ); } } if ( ! function_exists( 'fusion_get_content_stripped_and_excerpted' ) ) { /** * Get the content of the post, strip it and apply any changes required to the excerpt first. * * @since 2.1.1 * @param int $excerpt_length The length of our excerpt. * @param string $content The content. * @return string The stripped and excerpted content. */ function fusion_get_content_stripped_and_excerpted( $excerpt_length, $content ) { $pattern = get_shortcode_regex(); $content = preg_replace_callback( "/$pattern/s", 'fusion_extract_shortcode_contents', $content ); $content = explode( ' ', $content, $excerpt_length + 1 ); if ( $excerpt_length < count( $content ) ) { array_pop( $content ); } $content = implode( ' ', $content ); $content = preg_replace( '~(?:\[/?)[^/\]]+/?\]~s', '', $content ); // Strip shortcodes and keep the content. $content = str_replace( ']]>', ']]>', $content ); $content = strip_tags( $content ); // phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags $content = str_replace( [ '"', "'" ], [ '"', ''' ], $content ); $content = trim( $content ); return $content; } } if ( ! function_exists( 'fusion_extract_shortcode_contents' ) ) { /** * Extract text contents from all shortcodes for usage in excerpts. * * @param array $m The text. * @return string The shortcode contents */ function fusion_extract_shortcode_contents( $m ) { global $shortcode_tags; // Setup the array of all registered shortcodes. $shortcodes = array_keys( $shortcode_tags ); $no_space_shortcodes = [ 'fusion_dropcap' ]; $omitted_shortcodes = [ 'fusion_code', 'fusion_imageframe', 'fusion_slide', 'fusion_syntax_highlighter' ]; // Extract contents from all shortcodes recursively. if ( in_array( $m[2], $shortcodes, true ) && ! in_array( $m[2], $omitted_shortcodes, true ) ) { $pattern = get_shortcode_regex(); // Add space to the excerpt by shortcode, except for those who should stick together, like dropcap. $space = ' '; if ( in_array( $m[2], $no_space_shortcodes, true ) ) { $space = ''; } $content = preg_replace_callback( "/$pattern/s", 'fusion_extract_shortcode_contents', rtrim( $m[5] ) . $space ); return $content; } // Allow [[foo]] syntax for escaping a tag. if ( '[' === $m[1] && ']' === $m[6] ) { return substr( $m[0], 1, -1 ); } return $m[1] . $m[6]; } } /** * Returns the excerpt length for portfolio posts. * * @since 4.0.0 * @param string $page_id The id of the current page or post. * @return string/boolean The excerpt length for the post; false if full content should be shown. **/ function fusion_get_portfolio_excerpt_length( $page_id = '' ) { $excerpt_length = false; if ( 'excerpt' === fusion_get_option( 'portfolio_archive_content_length', 'portfolio_content_length', $page_id ) ) { // Determine the correct excerpt length. if ( fusion_get_page_option( 'portfolio_excerpt', $page_id ) ) { $excerpt_length = fusion_get_page_option( 'portfolio_excerpt', $page_id ); } else { $excerpt_length = fusion_library()->get_option( 'portfolio_archive_excerpt_length' ); } } elseif ( ! $page_id && 'excerpt' === fusion_get_option( 'portfolio_archive_content_length' ) ) { $excerpt_length = fusion_library()->get_option( 'portfolio_archive_excerpt_length' ); } return $excerpt_length; } if ( ! function_exists( 'fusion_link_pages' ) ) { /** * Pages links. * * @since 2.2.0 * @param array $args An array of arguments we want to pass to the wp_parse_args function. * @return void */ function fusion_link_pages( $args = '' ) { wp_link_pages( wp_parse_args( $args, [ 'before' => '