Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Add tinymce to Activity Post Form

  • @stefanolusetti-1

    Participant

    I,
    i need to add a rich text editor in activity stream instead of the actual textarea (id= #wats-new-textarea”)
    I have WordPress 3.9.1 and Buddypress 2.0.1.

    At the moment i change the file \mytheme\activity\post-form.php:

    I replace the textarea with the wp_editor:

    
    wp_editor( bp_get_activity_content_body(),'whats-new', array(
        'media_buttons' => true,
        'textarea_rows' => '200',
    	'teeny' => true,
        'quicktags' => array('buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close')
        )
    );
     
    

    But i can’t make it work. The submit button doesn’t appear.

Viewing 4 replies - 1 through 4 (of 4 total)
  • @danbp

    Participant

    hi @stefanolusetti-1,

    here we go !
    You already copied buddypress/bp-templates/bp-legacy/buddypress/activity/post-form.php to the right place in your child-theme:
    /child-theme/buddypress/activity/post-form.php

    Excellent! Here’s more.

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

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

    The above function use the new drag_drop_upload support introduced in WP 3.9

    First we go to remove the whats new textarea from this file, around line 29, 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.

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

    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 !

    @henrywright

    Moderator

    @danbp, just to mention, $editor_id is fussy about hyphens. See here. And contrary to the advice in that Codex article, I’ve also found $editor_id dislikes underscores. Best bet is to use lowercase letters only.

    @danbp

    Participant

    hi @henrywright,

    you’re right, but buddypress use his own js to handle this textarea, and use what-new as ID and as name.
    If you remove the hyphen, the editor doesn’t work correctly because js couldn’t recognize it.

    Of course i tested with 2013, but also with 2014 and 3 other themes containing heavy js effect without any conflict. I think if BP is working without any issue with a given theme, the snippet can be used.

    If you have a better solution, i would be glad to learn.

    @henrywright

    Moderator

    I was going on both my own experience with the editor and the note in the Codex article I referenced above. My own experience wasn’t with the what’s new form so if it’s working for the what’s new form then completely disregard what I said above 🙂

    Edit: And you’re right about BuddyPress JavaScript needing the #whats-new selector. I can see it’s used a couple of times inside buddypress.js.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Add tinymce to Activity Post Form’ is closed to new replies.
Skip to toolbar