2

As you already know, WordPress manipulates posts, even if you write everything in Text mode. (replacing line breaks with \r\n 's , converting single quotes into double quotes etc.)

I know this is good for helping us not to mess things up, however, in my case, I want to put HTML codes inside my post -both <code> and </code> tags , and some HTML directly-.

so I want to make sure what I see in Text mode (or install an HTML mode somehow) , so that What I See is What I Get, in terms of HTML :)

Maybe a better explanation for what I want is this :

What I write in "add new post" window should be exactly equal to what is printed between <div class='entry-content'> and </div>.

Any tips for this?

Should I change my theme? Or a plugin for tinymce?

p.s.:

I know single quotes should be escaped for database, but I want to preserve line breaks, html tags etc. So please tell me there is a way other than writing directly into the database.

  • Is there any particular reason that the TinyMCE editor built into WordPress core isn't working for you? – Chip Bennett Sep 30 '13 at 14:08
  • @ChipBennett Yes, it sometimes strips my p tags, and always removes my line breaks (in text mode). I mean, the line breaks I make in text mode, I switch to visual, and back to text, they are gone. All my articles become a single line. – jeff Sep 30 '13 at 14:12
  • The problem is not the HTML editor, or the TinyMCE editor, but rather switching between the two editors. The WordPress post editor is intended to be used either as text or HTML, but not both. Switching between the two will introduce problems, such as the ones you're experiencing. – Chip Bennett Sep 30 '13 at 14:30
  • possible duplicate of Wordpress automatically adding "&nbsp;"? – Chip Bennett Sep 30 '13 at 14:32
  • As a naive user, I think that the switching should be some kind of live preview. Or instead there should be a different functionality for that. anyway, the best solution for me is to disable the "visual editor", or the visual mess-up-per – jeff Sep 30 '13 at 20:09
1

I have decided that the best solution is to just disable the visual editor, from Users -> Your Profile -> Disable visual editor when writing.

0

get_user_meta() is a wrapper for get_metadata(). In case this gets triggered to question if a user can use the Rich Editor, you can disable it with that call.

<?php
/**
 * Plugin Name: (#116210) Disable RichEdit by User or Role
 * Author:      Franz Josef Kaiser <wecodemore@gmail.com>
 */
defined( 'ABSPATH' ) OR exit;

add_filter( 'get_user_metadata', 'wpse116210VisualEditorDisabled', 20, 4 );
function wpse116210VisualEditorDisabled( $enabled, $object_id, $meta_key, $single ) {
    if ( ! is_admin() )
        return $enabled;

    // Conditional switch for different post types
    if ( 'post' === get_current_screen()->post_type )
    {
        $user = wp_get_current_user();
        // Check here if you want *that* user/role to be enabled/disabled.
        $enabled = FALSE;
    }

    return $enabled;
}

Another option might be to use the WP_Role#has_cap check (in case it's used there). It has a filter as well: 'role_has_cap'

<?php
/**
 * Plugin Name: (#116210) Disable RichEdit by Role
 * Author:      Franz Josef Kaiser <wecodemore@gmail.com>
 */
defined( 'ABSPATH' ) OR exit;

add_filter( 'role_has_cap', 'wpse116210RoleHasCap' );
function wpse116210RoleHasCap( $allCaps, $checkedCap, $roleName )
{
    $role = get_role( $roleName );
    // Do your check if you want to allow it. Return *boolean*.

    return $allCaps[ $checkedCap ];
}
0

IIRC this is the user meta/caps filter:

<?php
/**
 * Plugin Name: (#116210) Disable RichEdit for some post types
 * Author:      Franz Josef Kaiser <wecodemore@gmail.com>
 */
defined( 'ABSPATH' ) OR exit;

add_filter( 'user_can_richedit', function( $enabled ) {
    if ( ! is_admin() )
        return $enabled;

    // Conditional switch for different post types
    // If you want to check against multiple post types, use in_array()
    return 'post' === get_current_screen()->post_type;
}

If you want to globally disable it for all post types, you can use the following shortcut:

<?php
/**
 * Plugin Name: (#116210) Disable RichEdit for some post types
 * Author:      Franz Josef Kaiser <wecodemore@gmail.com>
 */
defined( 'ABSPATH' ) OR exit;
add_filter( 'user_can_richedit', '__return_false' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.