I'm encountering a situation where on one page/component only, a BuddyPress script is printing to the page as text. This happens on the "Change Cover Image" tab of a user's profile, and I don't see this issue anywhere else at all.
I've tried googling every combination of keywords I can think of and have tried posting on the BuddyPress support forums, but haven't been able to get any help at all over there.
Maybe someone here might be able to provide me with a bit of insight?
Here's a screenshot of what the page looks like.
The template file looks like:
<?php
/**
* BuddyPress Cover Images main template.
*
* This template is used to inject the BuddyPress Backbone views
* dealing with cover images.
*
* It's also used to create the common Backbone views.
*
* @since 2.4.0
*
* @package BuddyPress
* @subpackage bp-attachments
*/
?>
<div class="bp-cover-image"></div>
<div class="bp-cover-image-status"></div>
<div class="bp-cover-image-manage"></div>
<?php bp_attachments_get_template_part( 'uploader' ); ?>
<script id="tmpl-bp-cover-image-delete" type="text/html">
<# if ( 'user' === data.object ) { #>
<p><?php _e( "If you would like to delete your current cover image but not upload a new one, please use the delete Cover Image button.", 'buddypress' ); ?></p>
<p><a class="button edit" id="bp-delete-cover-image" href="#"><?php esc_html_e( 'Delete My Cover Image', 'buddypress' ); ?></a></p>
<# } else if ( 'group' === data.object ) { #>
<p><?php _e( "If you would like to remove the existing group cover image but not upload a new one, please use the delete group cover image button.", 'buddypress' ); ?></p>
<p><a class="button edit" id="bp-delete-cover-image" href="#"><?php esc_html_e( 'Delete Group Cover Image', 'buddypress' ); ?></a></p>
<# } else { #>
<?php do_action( 'bp_attachments_cover_image_delete_template' ); ?>
<# } #>
</script>
<?php do_action( 'bp_attachments_cover_image_main_template' ); ?>
And all of that actually appears twice on the page itself, once in an inline script tag and then once as article text as shown in the screenshot above.
I don't get any javascript errors that I can see in my console.
I'd really appreciate anyone that might be able to help me troubleshoot this.
Thanks!
Well, I had this issue for about a week, but only nine hours after posting this question here I randomly stumbled upon the source of the problem. I was pretty sure it was going to be a script load order issue, but no -- it was this snippet from my child theme's functions.php file that was intended to remove empty HTML tags:
add_filter('the_content', 'remove_empty_tags_recursive', 20, 1);
function remove_empty_tags_recursive ($str, $repto = NULL) {
$str = force_balance_tags($str);
if (!is_string ($str) || trim ($str) == '')
return $str;
return preg_replace (
'~\s?<p>(\s| )+</p>\s?~',
!is_string ($repto) ? '' : $repto,
$str
);
}