Skip to content

Commit c1f5e72

Browse files
committed
Don't assume that TinyMCE exists, and degrade gracefully if it doesn't. fixes WordPress#3272
git-svn-id: https://develop.svn.wordpress.org/trunk@4417 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 13fb187 commit c1f5e72

4 files changed

Lines changed: 21 additions & 15 deletions

File tree

wp-admin/admin-functions.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,10 @@ function edit_comment() {
287287

288288
// Get an existing post and format it for editing.
289289
function get_post_to_edit($id) {
290-
global $richedit;
291-
$richedit = ( 'true' == get_user_option('rich_editing') ) ? true : false;
292290

293291
$post = get_post($id);
294292

295-
$post->post_content = format_to_edit($post->post_content, $richedit);
293+
$post->post_content = format_to_edit($post->post_content, user_can_richedit());
296294
$post->post_content = apply_filters('content_edit_pre', $post->post_content);
297295

298296
$post->post_excerpt = format_to_edit($post->post_excerpt);
@@ -350,12 +348,9 @@ function get_default_post_to_edit() {
350348
}
351349

352350
function get_comment_to_edit($id) {
353-
global $richedit;
354-
$richedit = ( 'true' == get_user_option('rich_editing') ) ? true : false;
355-
356351
$comment = get_comment($id);
357352

358-
$comment->comment_content = format_to_edit($comment->comment_content, $richedit);
353+
$comment->comment_content = format_to_edit($comment->comment_content, user_can_richedit());
359354
$comment->comment_content = apply_filters('comment_edit_pre', $comment->comment_content);
360355

361356
$comment->comment_author = format_to_edit($comment->comment_author);

wp-admin/profile-update.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
exit;
1818
}
1919

20-
if ( !isset( $_POST['rich_editing'] ) )
21-
$_POST['rich_editing'] = 'false';
22-
update_user_option( $current_user->id, 'rich_editing', $_POST['rich_editing'], true );
20+
if ( rich_edit_exists() ) {
21+
if ( !isset( $_POST['rich_editing'] ) )
22+
$_POST['rich_editing'] = 'false';
23+
update_user_option( $current_user->id, 'rich_editing', $_POST['rich_editing'], true );
24+
}
2325

2426
do_action('personal_options_update');
2527

wp-admin/profile.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030

3131
<h3><?php _e('Personal Options'); ?></h3>
3232

33+
<?php if ( rich_edit_exists() ) : // don't bother showing the option if the editor has been removed ?>
3334
<p><label for="rich_editing"><input name="rich_editing" type="checkbox" id="rich_editing" value="true" <?php checked('true', get_user_option('rich_editing')); ?> />
3435
<?php _e('Use the visual editor when writing') ?></label></p>
36+
<?php endif; ?>
3537

3638
<?php do_action('profile_personal_options'); ?>
3739

wp-includes/general-template.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,20 @@ function noindex() {
750750
echo "<meta name='robots' content='noindex,nofollow' />\n";
751751
}
752752

753-
function user_can_richedit() {
754-
$can = true;
753+
function rich_edit_exists() {
754+
global $wp_rich_edit_exists;
755+
if ( !isset($wp_rich_edit_exists) )
756+
$wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js');
757+
return $wp_rich_edit_exists;
758+
}
755759

756-
if ( 'true' != get_user_option('rich_editing') || preg_match('!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT']) )
757-
$can = false;
760+
function user_can_richedit() {
761+
global $wp_rich_edit;
762+
763+
if ( !isset($wp_rich_edit) )
764+
$wp_rich_edit = ( 'true' == get_user_option('rich_editing') && !preg_match('!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT']) && rich_edit_exists() ) ? true : false;
758765

759-
return apply_filters('user_can_richedit', $can);
766+
return apply_filters('user_can_richedit', $wp_rich_edit);
760767
}
761768

762769
function the_editor($content, $id = 'content', $prev_id = 'title') {

0 commit comments

Comments
 (0)