Pages

Showing posts with label editor. Show all posts
Showing posts with label editor. Show all posts

How to Add tinymce editor to Activity Post Form in buddypress

Add a rich text editor/tinymce editor in activity stream instead of the actual textarea (id= #wats-new-textarea”)

copy the file with the path to the theme/child theme

buddypress/bp-templates/bp-legacy/buddypress/activity/post-form.php to the

right place in your child-theme/theme:

/child-theme/buddypress/activity/post-form.php

Great!

forward to the here!

We’re going to use the wp_editor function to accomplish this task.

Note: if we want use wp_editor then wp_editor can replace any textarea. This means that if you use these function, that you have to remove the original textarea first.


First, we need to remove the whats new textarea from this file(/child-theme/buddypress/activity/post-form.php) , around line 36, and replace it with a custom action hook: whats_new_textarea


Before
<div id="whats-new-textarea">
   <textarea name="whats-new" id="whats-new" cols="50" rows="10"><?php if ( isset( $_GET['r'] ) ) : ?>@<?php echo esc_textarea( $_GET['r'] ); ?> <?php endif; ?></textarea>
</div>
After
<div id="whats-new-textarea">  
   ?php do_action( 'whats_new_textarea' ); ?>    
</div> 
save the file.

Now go to /plugins/bp-custom.php (if the file doesn’t exist, you have to create it) and paste in this snippet.

 <?php

function bpfr_whats_new_tiny_editor() {
// deactivation of the visual tab, so user can't play with template styles
add_filter ( 'user_can_richedit' , create_function ( '$a' , 'return false;' ) , 50 );

// building the what's new textarea
if ( isset( $_GET['r'] ) ) :
$content = esc_textarea( $_GET['r'] );
endif;

// adding tinymce tools
$editor_id = 'whats-new';
$settings = array(
'textarea_name' => 'whats-new',
'teeny' => true,
'media_buttons' => true,
'drag_drop_upload' => true,
'quicktags' => array(
'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close'));

// get the editor
wp_editor( $content, $editor_id, $settings );
}
add_action( 'whats_new_textarea', 'bpfr_whats_new_tiny_editor' ); ?>



Save and enjoy it! :)




  




 



Popular Posts