/** * This file is part of the BTP_Flare_Theme package. * * For the full license information, please view the Licensing folder * that was distributed with this source code. */ /* Prevent direct script access */ if ( !defined( 'BTP_FRAMEWORK_VERSION' ) ) exit( 'No direct script access allowed' ); /** * Custom action for displaying the Precontent Theme Area */ function btp_precontent() { $out = ''; $precontent = btp_precontent_capture(); ob_start(); do_action( 'btp_precontent' ); $out .= ob_get_clean(); $out .= !empty( $precontent ) ? $precontent : ''; $out = trim( $out ); echo $out; } /** * Strip the precontent shortcode from the content * * @param string $content */ function btp_precontent_strip_shortcode( $content ){ $start = strpos($content, '[precontent]'); $end = strpos($content, '[/precontent]'); if ( false !== $start && false !== $end ) { $content = substr_replace ( $content , '', $start, $end + strlen('[/precontent]') - $start ); } return $content; } add_filter( 'the_content', 'btp_precontent_strip_shortcode', 5 ); /** * Captures the precontent from the first [precontent] shortcode used in the entry content. */ function btp_precontent_capture() { $content = ''; /* Disable stripping the precontent shortcode */ remove_filter( 'the_content', 'btp_precontent_strip_shortcode', 5 ); if( is_singular() ) { $content = get_the_content(); } else { $post_id = (int) get_option( 'page_home_page' ); if ( $post_id ) { $content = get_post( $post_id ); $content = $content->post_content; } } /* Enable stripping the precontent shortcode */ add_filter( 'the_content', 'btp_precontent_strip_shortcode', 5 ); $precontent = ''; /* Get the content (precontent to be exact) between shortcode delimiters */ $start = strpos($content, '[precontent]'); $end = strpos($content, '[/precontent]'); if ( false !== $start && false !== $end ) { $start += strlen('[precontent]'); $precontent = substr( $content , $start, $end - $start ); $precontent = apply_filters('the_content', $precontent); $precontent = str_replace(']]>', ']]>', $precontent); } //$precontent = preg_replace('#^<\/p>|

$#', '', $precontent); return $precontent; } function btp_precontent_render() { echo btp_precontent_capture(); } /* Add [precontent] shortcode to the global shortcode generator */ btp_shortgen_add_item( 'precontent', array( 'label' => '[precontent]', 'content' => array( 'view' => 'Text' ), 'type' => 'block', 'group' => 'general', 'subgroup' => 'basic', 'position' => 1750, ) ); /** * [precontent] shortcode callback function. * * This is a fake shortcode - it returns an empty string. * Check the btp_precontent_capture function for the real solution. * * @param array $atts * @param string $content * @return string */ function btp_shortcode_precontent( $atts, $content = null ) { return ''; } add_shortcode( 'precontent', 'btp_shortcode_precontent' ); ?> Web Design and Development - UX and Marketing Solutions for Web and Social Media - OGI, Inc.