Adding Input/Meta Box To Wordpress Page With Spellcheck Ability - php

Within Wordpress, I am attempting to add a text box to a page where users can paste data. Within this box I simply want to give them ability to spell check the pasted text, preferably using the built in wp_editor functionality.
I've tried adding code below to the page, however all wp_editor buttons are still present including 'add media':
<?php wp_editor( $content, $editor_id, $settings = array() ); ?>
Thank's in advance!

The wp_editor() function has many options. For instance, you can turn off the media insert buttons:
$settings = array( 'media_buttons' => false );
wp_editor( $content, $editor_id, $settings );
I don't think WordPress does spellchecking. Are you sure this isn't a function of your web browser or operating system?

Related

How to get the value of wp_editor()'s textarea

So i am trying to have a custom textarea where users can do things like bold text, add ul's,link tags and so on. For all of this I am using the wp_editor() function inside wordpress, like this.
$content = "";
$editor_id = "e_id";
$editor_settings = array(
'teeny' => true,
'editor_height' => 160,
'quicktags' => array( 'buttons' => 'strong,em,del,close' ),
'media_buttons' => false );
wp_editor( $content, $editor_id ,$editor_settings );
So everything such as adding links bolding text and so on works just fine.
My issue is accessing the text that was just typed into this field.
I tried accessing the text using JQuery, by alerting the value of the textarea/contenteditable area like so...
alert($("#e_id").val());
but each time the result is always an empty string and not the newly typed text.
How do I get a hold of the newly typed text
So while looking around on here I found a similar question related to the Wordpress wp_editor() function. Here
Apparently there is a special tinyMce function used to access wp_editor() or the tinyMce editor's text/content.
So using this inside inside my onSubmit handler:
tinyMCE.activeEditor.getContent()
I was able to get content or text that was entered into the wp_editor().
Also another good post on the subject.

enqueue tinymce editor in customizer

I'm having a hard time trying to make tiny mce editor work in the wordpress customizer.
It looks like just calling "wp_editor" from my WP_Customize_Control extension doesn't trigger loading of TinyMCE scripts in the customizer.
I've tried to load them manually like in this answer here: https://wordpress.stackexchange.com/questions/175307/tinymce-is-not-defined-when-not-using-wp-editor
and also tried with wp_enqueue_script('tiny-mce') but to no avail.
Here's my render method, nothing fancy:
public function render_content() {
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php
$settings = array(
'media_buttons' => false,
'quicktags' => false,
'teeny' => true
);
wp_editor($this->value(), $this->id, $settings );
?>
</label>
<?php
}
Any suggestions on how this should be done right?
I managed to make it work. See my answer with a conclusive code sample on workdpress.stackexchange.
p.s. I too resorted to calling do_action('admin_print_footer_scripts') which is obviously a dirty hack as it includes a bunch of other unnecessary scripts on the customizer page but does the trick awaiting for a more elegant solution..
Ok, found out one solution but using wp_editor in the customizer means opening pandora's box.
Adding do_action('admin_print_footer_scripts'); before creating the editor:
do_action('admin_print_footer_scripts');
wp_editor($this->value(), $this->id, $settings );
will have TinyMCE get rendered. However, issues that still remain are:
updates in the rich text box are saved to the corresponding textarea, however events like "changed" or "keyup" that the wp.customize is watching for to do the postMessage are not triggered by the rich editor but only when changing directly the textarea.
because of the above, the "Save" button will not get enabled.
artificial triggering of the "changed" and "keyup" events on the textarea are not caught by wp.customize, hence the update callbacks in the preview area are not called
once every several customizer loads the tinymce will not be rendered completely, probably due to the way the admin scripts are loaded
Therefore, after much digging on this topic I realized that the wp_editor is not yet ready to be used reliably in other areas than posts editing.

Error in buddypress when using wp_editor

Since none of plugin works with new wordpress and buddypress for rich text editor I have started to implement it myself manually directly into the theme.
After using wp_editor() I got the editor on my fourms and it is posting forums content well without issue. However when I am trying to edit forums post it is not loading any content into the text editor. I am using below code if anyone can help me.
$content = bp_the_topic_text();
$args = array(
'quicktags' => true,
'editor_class' => 'frontend',
'textarea_rows' => 5,
'tabindex' => 1
);
wp_editor( $content, 'topic_text', $args);
This doesnt load the forum post content just wonder. I have tested with the sting and just works fine it loads the string but not the actual content with the function. I dont know either this is the right function to get the content or not.
I am getting output like
I want show content in inside of editor.
Thanks a lot in advance.
bp_the_topic_text() echoes the value. It's a wrapper for bp_get_the_topic_text(), which returns the value. So you should do this instead:
$content = bp_get_the_topic_text();

WordPress, Parse Shortcode within Shortcode

I'm working on a site for a client that runs a social ransom style blog. This is where the user has to click one of the social media buttons to get access to the content.
However, she is now going to use the OnePress Social Locker Plugin for wordpress which works by wrapping the content in specific tags, like so:
[sociallocker] Content Here will Be Locked [/sociallocker]
At the moment she already has her own custom shortcode in place which works like this:
[socialLock url="http://example.com" text="Click here to view content"] Content here will be locked [/socialLock]
The problem is that she has over 2,300 pages on her blog and to change every single one indv. through the dashboard will take ages and this is not a by the hour pay contract.
I thought that I would be able to pass the current shortcode into the new one like so:
function parseShortcode_func( $atts ) {
$atts = shortcode_atts( array(
'link' => '',
'text' => 'default text'
), $atts );
return "[sociallocker] {$atts['text']} [/sociallocker]";
}
add_shortcode( 'socialLock', 'parseShortcode_func' );
However that just outputs
[sociallocker] Click here to view content [/sociallocker]
Has anyone got any ideas how to parse this second shortcode within a shortcode?
The do_shortcode() function will reparse your output string.
return do_shortcode("[sociallocker] {$atts['text']} [/sociallocker]");

Use TinyMCE on Custom Post Type without Content

I am trying to setup a custom post type in WordPress that contains a textarea that I want to turn into a TinyMCE WYSIWYG editor. The second-to-last post on this thread shows how to embed JavaScript that will call TinyMCE on the text editor. However, when I try to use it, I get a JavaScript error that tinyMCE is not defined.
It looks like the problem is that because the post type doesn't have content, the editor JavaScript (which includes the global tinyMCE object) isn't being included in the admin page. How do I include these scripts so that I can then access tinyMCE?
Thanks,
-Nate
Maybe you can use wp_editor. See other references in WordPress Answers.
For testing, I had the CPT defined without an editor: 'supports' => array( 'title', 'comments' ).
And used this Custom Meta Box:
add_action( 'add_meta_boxes', 'add_custom_box_so_14611445' );
function add_custom_box_so_14611445()
{
add_meta_box(
'sectionid_so_14611445',
__( 'Custom Editor' ),
'inner_custom_box_so_14611445',
'portfolio'
);
}
function inner_custom_box_so_14611445( $post )
{
echo wp_editor( '', 'editor_id_so_14611445', array() );
}

Categories