' .'
tag if no other tags.
$caption = str_ireplace ( array ( '
', '
' ), '', $caption );
if ( $caption == strip_tags ( $caption, '
' ) ) { $caption = '
' . $caption . '
'; } return '', '', $content ); //$content = preg_replace( array ( '/
<\/p>/', '/
<\/p>/', '/
/', '/
<\/p>/' ), '', $content ); */ // Remove all comments $content = preg_replace( '//', '', $content ); // Remove all
tags that are empty or only have whitespace between them $content = preg_replace( '|(\s)*
|', '', $content ); return $content; } endif; // end ! function_exists /** * Add custom section to WordPress post/page editor */ if ( ! function_exists( 'xsbf_add_custom_box' ) ) : add_action( 'add_meta_boxes', 'xsbf_add_custom_box' ); function xsbf_add_custom_box() { $screens = array( 'post', 'page' ); foreach ( $screens as $screen ) { add_meta_box( 'xsbf_options', __( 'Additional Post / Page Options', 'flat-bootstrap' ), 'xsbf_inner_custom_box', $screen, 'normal', 'high' ); } } endif; // end ! function_exists /** * Prints the box content. * * @param WP_Post $post The object for the current post/page. */ if ( ! function_exists( 'xsbf_inner_custom_box' ) ) : function xsbf_inner_custom_box( $post ) { // Add an nonce field so we can check for it later. wp_nonce_field( 'xsbf_inner_custom_box', 'xsbf_inner_custom_box_nonce' ); // Retrieve existing value from the database and use the value for the form. $value = get_post_meta( $post->ID, '_subtitle', true ); echo ' '; echo ''; // For posts, also add option to set to full-width if ( 'post' == $post->post_type ) { $value = get_post_meta( $post->ID, '_fullwidth', true ); $checked = $value ? 'checked' : ''; echo ''; echo ' '; } //endif 'post' } endif; // end ! function_exists /** * When the post is saved, saves our custom data. * * @param int $post_id The ID of the post being saved. */ if ( ! function_exists( 'xsbf_save_postdata' ) ) : add_action( 'save_post', 'xsbf_save_postdata' ); function xsbf_save_postdata( $post_id ) { /* * We need to verify this came from the our screen and with proper authorization, * because save_post can be triggered at other times. */ // Check if our nonce is set. if ( ! isset( $_POST['xsbf_inner_custom_box_nonce'] ) ) return $post_id; $nonce = $_POST['xsbf_inner_custom_box_nonce']; // Verify that the nonce is valid. if ( ! wp_verify_nonce( $nonce, 'xsbf_inner_custom_box' ) ) return $post_id; // If this is an autosave, our form has not been submitted, so we don't want to do anything. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id; // Check the user's permissions. if ( 'page' == $_POST['post_type'] ) { if ( ! current_user_can( 'edit_page', $post_id ) ) return $post_id; } else { if ( ! current_user_can( 'edit_post', $post_id ) ) return $post_id; } /* OK, its safe for us to save the data now. */ $post_subtitle = sanitize_text_field( $_POST['xsbf_post_subtitle'] ); update_post_meta( $post_id, '_subtitle', $post_subtitle ); if ( 'post' == $_POST['post_type'] ) { $post_fullwidth = $_POST['xsbf_post_template'] ? true : false; update_post_meta( $post_id, '_fullwidth', $post_fullwidth ); } } endif; // end ! function_exists /** * Add Bootstrap class for thumbnails to user profile pics (avatars) */ if ( ! function_exists( 'xsbf_get_avatar' ) ) : add_filter ('get_avatar', 'xsbf_get_avatar', 10, 5); function xsbf_get_avatar ( $avatar, $id_or_email, $size, $default, $alt ) { $avatar = str_replace ( "avatar-{$size}", "avatar-{$size} thumbnail", $avatar ); //$avatar = str_replace ( "avatar-{$size}", "avatar-{$size} img-circle", $avatar ); return $avatar; } endif; // end ! function_exists /** * Add Bootstrap thumbnail class to gallery images */ add_filter('wp_get_attachment_link', 'xsbf_attachment_link_class', 10, 1); //Add Bootstrap thumnail class function xsbf_attachment_link_class($html) { $html = str_replace('class="attachment-', 'class="thumbnail attachment-' , $html); return $html; } /** * Adjust the number of columns for the footer based on how many widgets were added. * This is Bootstrap-specific using col-sm-n. */ if ( ! function_exists( 'xsbf_footer_filter' ) ) : add_filter('xsbf_footer' , 'xsbf_footer_filter' , 10 , 1); function xsbf_footer_filter( $footer ) { // Use PHP to parse the DOM structure and count the number of widgets. Note that we // have to suppress errors because libxml doesn't recognize html5 tags yet. It still // processes them just fine, though. $dom = new DOMDocument('1.0', 'utf-8'); libxml_use_internal_errors(true); $dom->loadHTML( $footer ); libxml_clear_errors(); $asides = $dom->getElementsByTagName('aside'); $num_widgets = $asides->length; // Loop through each widget and modify the Bootstrap grid, depending on how many foreach ($asides as $counter => $aside) { //if ( $num_widgets >= 4 ) { if ( $num_widgets == 4 ) { $aside->setAttribute( 'class', str_ireplace( 'col-sm-4', 'col-sm-6 col-lg-3 clearfix', $aside->getAttribute('class') ) ); // For the above to work, we need to add a clearing div after the 2nd column if ( $counter == 2 ) { $cleardiv = $dom->createElement('div'); $cleardiv->setAttribute('class', 'clearfix hidden-lg'); $aside->parentNode->insertBefore($cleardiv, $aside); } } elseif ( $num_widgets == 3 ) { //$aside->setAttribute( 'class', str_ireplace( 'col-sm-4', 'col-sm-4', $aside->getAttribute('class') ) ); } elseif ( $num_widgets == 2 ) { $aside->setAttribute( 'class', str_ireplace( 'col-sm-4', 'col-sm-6', $aside->getAttribute('class') ) ); } else { $aside->setAttribute( 'class', str_ireplace( 'col-sm-4', 'col-sm-12', $aside->getAttribute('class') ) ); } //endif } //endforeach // Save what we just changed and return the value $footer = $dom->saveHTML(); //ini_set ( 'display_errors', 0 ); //TEST return $footer; } endif; // end ! function_exists /* * Add some "quicktag" buttons to the WordPress HTML editor. Note these don't appear in * the visual editor, only when in "text" (HTML) mode. */ if ( ! function_exists( 'xsbf_add_quicktags' ) ) : add_action( 'admin_print_footer_scripts', 'xsbf_add_quicktags' ); function xsbf_add_quicktags() { if (wp_script_is('quicktags')){ ?>