Skip to content

Instantly share code, notes, and snippets.

@cogdog
Created July 2, 2019 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cogdog/a857ea5d6a0435de7ba2ed2279e85758 to your computer and use it in GitHub Desktop.
Save cogdog/a857ea5d6a0435de7ba2ed2279e85758 to your computer and use it in GitHub Desktop.
Get Tinymce text editor contents
/* php form creation
<?php if ( trucollector_option('caption_field') == 's'):?>
<input id="wRichText" type="hidden" value="0">
<textarea name="wText" id="wText" rows="4" tabindex="4"><?php echo stripslashes( $wText );?></textarea><p style="font-size:0.8rem">To create hyperlinks use this shortcode<br /><code>[link url="http://www.themostamazingwebsiteontheinternet.com/" text="the coolest site on the internet"]</code><br />If you omit <code>text=</code> the URL will be the link text.</p>
<?php else:?>
<input id="wRichText" type="hidden" value="1">
<?php
// set up for inserting the WP post editor
$settings = array( 'textarea_name' => 'wText', 'editor_height' => '300', 'tabindex' => "5", 'media_buttons' => false, 'drag_drop_upload' => true);
wp_editor( stripslashes( $wText ), 'wTextHTML', $settings );
?>
<?php endif?>
/* js */
// flag for the editor type- set as hidden form variable
if ( $('#wRichText').val() == 1) {
// get content from tinymce editor
// using visual editor?
if ( $("#wp-wTextHTML-wrap").hasClass("tmce-active") ){
wtext = $('#wTextHTML_ifr').contents().find("html").html()
// using HTML editor
} else {
wtext = $('#wTextHTML').val();
}
} else {
// get content from textarea for plain caption
wtext = $('#wText').val();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment