Make WordPress Core

Opened 10 years ago

Closed 9 years ago

#30071 closed defect (bug) (fixed)

Notice triggered by wp_fullscreen_html when using wp_editor and no global $post is set

Reported by: marcochiesi's profile marcochiesi Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 4.2 Priority: normal
Severity: normal Version: 4.0
Component: Editor Keywords: has-patch
Focuses: Cc:

Description

When wp_editor() is called in contexts when no global post is defined (i.e. in widgets administration page) a notice is triggered as following:

Notice
Trying to get property of non-object in wp-includes/class-wp-editor.php:1253

Stack:
_WP_Editors::wp_fullscreen_html()
_WP_Editors::editor_js()
do_action('admin_print_footer_scripts')

The code triggering the notice is the following:

<?php if ( $post->post_status == 'publish' ) _e('Updated.'); else _e('Saved.'); ?>

and could be easily fixed as following

<?php if ( $post && $post->post_status == 'publish' ) _e('Updated.'); else _e('Saved.'); ?>

An easy way to reproduce the issue is to install the Black Studio TinyMCE widget plugin, go to Widgets page and debug with Query Monitor plugin.

Further info here

Attachments (1)

30071.patch (776 bytes) - added by marcochiesi 10 years ago.

Download all attachments as: .zip

Change History (16)

#1 @marcochiesi
10 years ago

  • Keywords has-patch added

@marcochiesi
10 years ago

#2 follow-up: @valendesigns
10 years ago

I've tested your patch and can verify it does solve the issue. One thing to mention though is that you need to cd into the wp-includes directory to apply the patch or you get a "No such file or directory" error in the terminal. Not a big deal, but thought I would mention it.

#3 in reply to: ↑ 2 ; follow-ups: @marcochiesi
10 years ago

Replying to valendesigns:

... One thing to mention though is that you need to cd into the wp-includes directory to apply the patch or you get a "No such file or directory" error in the terminal. Not a big deal, but thought I would mention it.

I followed this tutorial to create the patch with Tortoise. Could you suggest how to get the correct path inside the patch file with Tortoise?

#4 in reply to: ↑ 3 @valendesigns
10 years ago

I followed this tutorial to create the patch with Tortoise. Could you suggest how to get the correct path inside the patch file with Tortoise?

Sorry, someone else would need to answer that question. I only use the Terminal and haven't used Tortoise, so I can't really be of any help with that specifically. I'm still new here and I don't know if the path in the patch is technically wrong or not.

#5 @valendesigns
10 years ago

  • Keywords dev-feedback added

#6 in reply to: ↑ 3 ; follow-up: @kpdesign
10 years ago

Replying to marcochiesi:

Replying to valendesigns:

... One thing to mention though is that you need to cd into the wp-includes directory to apply the patch or you get a "No such file or directory" error in the terminal. Not a big deal, but thought I would mention it.

I followed this tutorial to create the patch with Tortoise. Could you suggest how to get the correct path inside the patch file with Tortoise?

You will need to be in the root directory of your WordPress SVN checkout (the folder you created the SVN checkout in). The directory structure in that folder will be as follows:

/src/
/tests/
/tools/
.editorconfig
.gitignore
.jshintrc
.travis.yml
Gruntfile.js
package.json
phpunit.xml.dist
wp-cli.yml
wp-config-sample.php
wp-tests-config-sample.php

In that folder, right-click and select SVN Create Patch from the TortoiseSVN context menu.

Once the patch is created and saved, you should see the proper path at the top of the file. :

Index: src/wp-includes/class-wp-editor.php
===================================================================
--- src/wp-includes/class-wp-editor.php	(revision 30275)
+++ src/wp-includes/class-wp-editor.php	(working copy)

#7 in reply to: ↑ 6 ; follow-up: @marcochiesi
10 years ago

Replying to kpdesign:

...
In that folder, right-click and select SVN Create Patch from the TortoiseSVN context menu.

Thanks for the heads up, I was right clicking on the file, not on the base folder.

By the way, which is the correct folder to be used as base? In the tutorial the paths were like this:

Index: wp-includes/class-wp-editor.php

and I also foundthis other article with the same path, while in your example it was:

Index: src/wp-includes/class-wp-editor.php

#8 in reply to: ↑ 7 @kpdesign
10 years ago

Replying to marcochiesi:

Replying to kpdesign:
By the way, which is the correct folder to be used as base? In the tutorial the paths were like this:

Index: wp-includes/class-wp-editor.php

and I also foundthis other article with the same path, while in your example it was:

Index: src/wp-includes/class-wp-editor.php

If you check out WordPress via SVN from http://develop.svn.wordpress.org/trunk/, you'll get the folder structure I posted above, and the path in your patch will look like

Index: src/wp-includes/class-wp-editor.php

when you create the patch from the root directory.

The tutorial in the handbook will be updated to reflect this.

#9 @iseulde
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

DFW mode has changed in 4.1.

#10 @marcochiesi
9 years ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened

Even if DFW mode changed, the issue reported is still present in WordPress 4.1. The fix would be extremely simple as shown above, and by the way, it's a good programming practice to check the validity of an object before using its properties.

In WP 4.1 the code is located at line 1319 of wp-includes/class-wp-editor.php.

Please fix it.

#11 @iseulde
9 years ago

That code isn't used anywhere anymore and will most likely be removed from core soon.

#12 @SergeyBiryukov
9 years ago

  • Keywords close added; dev-feedback removed
  • Milestone set to Awaiting Review

#13 @marcochiesi
9 years ago

Another user reported this problem (see topic) blaming it was plugin's fault, while the bug is in WP Core.

Please fix it or remove the offending code. Thank you.

#14 @SergeyBiryukov
9 years ago

  • Keywords close removed
  • Milestone changed from Awaiting Review to 4.2

Reproduced the notice in 4.1 following the steps from description.

#15 @SergeyBiryukov
9 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from reopened to closed

In 31112:

Avoid a PHP notice in _WP_Editors::wp_fullscreen_html() when no $post global is set.

props marcochiesi.
fixes #30071.

Note: See TracTickets for help on using tickets.