tinymce in activity replies and comments
-
So far i know, this stopped to work correctly recently (search the forum). Something is going wrong with JS and the what’s new textarea. In fact, it doesn’t become a real wp-editor when used inside BP…
Hi!
I have the same “problem” and I am very interested!How did you manage the integration of the editor for βwhatβs new postβ?
Sweeny
The ultimate tutorial to add wp_editor to What’s New textarea (on Site, Members and Group Activities pages).
Warning
The What’s New feature was never intended to publish posts or formatted text. It was imagined for brief announcement or instant conversation. That’s why this textarea is texturized and doesn’t allow much HTML tags. It is also ajaxified and need the original BP ID to work.
You will use it at your own risk.The following trick will let you remove the existing textarea from the template and replace it with a custom wp_editor. And it will be very customized ! For example, you will not have the visual tab, but only his HTML version, similar to the one you see on this forum for example.
Required:
BuddyPress activated
a working child theme
some understanding of HTML and php grammarThis trick was succesfully tested on a single install with WP 4.6, BP 2.6.2 and a Twenty Sixteen child theme.
Start !
Read from here how to remove the textarea in post-form.phpThe code to remove is line 40 and looks like this:
<textarea class="bp-suggestions" name="whats-new" id="whats-new" cols="50" rows="10" <?php if ( bp_is_group() ) : ?>data-suggestions-group-id="<?php echo esc_attr( (int) bp_get_current_group_id() ); ?>" <?php endif; ?> ><?php if ( isset( $_GET['r'] ) ) : ?>@<?php echo esc_textarea( $_GET['r'] ); ?> <?php endif; ?></textarea>
You replace it by:
<?php $content = ''; $editor_id = 'whats-new'; wp_editor( $content, $editor_id ); ?>
As the visual edit tab doesn’t work, you must deactivate it. In your child-theme functions.php, add this:
add_filter( 'user_can_richedit' , '__return_false', 50 );
And that’s it !
If you want also rich edit for activity comments, which i didn’t recommand for sites who have many comments, you can use the same technique as above, with some more settings. Note that each comment has is own ID and that each comment editor should also have an unique ID.
First, you need to remove the textarea from (child-theme/buddypress/)activity/entry.php
You remove this:
<textarea id="ac-input-<?php bp_activity_id(); ?>" class="ac-input bp-suggestions" name="ac_input_<?php bp_activity_id(); ?>"></textarea>
and replace it by<?php $id = bp_get_activity_id(); $content = ''; $editor_id = 'ac-input-'. $id; $settings = array( 'textarea_name' => 'ac_input_'. $id, 'editor_class' => 'ac-input bp-suggestions' ); wp_editor( $content, $editor_id, $settings ); ?>
With Twenty Sixteen, i first couldn’t see the Post Update button and the option selector. I got it with this little CSS adjustment (in child-theme/style.css).
div#whats-new-options { display: block!important;}
Function reference: wp_editor.
@danbp Thanks for the reply.. I got this working with “text editor” on both post (what’s new) & comment section, but just wondering what prevents those forms from allowing “visual editor” – as it remains unclickable. Is it something to do with filters on buddypress or the problem comes from within wordpress? I’d just want “add media” and “bold font” button on the visual switch.
If you can point me the files I can edit, that would be wonderful.. I looked around activity filters & bp-core but I’d want to confirm from your end about this before experimenting it or messing up the wrong files.
Thanks
Hi, glad it works for you.
The visual editor use TinyMCE wich comes with his own ID and class. That works with WP, but not with BP who use his own id’s and JS on activity page.
Tweaking JS files is delicate and that’s why i said “deactivate the visual tab”. You should use the filter i indicated to remove it completely (so nobody would be tempted to click it).
But if you’re comfortable with JS, feel free to do it. But without any warranty (outside some headeache) about the final result as it will be very tricky to do.The media uploader is usually reserved to site admin, editors and authors when they post on the blog from backend. In our case, adding some styling possibilities to the what’s new content from frontend, is slightly different.
Imagine all your xxx.xxxx members accessing to the media library without any control each time they write something! That’s a big security risk, because subscribers (wich is the default BP users level) could access to a part of your backend and also to your server.
If you need full publication rights, create authors and let them publish real blog posts. But don’t use the what’s new form to replace this (complex) bloging functionnality.
The text tab has already a bold button (
b
– the first one, on the left ).
And you can embed links to images using theimg
button or embed different medias like video simply by copy/pasting a youtube link or other allowed services.Take also in mind that the default form comes without any style buttons. This trick add some.
Guess you have to work with this compromise. IMO better as nothing, no ? Avoid reinventing the wheel ! Stay simple and your site will remain operable.
Hey, @danbp Thanks for the long and detailed response.
I’m fully aware of what you’re trying to convey the risk factors on this.. But as my requirements are different, I’ve completely disabled the media library and allowed access the users to each individual gallery only (negating the access of other’s files).. I’ve uploaded images hosted on sub-domains that completely separate from the main site.
All the activities that takes place on the site are on the front end.. The back end wp administrator dashboard are disabled for editing ( of course they are enabled for updating plugins & adding pages occasionally) as most of the pages are done in custom-template.. No admin or author level privileges are created on the site – just the subscriber as it’s mainly a networking site.. The idea that attaching the media button gives lots of flexibility to the users to resize the images or review them in the content area itself before they can post the activity.. Unless it’s a forums or community sites, for a networking sites, leaving alone with html codes or text editors may be (perhaps) discouraging impression for the social users.
I’m glad that you pointed out it’s more of a wordpress thing than buddypress.. I’ll have a look at the possibility of getting it work and let you know.
Thanks.
You’re welcome.
Did you have any tips on editing that js file?
I know this is one of those “don’t try this at home kids” type of things, however I think I’m a trained professional, just not at js. I’ve spent I long time removing the media buttons and other problematic buttons. I used your old trick and had everything working. However I really needed images so I put everything aside I went with a BP gallery plugin. It was safe (or as safe as you can get), but it still saved photos on our sever.
I was going to scrap Activity altogether and go back to good old bbPress, but then I found this:
https://codecanyon.net/item/dw-tinymce-imgur-upload-wordpress-plugin/16386641
It instantly uploads user images to imgur seamlessly. All my dreams where answered. No more bloated hard drives with user images and no need to leave the site to upload to a image host.
Sadly (as you know), when I put the editor code back in place the trick no longer worked.
Sorry for the long story. The great thing about WP & BP (most of the time) is you can expand beyond what was intended. Making thing “idiot proof” is not going to stop idiots, just innovation.
Anyway if you have some tips that would be great. And you may want to check out that plugin (I have nothing to do with it).
Best,
Big Kahuna Burger πHi @bigkahunaburger,
thanks for the burger! π
Like you, I’m not a JS specialist so i can’t help you more with that. πBut i can suggest you an alternative solution by using MediaPress. It appears that this plugin allows you to add mediabuttons by shortcode to the Status form (and not only there…).
Take a little moment to study this option, completely or to check the code how the author implemented it.
Thanks @danbp
That’s kind of like the BuddyBoss Media plugin we almost used.
It still has the problem of storing images on your server.
I wish I knew what they changed to make the old trick stop working. Maybe then I could reverse engineer it.
I could able to implement rich text editor in the comment section by adding/modifying some js files but for the replies and threaded comments it’s a huge task.. To be honest, buddypress are not meant to be work as smooth in threaded comments (at least as of now). I will update If I can successfully implement tinymce in both comments and replies section. Cheers!
Hi @jbboro3
I had replies working before, but now has the same issues as the main activity editor:
https://buddypress.org/support/topic/add-tinymce-to-activity-post-reply-form/
@bigkahunaburger you must be talking about plain text tinymce editor (just like you see here in the editor)?? If this is the one you’re talking about, then you can do it without problem (even in the replies).. What I’m talking about is rich text editor where you can see the image conversion (from code) within the editor text area itself like in the wp backend. This will allow direct image insertion in the post form along with some few other basic features like bold, italic, indentation and listing – which is a basis of WYSIWYG. This ensures that instead of dealing with the codes, you will see directly preview of live output within the content itself which is very important when you’re building social networking website.. As you’d know social networkers doesn’t understand codes and it looks very messy (unless it’s a forums like here).. Check for example quora.com.. But to be aware that, while working with media button in tinymce, it comes huge responsibilites with storing the images and restricting others from accessing the gallery of other users.. If you can allocate space for storing images in your subdomains, and restrict others from accessing gallery of fellow users – it could be a juicy UI to bet on..
@jbboro3 Oh wait that is the code just for the tinymce. I’m trying to remember if I ever had the rich text editor working for comments.
Here is the code I was using for what’s new (its modified slightly for the plugin I posted above):
function bpfr_whats_new_tiny_editor() { $dwqa_tinymce_css = apply_filters( 'dwqa_editor_style', DWQA_URI . 'templates/assets/css/editor-style.css' ); $toolbar1 = apply_filters( 'dwqa_tinymce_toolbar1', 'bold,italic,underline,|,' . 'bullist,numlist,blockquote,|,' . 'link,unlink,|,' . 'image,code,|,'. 'spellchecker,fullscreen,dwqaCodeEmbed,|,' ); wp_editor( isset( $_GET['r'] ) ? '@' . esc_attr( $_GET['r'] ) : '', 'whats-new', array( 'textarea_name' => 'whats-new', 'editor_class' => 'whats-new-mce', 'editor_height' => 200, 'media_buttons' => false, 'quicktags' => false, 'tinymce' => array( 'toolbar1' => $toolbar1, 'toolbar2' => '', 'content_css' => $dwqa_tinymce_css ) ) ); } add_action( 'whats_new_textarea', 'bpfr_whats_new_tiny_editor' );
I need to do some digging too see if I have something for the rich editor in comments. I tired so many different things trying to get it working I forgot where I left off.
That code is for plain text tinymce in “post form”.. This will render in the post form but not in the comment form (though without rich text editor you can implement it easily anywhere). The problem is only with rich text editor which you can insert images, bold font, italic etc without displaying codes (as in text form editor).. When you are on to threaded forum (multi-level commenting) you will have to figure out three things here.. 1st Post form (the one you posted above), 2nd comment form (replies to the original post) and the replies form (replies to the comments which is threaded in nature)..
The one I’m talking about is – I could able to implement first two steps i.e, post and comment form in rich text editor format, but still figuring out the last format i.e., replies which is messing up the things.. The thing is that buddypres is implementing both comment and replies in the same ids which needs to be corrected to be able to implement with tinymce and also the AJAX on the replies collapse behavior which doesn’t support with the buddypress right now
@jbboro3 Just to save some time can we refer to the “rich text editor” as the “visual tab” and tinymce as “text tab”? Just so people don’t get confused. π
If you have a solution for the “What’s new” post form and the comments that allows you to use the “visual tab” I can test it out and see if I can figure out anything for nested replies.
@djpaul Any ideas on how to get this working?
- You must be logged in to reply to this topic.
jbboro3
@jbboro3
8 years, 3 months ago
As we know, right now we can easily get tinymce in “what’s new post” but I’m unable to get it correct when it comes to activity comments and replies.. couldn’t exactly figure out the correct $editor_id.. I tried with some of them but didn’t render well..
Please someone advice..
Thanks