Skip to content

Instantly share code, notes, and snippets.

@dxd5001
Created February 24, 2023 15:27
Show Gist options
  • Save dxd5001/bc36cf50ca1f2f645f85aa910bd9e265 to your computer and use it in GitHub Desktop.
Save dxd5001/bc36cf50ca1f2f645f85aa910bd9e265 to your computer and use it in GitHub Desktop.
Modify the edit function of BuddyPress Edit Activity (WordPress plugin)

Put this function in the functions.php of the theme activated.

<?php
/**
 * Modify the edit function of BuddyPress Edit Activity (made by @buddyboss).
 *
 * This function will hide the html source while editing the activity content
 * containing images uploaded with rtMedia (made by @rtcamp).
 *
 * @link https://wordpress.org/plugins/buddypress-edit-activity/
 * @link https://wordpress.org/plugins/buddypress-media/
 *
 * @param string $content
 * @return string $content
 */
function bea_hide_html_from_edit_textarea( $content ) {

	// Check if $content contains the word 'rtmedia'.
	$flag = strstr( $content, 'rtmedia' );
	if ( $flag ) {

		$matches = array();

		// Pull the text inside of 'rtmedia-activity-text' class out using regular expression.
		preg_match( '#<div class="rtmedia-activity-text">(.*)</div>#s', $content, $matches );

		// The 2nd array element of $matches is the raw text.
		$content = $matches[1];
	}

	return $content;
}
add_filter( 'bea_get_activity_content', 'bea_hide_html_from_edit_textarea' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment