tinymce init location script - wordpress

I'm trying to find a solution for this for weeks and I'm finding answers all
over the internet but I do not know where and how to add this very short script.
I want to have plain text paste enabled on my frontend wordpress tinymce.
So people say use this
tinymce.init({
plugins: "paste",
paste_as_text: true
});
But I don't know where to put this script in.
The class-wp-editor.php does not have any tinymce.init config that I can find.
Would be great if I can solve this.
Thanks

I would use
wp_editor()
with a shortcode.
tinymce is part of settings.
$settings = array( 'tinymce' => array('your_options') );
wp_editor($content, $editor_id, $settings);

Thank you for your respond.
Still I don't know how where to add this.
Do I need to add this to my function.php or a new .php file.
If so how can I make tinymce see this file?
This is the script I use to display the tinymce at the frontend.
With searching over the internet I added the 'paste as text' => true in,
but this does not help as the editor still paste in styled format.
Did I do this correct, if not, how to enable 'paste as text'?
<?php $cont = isset($post) ? $post->post_content : '';
wp_editor(wpautop(stripslashes($cont)),'post_content', array(
'paste_as_text' => true,
'textarea_name' => 'pack[post_content]',
'teeny' => 1, 'media_buttons' => 0,
'tinymce' => array('toolbar1' => 'bold,italic,underline,blockquote,strikethrough,bullist,link,unlink,media,mybutton'),
'quicktags' => false, 'textarea_rows' => 15)); ?>

Related

How to change URL of item in Wordpress dashboard in order to go directly to first post inside it

I created some custom fields for the Wordpress dashboard, for example:
functions.php
function create_field() {
register_post_type('field',
array(
'labels' => array(
'name' => 'Field',
'singular_name' => 'Field'
),
'public' => true,
'has_archive' => false,
'rewrite' => false,
'show_in_menu' => false,
'capability_type' => 'post',
'capabilities' => array(
'create_posts' => false
),
'map_meta_cap' => true,
)
);
}
add_action('init', 'create_field');
In some of them, only one post will be created. It will be continually edited and never deleted. So, what I want is to change de URL of this item in dashboard menu and go directly to this post inside it instead of showing the list of posts, because it will be no necessary.
For example, in the dashboard menu, when click in Products, instead of going to www.mywebsite.com/wp-admin/edit.php?post_type=products, I want it to go directly to the only post created inside it: www.mywebsite.com/wp-admin/post.php?post=24&action=edit.
Is that possible? I searched and tried a lot of things, since rewrite, different add_action functions, removing the item and trying to replace it and so on. I don't know exactly what else I can try for now.
I searched a little more without success. Unfortunately I had to use JavaScript, something I was avoiding, but solves it temporarily.
First, I used admin_enqueue_scripts action hook in functions.php to add JavaScript on the administration screens.
function admin_scripts() {
wp_enqueue_script( "", get_template_directory_uri() . "/scripts_admin.js", "", "", true );
}
add_action( "admin_enqueue_scripts", "admin_scripts" );
Then on my JavaScript I replaced the link hrefs:
// examples
document.querySelector("#menu-posts-products a").href = "post.php?post=10&action=edit";
document.querySelector("#menu-posts-contact a").href = "post.php?post=20&action=edit";
I still think there is a way to do it through Wordpress, maybe in the creation of Post Types. But for now, that solves it.

Using Code Snippets in Wordpress to remove a line of code from a plugin?

I want to remove a specific line of code from a plugin in WordPress. I can edit the plugin itself, but when it is updated it overwrites the changes I have done. I read that using the code snippet WordPress plugin I can have it always overwrite, regardless of updates.
If the line of code I want to be removed is the
'required'=>true
from the code below, how would I write that in the code snippet plugin? The plugin file I am editing is located at wp-store-locator/admin/class-metaboxes.php
`$meta_fields = array(
__( 'Location', 'wpsl' ) => array(
'address' => array(
'label' => __( 'Address', 'wpsl' ),
'required' => true
),`
Thanks so much

TinyMCE Visual Editor Won't Save, PlainText Does?

I have TinyMCE in my Wordpress plugin, and have been having a super irritating problem with TinyMCE. It will save edits made in plaintext mode but won't save edit made in Visual mode (and throws an error).
This is the code I use to create the TinyMCE textarea. I name the field correctly to save and load from options.php (which works when it's just a plain textarea).
$x_options = get_option('editbox');
/*HTML form fields*/
$rc_initial_data = ( isset( $x_options['fluid_body'] ) ) ?$x_options['fluid_body']:'';
$settings = array( 'wpautop' => true, 'textarea_name' => 'editbox[fluid_body]', 'quicktags' => true, 'tinymce' => true, 'quicktags' => array('buttons' => 'em,strong,link,block,ul,ol,li,p,close,spell,img') );
wp_editor( $rc_initial_data, 'fluid_body', $settings );
The error I get is this:
Can't create duplicate variable: 'typeMap'
The error is in wp-tinymce.php (which loads a .js file). I use multiple TinyMCE-enabled fields, but they are all named uniquely so the "duplicate" thing shouldn't be a problem (and isn't, if it's plaintext).
Any ideas why the Visual editor isn't working? Everything is the current version, Wordpress, jQuery, etc.

Adding wp_editor to custom WP widget

I want to add WP editor with TinyMCE to my custom text widget, but it won't show TinyMCE buttons it just shows textarea. When I test my code on page.php it works perfectly - editor shows with all the buttons and metabox. Can You please tell me what I'm doing wrong?EDITWidgets screenshot.Same code used in page.php screenshot
The code I use :
$settings = array(
'wpautop' => true,
'media_buttons' => false,
'textarea_name' => 'test-editor',
'textarea_rows' => get_option('default_post_edit_rows', 10),
'tabindex' => '',
'editor_css' => '',
'editor_class' => '',
'teeny' => true,
'dfw' => true,
'tinymce' => array(
'theme_advanced_buttons1' => 'bold,italic,underline'
),
'quicktags' => false
);
wp_editor( 'Text in editor', 'test-editor', $settings );
Looks like you need to find another WYSIWYG editor. Reading the Codex, there are two issues with your code:
The $editor_id
can only be composed of lower-case letters. No underscores, no hyphens. Anything else will cause the WYSIWYG editor to malfunction.
And this one that prevents the editor from working in a meta box
Once instantiated, the WYSIWYG editor cannot be moved around in the DOM. What this means in practical terms, is that you cannot put it in meta-boxes that can be dragged and placed elsewhere on the page.

Wordpress comment_form( ) won't accept my arguments

I'm trying to diligently follow what the codex says about modifying the appearance of the comments form (located here) but I can't get it to work. The default comments form appears despite my array of arguments that should change it.
In the template I have: comments_template('mycomments.php');
Then...
<?php
//inside my mycomments.php file
$comment_args = array (
'fields' => array('author', 'email'),
'must_log_in' => true,
'title_reply' => 'Review this product',
'label_submit' => 'Submit',
);
comment_form($comment_args, $post->ID); ?>
Am I doing something wrong?
I figured it out. There was nothing wrong with my arguments. Instead... I needed a / infront of the relative link to my customized comments template:
comments_template('/mycomments.php');
Moral of the story: If you're having trouble getting the template to work (at all), make sure you're actually loading the right template file!

Resources